Search in sources :

Example 1 with Observable

use of com.hazelcast.jet.Observable in project hazelcast by hazelcast.

the class ObservableResultsTest method multipleObservables.

@Test
public void multipleObservables() {
    Pipeline pipeline = Pipeline.create();
    BatchStage<Long> stage = pipeline.readFrom(TestSources.items(0L, 1L, 2L, 3L, 4L));
    TestObserver otherTestObserver = new TestObserver();
    Observable<Long> otherObservable = hz().getJet().getObservable("otherObservable");
    otherObservable.addObserver(otherTestObserver);
    stage.filter(i -> i % 2 == 0).writeTo(Sinks.observable(observableName));
    stage.filter(i -> i % 2 != 0).writeTo(Sinks.observable("otherObservable"));
    // when
    Job job = hz().getJet().newJob(pipeline);
    job.join();
    // then
    assertSortedValues(testObserver, 0L, 2L, 4L);
    assertError(testObserver, null);
    assertCompletions(testObserver, 1);
    // also
    assertSortedValues(otherTestObserver, 1L, 3L);
    assertError(otherTestObserver, null);
    assertCompletions(otherTestObserver, 1);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) QuickTest(com.hazelcast.test.annotation.QuickTest) Observable(com.hazelcast.jet.Observable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Job(com.hazelcast.jet.Job) TestInClusterSupport(com.hazelcast.jet.TestInClusterSupport) Before(org.junit.Before) RingbufferProxy(com.hazelcast.ringbuffer.impl.RingbufferProxy) LongStream(java.util.stream.LongStream) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) Assert.assertNotNull(org.junit.Assert.assertNotNull) Sinks(com.hazelcast.jet.pipeline.Sinks) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) ConsumerEx(com.hazelcast.function.ConsumerEx) Test(org.junit.Test) Observer(com.hazelcast.jet.function.Observer) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with Observable

use of com.hazelcast.jet.Observable in project hazelcast by hazelcast.

the class ObservableResultsTest method observableRegisteredAfterJobFailedGetError.

@Test
public void observableRegisteredAfterJobFailedGetError() {
    BatchSource<String> errorSource = SourceBuilder.batch("error-source", x -> null).<String>fillBufferFn((in, Void) -> {
        throw new RuntimeException("Intentionally thrown!");
    }).destroyFn(ConsumerEx.noop()).build();
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(errorSource).writeTo(Sinks.observable(observableName));
    Job job = hz().getJet().newJob(pipeline);
    assertTrueEventually(() -> assertEquals(JobStatus.FAILED, job.getStatus()));
    // when
    TestObserver otherTestObserver = new TestObserver();
    Observable<Long> lateObservable = hz().getJet().getObservable(observableName);
    lateObservable.addObserver(otherTestObserver);
    // then
    assertSortedValues(testObserver);
    assertError(testObserver, "Intentionally thrown!");
    assertCompletions(testObserver, 0);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) QuickTest(com.hazelcast.test.annotation.QuickTest) Observable(com.hazelcast.jet.Observable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Job(com.hazelcast.jet.Job) TestInClusterSupport(com.hazelcast.jet.TestInClusterSupport) Before(org.junit.Before) RingbufferProxy(com.hazelcast.ringbuffer.impl.RingbufferProxy) LongStream(java.util.stream.LongStream) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) Assert.assertNotNull(org.junit.Assert.assertNotNull) Sinks(com.hazelcast.jet.pipeline.Sinks) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) ConsumerEx(com.hazelcast.function.ConsumerEx) Test(org.junit.Test) Observer(com.hazelcast.jet.function.Observer) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ConsumerEx (com.hazelcast.function.ConsumerEx)2 Job (com.hazelcast.jet.Job)2 Observable (com.hazelcast.jet.Observable)2 TestInClusterSupport (com.hazelcast.jet.TestInClusterSupport)2 Observer (com.hazelcast.jet.function.Observer)2 BatchSource (com.hazelcast.jet.pipeline.BatchSource)2 BatchStage (com.hazelcast.jet.pipeline.BatchStage)2 Pipeline (com.hazelcast.jet.pipeline.Pipeline)2 Sinks (com.hazelcast.jet.pipeline.Sinks)2 SourceBuilder (com.hazelcast.jet.pipeline.SourceBuilder)2 SimpleEvent (com.hazelcast.jet.pipeline.test.SimpleEvent)2 TestSources (com.hazelcast.jet.pipeline.test.TestSources)2 RingbufferProxy (com.hazelcast.ringbuffer.impl.RingbufferProxy)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2