Search in sources :

Example 26 with Queue

use of com.oath.cyclops.async.adapters.Queue in project bender by Nextdoor.

the class ForkOperationTest method testNullOpFork.

@Test
public void testNullOpFork() {
    /*
     * Setup the pipeline of operation processors
     */
    List<List<OperationProcessor>> forks = new ArrayList<List<OperationProcessor>>();
    List<OperationProcessor> fork1 = new ArrayList<OperationProcessor>();
    DummyNullOperation nullOp = new DummyNullOperation();
    fork1.add(new OperationProcessor(new DummyOperationFactory(nullOp)));
    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> actual = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    assertEquals(0, actual.size());
}
Also used : DummyNullOperation(com.nextdoor.bender.testutils.DummyOperationHelper.DummyNullOperation) ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 27 with Queue

use of com.oath.cyclops.async.adapters.Queue 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 28 with Queue

use of com.oath.cyclops.async.adapters.Queue 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 29 with Queue

use of com.oath.cyclops.async.adapters.Queue in project bender by Nextdoor.

the class ForkOperationTest method testSingleFork.

@Test
public void testSingleFork() {
    /*
     * 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);
    ForkOperation op = new ForkOperation(forks);
    /*
     * Create thread that supplies input events
     */
    Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
    supply(2, inputQueue);
    /*
     * Process
     */
    Stream<InternalEvent> input = inputQueue.stream();
    Stream<InternalEvent> output = op.getOutputStream(input);
    List<String> actual = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    List<String> expected = Arrays.asList("0", "1");
    assertEquals(2, actual.size());
    assertTrue(expected.containsAll(actual));
}
Also used : ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 30 with Queue

use of com.oath.cyclops.async.adapters.Queue in project bender by Nextdoor.

the class ForkOperationTest method testNullOpFork1.

@Test
public void testNullOpFork1() {
    /*
     * 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>();
    DummyNullOperation nullOp = new DummyNullOperation();
    fork2.add(new OperationProcessor(new DummyOperationFactory(nullOp)));
    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> actual = output.map(InternalEvent::getEventString).collect(Collectors.toList());
    assertEquals(10, actual.size());
}
Also used : DummyNullOperation(com.nextdoor.bender.testutils.DummyOperationHelper.DummyNullOperation) ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) ArrayList(java.util.ArrayList) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Aggregations

Queue (com.oath.cyclops.async.adapters.Queue)68 Test (org.junit.Test)52 List (java.util.List)34 ArrayList (java.util.ArrayList)28 Collectors (java.util.stream.Collectors)25 Stream (java.util.stream.Stream)23 LazyReact (cyclops.futurestream.LazyReact)22 InternalEvent (com.nextdoor.bender.InternalEvent)18 OperationProcessor (com.nextdoor.bender.operation.OperationProcessor)18 QueueFactories (com.oath.cyclops.async.QueueFactories)17 Tuple2 (cyclops.data.tuple.Tuple2)17 Iterator (java.util.Iterator)17 ReactiveSeq (cyclops.reactive.ReactiveSeq)16 Ignore (org.junit.Ignore)16 FutureStream (cyclops.futurestream.FutureStream)15 Arrays.asList (java.util.Arrays.asList)15 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)15 Matchers.is (org.hamcrest.Matchers.is)15 ThreadPools (com.oath.cyclops.react.ThreadPools)14 Tuple.tuple (cyclops.data.tuple.Tuple.tuple)14