Search in sources :

Example 1 with Vector

use of cyclops.data.Vector in project cyclops by aol.

the class LimitWhileClosedOperatorTest method takeWhile1Async.

@Test
public void takeWhile1Async() {
    AtomicReference<Vector<Integer>> data = new AtomicReference(Vector.empty());
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
    Spouts.async(ReactiveSeq.of(1, 2, 3, 4, 5), ex).takeWhileInclusive(i -> i < 1).forEach(n -> {
        assertFalse(complete.get());
        data.updateAndGet(s -> s.plus(n));
    }, e -> {
        error.set(e);
    }, () -> {
        complete.set(true);
    });
    while (!complete.get()) {
        LockSupport.parkNanos(10l);
    }
    assertThat(data.get(), equalTo(Vector.of(1)));
    assertThat(complete.get(), equalTo(true));
    assertNull(error.get());
}
Also used : Spouts(cyclops.reactive.Spouts) Executor(java.util.concurrent.Executor) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Executors(java.util.concurrent.Executors) LockSupport(java.util.concurrent.locks.LockSupport) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Vector(cyclops.data.Vector) Test(org.junit.Test)

Example 2 with Vector

use of cyclops.data.Vector in project cyclops by aol.

the class LimitWhileClosedOperatorTest method takeWhile5.

@Test
public void takeWhile5() {
    AtomicReference<Vector<Integer>> data = new AtomicReference(Vector.empty());
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
    Spouts.of(1, 2, 3, 4, 5).takeWhileInclusive(i -> true).forEach(n -> {
        assertFalse(complete.get());
        data.updateAndGet(s -> s.plus(n));
    }, e -> {
        error.set(e);
    }, () -> {
        complete.set(true);
    });
    assertThat(data.get(), equalTo(Vector.of(1, 2, 3, 4, 5)));
    assertThat(complete.get(), equalTo(true));
    assertNull(error.get());
}
Also used : Spouts(cyclops.reactive.Spouts) Executor(java.util.concurrent.Executor) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Executors(java.util.concurrent.Executors) LockSupport(java.util.concurrent.locks.LockSupport) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Vector(cyclops.data.Vector) Test(org.junit.Test)

Example 3 with Vector

use of cyclops.data.Vector in project cyclops by aol.

the class SkipWhileClosedOperatorTest method dropWhile5Async.

@Test
public void dropWhile5Async() {
    AtomicReference<Vector<Integer>> data = new AtomicReference(Vector.empty());
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
    Spouts.async(ReactiveSeq.of(1, 2, 3, 4, 5), ex).dropWhileInclusive(i -> false).forEach(n -> {
        assertFalse(complete.get());
        data.updateAndGet(s -> s.plus(n));
    }, e -> {
        error.set(e);
    }, () -> {
        complete.set(true);
    });
    while (!complete.get()) {
        LockSupport.parkNanos(10l);
    }
    assertThat(data.get(), equalTo(Vector.of(2, 3, 4, 5)));
    assertThat(complete.get(), equalTo(true));
    assertNull(error.get());
}
Also used : Spouts(cyclops.reactive.Spouts) Executor(java.util.concurrent.Executor) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Executors(java.util.concurrent.Executors) LockSupport(java.util.concurrent.locks.LockSupport) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Vector(cyclops.data.Vector) Test(org.junit.Test)

Example 4 with Vector

use of cyclops.data.Vector in project cyclops by aol.

the class SkipWhileClosedOperatorTest method dropWhile1_transforms5.

@Test
public void dropWhile1_transforms5() {
    AtomicReference<Vector<Integer>> data = new AtomicReference(Vector.empty());
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
    AtomicInteger peeks = new AtomicInteger(0);
    Spouts.of(1, 2, 3, 4, 5).peek(System.out::println).peek(p -> peeks.incrementAndGet()).dropWhileInclusive(i -> i < 1).forEach(n -> {
        assertFalse(complete.get());
        data.updateAndGet(s -> s.plus(n));
    }, e -> {
        error.set(e);
    }, () -> {
        complete.set(true);
    });
    assertThat(peeks.get(), equalTo(5));
    assertThat(data.get(), equalTo(Vector.of(2, 3, 4, 5)));
    assertThat(complete.get(), equalTo(true));
    assertNull(error.get());
}
Also used : Spouts(cyclops.reactive.Spouts) Executor(java.util.concurrent.Executor) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Executors(java.util.concurrent.Executors) LockSupport(java.util.concurrent.locks.LockSupport) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) Vector(cyclops.data.Vector) Test(org.junit.Test)

Example 5 with Vector

use of cyclops.data.Vector in project cyclops by aol.

the class SkipWhileClosedOperatorTest method dropWhile1.

@Test
public void dropWhile1() {
    AtomicReference<Vector<Integer>> data = new AtomicReference(Vector.empty());
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
    Spouts.of(1, 2, 3, 4, 5).dropWhileInclusive(i -> i < 5).forEach(n -> {
        assertFalse(complete.get());
        data.updateAndGet(s -> s.plus(n));
    }, e -> {
        error.set(e);
    }, () -> {
        complete.set(true);
    });
    assertThat(data.get(), equalTo(Vector.of()));
    assertThat(complete.get(), equalTo(true));
    assertNull(error.get());
}
Also used : Spouts(cyclops.reactive.Spouts) Executor(java.util.concurrent.Executor) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Executors(java.util.concurrent.Executors) LockSupport(java.util.concurrent.locks.LockSupport) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Vector(cyclops.data.Vector) Test(org.junit.Test)

Aggregations

Vector (cyclops.data.Vector)114 Test (org.junit.Test)112 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)111 AtomicReference (java.util.concurrent.atomic.AtomicReference)110 Subscription (org.reactivestreams.Subscription)96 Assert (org.junit.Assert)80 ReactiveSeq (cyclops.reactive.ReactiveSeq)78 Spouts (cyclops.reactive.Spouts)74 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)74 LockSupport (java.util.concurrent.locks.LockSupport)74 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)74 Executor (java.util.concurrent.Executor)68 Executors (java.util.concurrent.Executors)68 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)54 Matchers.equalTo (org.hamcrest.Matchers.equalTo)32 Arrays (java.util.Arrays)28 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Tuple (cyclops.data.tuple.Tuple)24 Tuple2 (cyclops.data.tuple.Tuple2)24 Tuple3 (cyclops.data.tuple.Tuple3)24