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);
}
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);
}
Aggregations