Search in sources :

Example 6 with TaskExecutor

use of org.ak.trafficController.TaskExecutor in project trafficController by amitkhosla.

the class TaskHelperTest method testGetExecutorByNameHavingIntCommaIntMixPercentage.

@Test
public void testGetExecutorByNameHavingIntCommaIntMixPercentage() {
    TaskHelper taskHelper = new TaskHelper();
    int processors = Runtime.getRuntime().availableProcessors();
    int fast = 2 * processors;
    int slow = 4 * processors;
    TaskExecutor taskExecutor = taskHelper.getExecutorByName("200%,8");
    Assert.assertEquals(fast, taskExecutor.getNumberOfFastQueueConsumers());
    Assert.assertEquals(8, taskExecutor.getNumberOfSlowQueueConsumers());
    TaskExecutor taskExecutor1 = taskHelper.getExecutorByName("200% ,8 ");
    Assert.assertEquals(fast, taskExecutor1.getNumberOfFastQueueConsumers());
    Assert.assertEquals(8, taskExecutor1.getNumberOfSlowQueueConsumers());
    Assert.assertNotSame(taskExecutor, taskExecutor1);
    TaskExecutor taskExecutor2 = taskHelper.getExecutorByName("20,400%");
    Assert.assertEquals(20, taskExecutor2.getNumberOfFastQueueConsumers());
    Assert.assertEquals(slow, taskExecutor2.getNumberOfSlowQueueConsumers());
    Assert.assertNotSame(taskExecutor, taskExecutor2);
    TaskExecutor taskExecutor3 = taskHelper.getExecutorByName("20 ,400%");
    Assert.assertEquals(20, taskExecutor3.getNumberOfFastQueueConsumers());
    Assert.assertEquals(slow, taskExecutor3.getNumberOfSlowQueueConsumers());
    Assert.assertNotSame(taskExecutor1, taskExecutor3);
}
Also used : TaskExecutor(org.ak.trafficController.TaskExecutor) Test(org.junit.Test)

Example 7 with TaskExecutor

use of org.ak.trafficController.TaskExecutor in project trafficController by amitkhosla.

the class TaskHelperTest method testGetExecutorByNameOthers.

@Test
public void testGetExecutorByNameOthers() {
    TaskHelper taskHelper = new TaskHelper();
    TaskExecutor taskExecutor = taskHelper.getExecutorByName("some");
    Assert.assertNull(taskExecutor);
    taskExecutor = taskHelper.getExecutorByName("one,some");
    Assert.assertNull(taskExecutor);
    taskExecutor = taskHelper.getExecutorByName("2,some");
    Assert.assertNull(taskExecutor);
    taskExecutor = taskHelper.getExecutorByName("234a,2");
    Assert.assertNull(taskExecutor);
    taskExecutor = taskHelper.getExecutorByName("2,3,4");
    Assert.assertNull(taskExecutor);
    Assert.assertEquals(0, taskHelper.taskExecutors.size());
    TaskExecutor mock = Mockito.mock(TaskExecutor.class);
    taskHelper.taskExecutors.put("myString", mock);
    taskExecutor = taskHelper.getExecutorByName("myString");
    Assert.assertEquals(mock, taskExecutor);
}
Also used : TaskExecutor(org.ak.trafficController.TaskExecutor) Test(org.junit.Test)

Example 8 with TaskExecutor

use of org.ak.trafficController.TaskExecutor in project trafficController by amitkhosla.

the class TaskHelperTest method testGetExecutorByNameHavingIntCommaIntPercentage.

@Test
public void testGetExecutorByNameHavingIntCommaIntPercentage() {
    TaskHelper taskHelper = new TaskHelper();
    int processors = Runtime.getRuntime().availableProcessors();
    int fast = 2 * processors;
    int slow = 4 * processors;
    TaskExecutor taskExecutor = taskHelper.getExecutorByName("200%,400%");
    Assert.assertEquals(fast, taskExecutor.getNumberOfFastQueueConsumers());
    Assert.assertEquals(slow, taskExecutor.getNumberOfSlowQueueConsumers());
    TaskExecutor taskExecutor1 = taskHelper.getExecutorByName("200% ,400%");
    Assert.assertEquals(fast, taskExecutor1.getNumberOfFastQueueConsumers());
    Assert.assertEquals(slow, taskExecutor1.getNumberOfSlowQueueConsumers());
    Assert.assertNotSame(taskExecutor, taskExecutor1);
    TaskExecutor taskExecutor2 = taskHelper.getExecutorByName("200%,400%");
    Assert.assertEquals(fast, taskExecutor2.getNumberOfFastQueueConsumers());
    Assert.assertEquals(slow, taskExecutor2.getNumberOfSlowQueueConsumers());
    Assert.assertSame(taskExecutor, taskExecutor2);
    TaskExecutor taskExecutor3 = taskHelper.getExecutorByName("200% ,400%");
    Assert.assertEquals(fast, taskExecutor3.getNumberOfFastQueueConsumers());
    Assert.assertEquals(slow, taskExecutor3.getNumberOfSlowQueueConsumers());
    Assert.assertSame(taskExecutor1, taskExecutor3);
}
Also used : TaskExecutor(org.ak.trafficController.TaskExecutor) Test(org.junit.Test)

Example 9 with TaskExecutor

use of org.ak.trafficController.TaskExecutor in project trafficController by amitkhosla.

the class TaskHelperTest method testGetExecutorByNameHavingIntCommaInt.

@Test
public void testGetExecutorByNameHavingIntCommaInt() {
    TaskHelper taskHelper = new TaskHelper();
    TaskExecutor taskExecutor = taskHelper.getExecutorByName("2,3");
    Assert.assertEquals(2, taskExecutor.getNumberOfFastQueueConsumers());
    Assert.assertEquals(3, taskExecutor.getNumberOfSlowQueueConsumers());
    TaskExecutor taskExecutor1 = taskHelper.getExecutorByName("2 ,3");
    Assert.assertEquals(2, taskExecutor1.getNumberOfFastQueueConsumers());
    Assert.assertEquals(3, taskExecutor1.getNumberOfSlowQueueConsumers());
    Assert.assertNotSame(taskExecutor, taskExecutor1);
    TaskExecutor taskExecutor2 = taskHelper.getExecutorByName("2,3");
    Assert.assertEquals(2, taskExecutor2.getNumberOfFastQueueConsumers());
    Assert.assertEquals(3, taskExecutor2.getNumberOfSlowQueueConsumers());
    Assert.assertSame(taskExecutor, taskExecutor2);
    TaskExecutor taskExecutor3 = taskHelper.getExecutorByName("2 ,3");
    Assert.assertEquals(2, taskExecutor3.getNumberOfFastQueueConsumers());
    Assert.assertEquals(3, taskExecutor3.getNumberOfSlowQueueConsumers());
    Assert.assertSame(taskExecutor1, taskExecutor3);
}
Also used : TaskExecutor(org.ak.trafficController.TaskExecutor) Test(org.junit.Test)

Example 10 with TaskExecutor

use of org.ak.trafficController.TaskExecutor in project trafficController by amitkhosla.

the class TaskHelper method getTaskExecutor.

/**
 * Get task executor for controlled.
 * @param parallel Controlled
 * @param joinPoint Join point
 * @return TaskExecutor details
 */
public TaskExecutorDetails getTaskExecutor(Controlled parallel, ProceedingJoinPoint joinPoint) {
    String taskExecutorName = parallel.executorName();
    if (parallel.maxConsumer().equals("0") && parallel.maxSlowConsumer().equals("0") && taskExecutorName.isEmpty()) {
        taskExecutorName = Constants.DEFAULT;
    }
    TaskExecutor taskExecutor = getExecutorByName(taskExecutorName);
    if (StringUtils.isEmpty(taskExecutorName)) {
        taskExecutorName = getNameFromJoinPointMethodSignature(joinPoint);
    }
    if (Objects.isNull(taskExecutor)) {
        if (taskExecutorName.equals(Constants.DEFAULT)) {
            taskExecutor = TaskExecutor.getInstance();
        } else {
            taskExecutor = getTaskExecutorBasedOnAsyncProps(parallel, joinPoint);
        }
        taskExecutors.put(taskExecutorName, taskExecutor);
    }
    TaskExecutorDetails details = new TaskExecutorDetails().setName(taskExecutorName).setTaskExecutor(taskExecutor);
    return details;
// return null;//TaskExecutor.getInstance();
}
Also used : TaskExecutor(org.ak.trafficController.TaskExecutor)

Aggregations

TaskExecutor (org.ak.trafficController.TaskExecutor)10 Test (org.junit.Test)4 ExecutableTask (org.ak.trafficController.ExecutableTask)2 ParallelExecutingTask (org.ak.trafficController.ParallelExecutingTask)2 ParallelTask (org.ak.trafficController.ParallelTask)2 Task (org.ak.trafficController.Task)2 UnlinkedTask (org.ak.trafficController.UnlinkedTask)2 Around (org.aspectj.lang.annotation.Around)2 ArrayList (java.util.ArrayList)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RunnableToBeExecuted (org.ak.trafficController.RunnableToBeExecuted)1 TaskType (org.ak.trafficController.annotations.api.TaskType)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1