-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from CloudSlang/master
update
- Loading branch information
Showing
13 changed files
with
373 additions
and
149 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...score-queue-api/src/main/java/io/cloudslang/engine/queue/services/BusyWorkersService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Apache License v2.0 which accompany this distribution. | ||
* | ||
* The Apache License is available at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*******************************************************************************/ | ||
|
||
|
||
package io.cloudslang.engine.queue.services; | ||
|
||
public interface BusyWorkersService { | ||
boolean isWorkerBusy(String workerId); | ||
void findBusyWorkers(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
314 changes: 175 additions & 139 deletions
314
...l/src/main/java/io/cloudslang/engine/queue/repositories/ExecutionQueueRepositoryImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...-queue-impl/src/main/java/io/cloudslang/engine/queue/services/BusyWorkersServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Apache License v2.0 which accompany this distribution. | ||
* | ||
* The Apache License is available at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*******************************************************************************/ | ||
|
||
package io.cloudslang.engine.queue.services; | ||
import io.cloudslang.engine.queue.entities.ExecStatus; | ||
import io.cloudslang.engine.queue.repositories.ExecutionQueueRepository; | ||
import org.apache.log4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BusyWorkersServiceImpl implements BusyWorkersService{ | ||
|
||
private final Logger logger = Logger.getLogger(BusyWorkersServiceImpl.class); | ||
private List<String> busyWorkers = new ArrayList<>(); | ||
|
||
@Autowired | ||
private ExecutionQueueRepository executionQueueRepository; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public boolean isWorkerBusy(String workerId) { | ||
return busyWorkers.contains(workerId); | ||
} | ||
@Override | ||
@Transactional(readOnly = true) | ||
public void findBusyWorkers() { | ||
long startTime = 0; | ||
if (logger.isDebugEnabled()) { | ||
startTime = System.currentTimeMillis(); | ||
logger.debug("Querying for busy workers..."); | ||
} | ||
busyWorkers = executionQueueRepository.getBusyWorkers(ExecStatus.ASSIGNED); | ||
|
||
if (logger.isDebugEnabled()) { | ||
long endTime = System.currentTimeMillis(); | ||
logger.debug("Queried for busy workers, the following workers are busy: " + this.busyWorkers + ". Query took: " + (endTime - startTime) + " ms to complete"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...-queue-impl/src/test/java/io/cloudslang/engine/queue/services/BusyWorkersServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Apache License v2.0 which accompany this distribution. | ||
* | ||
* The Apache License is available at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*******************************************************************************/ | ||
|
||
|
||
package io.cloudslang.engine.queue.services; | ||
|
||
import io.cloudslang.engine.queue.entities.ExecStatus; | ||
import io.cloudslang.engine.queue.repositories.ExecutionQueueRepository; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
|
||
@ContextConfiguration | ||
public class BusyWorkersServiceTest { | ||
|
||
|
||
|
||
@Autowired | ||
private BusyWorkersService busyWorkersService; | ||
|
||
@Autowired | ||
private ExecutionQueueRepository executionQueueRepository; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
MockitoAnnotations.initMocks(this); | ||
reset(executionQueueRepository); | ||
} | ||
|
||
@Test | ||
public void testIdleWorker(){ | ||
List<String> busyWorkers = new ArrayList<>(); | ||
when(executionQueueRepository.getBusyWorkers(ExecStatus.ASSIGNED)).thenReturn(busyWorkers); | ||
Assert.assertFalse(busyWorkersService.isWorkerBusy("worker1")); | ||
} | ||
|
||
@Test | ||
public void testBusyWorker(){ | ||
List<String> busyWorkers = new ArrayList<>(); | ||
busyWorkers.add("worker1"); | ||
when(executionQueueRepository.getBusyWorkers(ExecStatus.ASSIGNED)).thenReturn(busyWorkers); | ||
busyWorkersService.findBusyWorkers(); | ||
Assert.assertTrue(busyWorkersService.isWorkerBusy("worker1")); | ||
} | ||
|
||
|
||
@Configuration | ||
static class EmptyConfig { | ||
@Bean | ||
public BusyWorkersService busyWorkersService(){ | ||
return new BusyWorkersServiceImpl(); | ||
} | ||
|
||
@Bean | ||
public ExecutionQueueRepository executionQueueRepository(){ | ||
return mock(ExecutionQueueRepository.class); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters