Search in sources :

Example 41 with Queue

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

the class BatchingInvestigationsTest method batchIssue.

@Test
public void batchIssue() throws InterruptedException {
    Queue<String> queue = QueueFactories.<String>unboundedQueue().build();
    new Thread(() -> {
        for (int i = 0; i < 10; i++) {
            queue.offer("New message " + i);
            sleep(10000);
        }
    }).start();
    queue.stream().groupedBySizeAndTime(10, 500, TimeUnit.MILLISECONDS).to(s -> new LazyReact(ThreadPools.getSequential()).fromStream(s)).async().peek(System.out::println).run();
    while (true) {
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) QueueFactories(com.oath.cyclops.async.QueueFactories) Ignore(org.junit.Ignore) LazyReact(cyclops.futurestream.LazyReact) ThreadPools(com.oath.cyclops.react.ThreadPools) Test(org.junit.Test) StreamSource(cyclops.stream.StreamSource) Subscription(com.oath.cyclops.react.async.subscription.Subscription) ArrayList(java.util.ArrayList) LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 42 with Queue

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

the class PipesTest method oneOrError.

@Test
public void oneOrError() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    pipes.push("hello", "world2");
    q.close();
    assertThat(pipes.oneOrError("hello").toOptional().get(), equalTo("world"));
    assertThat(pipes.oneOrError("hello").toOptional().get(), equalTo("world2"));
}
Also used : Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 43 with Queue

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

the class PipesTest method nextValue.

@Test
public void nextValue() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    pipes.push("hello", "world2");
    q.close();
    Eval<Maybe<String>> nextValue = pipes.nextValue("hello");
    int values = 0;
    while (nextValue.get().isPresent()) {
        System.out.println(values++);
    }
    assertThat(values, equalTo(2));
}
Also used : Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 44 with Queue

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

the class PipesTest method oneValueOrErrorTryException.

@Test
public void oneValueOrErrorTryException() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    q.close();
    assertThat(pipes.oneValueOrError("hello", Throwable.class), equalTo(Option.some(Try.success("world"))));
    assertThat(pipes.oneValueOrError("hello", Throwable.class).toOptional().get().failureGet().orElse(null), instanceOf(NoSuchElementException.class));
}
Also used : Queue(com.oath.cyclops.async.adapters.Queue) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 45 with Queue

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

the class PipesTest method nextNull.

@Test
public void nextNull() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    pipes.push("hello", "world2");
    q.close();
    Eval<String> nextValue = pipes.nextOrNull("hello");
    int values = 0;
    while (nextValue.get() != null) {
        System.out.println(values++);
    }
    assertThat(values, equalTo(2));
}
Also used : 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