Search in sources :

Example 1 with DummyThrottleOperationFactory

use of com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory in project bender by Nextdoor.

the class ForkOperationTest method testForkMonitoringParallel.

@Test
public void testForkMonitoringParallel() {
    /*
     * Setup the pipeline of operation processors
     */
    List<List<OperationProcessor>> forks = new ArrayList<List<OperationProcessor>>();
    List<OperationProcessor> fork1 = new ArrayList<OperationProcessor>();
    fork1.add(new OperationProcessor(new DummyOperationFactory()));
    forks.add(fork1);
    List<OperationProcessor> fork2 = new ArrayList<OperationProcessor>();
    fork2.add(new OperationProcessor(new DummyThrottleOperationFactory()));
    forks.add(fork2);
    ForkOperation op = new ForkOperation(forks);
    /*
     * Create thread that supplies input events
     */
    Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
    supply(10, inputQueue);
    /*
     * Process
     */
    Stream<InternalEvent> input = inputQueue.stream();
    Stream<InternalEvent> output = op.getOutputStream(input);
    List<String> outputEvents = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    Monitor m = Monitor.getInstance();
    List<Stat> stats = m.getStats();
    Map<String, String> actual = new HashMap<String, String>();
    for (Stat stat : stats) {
        String key = String.format("%s.%s", stat.getTags().iterator().next().getValue(), stat.getName());
        actual.put(key, "" + stat.getValue());
    }
    assertEquals("0", actual.get("com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation.error.count"));
    assertEquals("10", actual.get("com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation.success.count"));
    assertEquals("10", actual.get("com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperation.success.count"));
    assertEquals("0", actual.get("com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperation.error.count"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) Monitor(com.nextdoor.bender.monitoring.Monitor) Stat(com.nextdoor.bender.monitoring.Stat) DummyThrottleOperationFactory(com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 2 with DummyThrottleOperationFactory

use of com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory in project bender by Nextdoor.

the class ForkOperationTest method testForkMonitoringSeries.

@Test
public void testForkMonitoringSeries() {
    /*
     * Setup the pipeline of operation processors
     */
    List<List<OperationProcessor>> forks = new ArrayList<List<OperationProcessor>>();
    List<OperationProcessor> fork1 = new ArrayList<OperationProcessor>();
    fork1.add(new OperationProcessor(new DummyThrottleOperationFactory()));
    fork1.add(new OperationProcessor(new DummyOperationFactory()));
    forks.add(fork1);
    ForkOperation op = new ForkOperation(forks);
    /*
     * Create thread that supplies input events
     */
    Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
    supply(10, inputQueue);
    /*
     * Process
     */
    Stream<InternalEvent> input = inputQueue.stream();
    Stream<InternalEvent> output = op.getOutputStream(input);
    List<String> outputEvents = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    Monitor m = Monitor.getInstance();
    List<Stat> stats = m.getStats();
    Map<String, String> actual = new HashMap<String, String>();
    for (Stat stat : stats) {
        String key = String.format("%s.%s", stat.getTags().iterator().next().getValue(), stat.getName());
        actual.put(key, "" + stat.getValue());
    }
    assertEquals("0", actual.get("com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation.error.count"));
    assertEquals("10", actual.get("com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation.success.count"));
    assertEquals("10", actual.get("com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperation.success.count"));
    assertEquals("0", actual.get("com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperation.error.count"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) Monitor(com.nextdoor.bender.monitoring.Monitor) Stat(com.nextdoor.bender.monitoring.Stat) DummyThrottleOperationFactory(com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 3 with DummyThrottleOperationFactory

use of com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory in project bender by Nextdoor.

the class ForkOperationTest method testTwoForksSlow.

@Test
public void testTwoForksSlow() {
    /*
     * Setup the pipeline of operation processors
     */
    List<List<OperationProcessor>> forks = new ArrayList<List<OperationProcessor>>();
    List<OperationProcessor> fork1 = new ArrayList<OperationProcessor>();
    fork1.add(new OperationProcessor(new DummyThrottleOperationFactory()));
    forks.add(fork1);
    List<OperationProcessor> fork2 = new ArrayList<OperationProcessor>();
    fork2.add(new OperationProcessor(new DummyOperationFactory()));
    forks.add(fork2);
    ForkOperation op = new ForkOperation(forks);
    /*
     * Create thread that supplies input events
     */
    Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
    supply(1000, inputQueue);
    /*
     * Process
     */
    Stream<InternalEvent> input = inputQueue.stream();
    Stream<InternalEvent> output = op.getOutputStream(input);
    List<String> actual = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    assertEquals(2000, actual.size());
}
Also used : ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) DummyThrottleOperationFactory(com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 4 with DummyThrottleOperationFactory

use of com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory in project bender by Nextdoor.

the class ForkOperationTest method testThreeForks.

@Test
public void testThreeForks() {
    /*
     * Setup the pipeline of operation processors
     */
    List<List<OperationProcessor>> forks = new ArrayList<List<OperationProcessor>>();
    List<OperationProcessor> fork1 = new ArrayList<OperationProcessor>();
    fork1.add(new OperationProcessor(new DummyThrottleOperationFactory()));
    forks.add(fork1);
    List<OperationProcessor> fork2 = new ArrayList<OperationProcessor>();
    fork2.add(new OperationProcessor(new DummyOperationFactory()));
    forks.add(fork2);
    List<OperationProcessor> fork3 = new ArrayList<OperationProcessor>();
    fork3.add(new OperationProcessor(new DummyOperationFactory()));
    forks.add(fork3);
    ForkOperation op = new ForkOperation(forks);
    /*
     * Create thread that supplies input events
     */
    Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
    supply(10, inputQueue);
    /*
     * Process
     */
    Stream<InternalEvent> input = inputQueue.stream();
    Stream<InternalEvent> output = op.getOutputStream(input);
    List<String> actual = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    assertEquals(30, actual.size());
}
Also used : ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) DummyThrottleOperationFactory(com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)4 OperationProcessor (com.nextdoor.bender.operation.OperationProcessor)4 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)4 DummyThrottleOperationFactory (com.nextdoor.bender.testutils.DummyThrottleOperationHelper.DummyThrottleOperationFactory)4 Queue (com.oath.cyclops.async.adapters.Queue)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Test (org.junit.Test)4 Monitor (com.nextdoor.bender.monitoring.Monitor)2 Stat (com.nextdoor.bender.monitoring.Stat)2 HashMap (java.util.HashMap)2