use of com.hazelcast.jet.pipeline.test.SimpleEvent in project hazelcast by hazelcast.
the class SpringServiceFactoriesTest method testFilterStreamUsingSpringBean.
@Test
public void testFilterStreamUsingSpringBean() {
Pipeline pipeline = Pipeline.create();
pipeline.readFrom(TestSources.itemStream(100)).withNativeTimestamps(0).map(SimpleEvent::sequence).filterUsingService(bean("calculator"), Calculator::filter).writeTo(assertCollectedEventually(10, c -> {
assertTrue(c.size() > 100);
c.forEach(i -> assertEquals(0, i % 2));
}));
Job job = jet.newJob(pipeline);
assertJobCompleted(job);
}
use of com.hazelcast.jet.pipeline.test.SimpleEvent in project hazelcast by hazelcast.
the class HazelcastConnector_RestartTest method when_iListWrittenAndMemberShutdown_then_jobRestarts.
@Test
public void when_iListWrittenAndMemberShutdown_then_jobRestarts() {
IList<SimpleEvent> sinkList = instance1.getList("list");
Pipeline p = Pipeline.create();
p.readFrom(TestSources.itemStream(10)).withoutTimestamps().writeTo(Sinks.list(sinkList));
Job job = instance1.getJet().newJob(p);
assertTrueEventually(() -> assertTrue("no output to sink", sinkList.size() > 0), 10);
Long executionId = executionId(instance1, job);
if (executionId == null) {
executionId = executionId(instance2, job);
}
instance2.shutdown();
// Then - assert that the job stopped producing output
waitExecutionDoneOnMember(instance1, executionId);
int sizeAfterShutdown = sinkList.size();
// Then2 - job restarts and continues production
assertTrueEventually(() -> assertTrue("no output after migration completed", sinkList.size() > sizeAfterShutdown), 20);
}
use of com.hazelcast.jet.pipeline.test.SimpleEvent in project hazelcast by hazelcast.
the class ObservableShutdownTest method when_jetInstanceIsShutDown_then_ObservablesStopReceivingEvents.
@Test
public void when_jetInstanceIsShutDown_then_ObservablesStopReceivingEvents() {
Pipeline pipeline = Pipeline.create();
StreamStage<Long> stage = pipeline.readFrom(TestSources.itemStream(100)).withoutTimestamps().map(SimpleEvent::sequence);
stage.writeTo(Sinks.observable(clientObservable));
stage.writeTo(Sinks.observable(memberObservable));
// when
Job job = client.getJet().newJob(pipeline);
// then
assertTrueEventually(() -> assertTrue(clientObserver.getNoOfValues() > 10));
assertTrueEventually(() -> assertTrue(memberObserver.getNoOfValues() > 10));
// when
client.shutdown();
// then
assertObserverStopsReceivingValues(clientObserver);
// when
long jobId = job.getId();
members[members.length - 1].shutdown();
// then
assertJobStatusEventually(members[0].getJet().getJob(jobId), JobStatus.RUNNING);
assertObserverStopsReceivingValues(memberObserver);
}
use of com.hazelcast.jet.pipeline.test.SimpleEvent in project hazelcast by hazelcast.
the class SpringServiceFactoriesTest method testMapStreamUsingSpringBean.
@Test
public void testMapStreamUsingSpringBean() {
Pipeline pipeline = Pipeline.create();
pipeline.readFrom(TestSources.itemStream(100)).withNativeTimestamps(0).map(SimpleEvent::sequence).mapUsingService(bean("calculator"), Calculator::multiply).writeTo(assertCollectedEventually(10, c -> {
assertTrue(c.size() > 100);
c.forEach(i -> assertTrue(i <= 0));
}));
Job job = jet.newJob(pipeline);
assertJobCompleted(job);
}
use of com.hazelcast.jet.pipeline.test.SimpleEvent in project hazelcast by hazelcast.
the class ObservableResultsTest method multipleJobsWithTheSameSink.
@Test
public void multipleJobsWithTheSameSink() {
Pipeline pipeline = Pipeline.create();
pipeline.readFrom(TestSources.itemStream(100)).withoutTimestamps().map(SimpleEvent::sequence).filter(t -> (t % 2 == 0)).writeTo(Sinks.observable(observableName));
Pipeline pipeline2 = Pipeline.create();
pipeline2.readFrom(TestSources.itemStream(100)).withoutTimestamps().map(SimpleEvent::sequence).filter(t -> (t % 2 != 0)).writeTo(Sinks.observable(observableName));
// when
Job job = hz().getJet().newJob(pipeline);
Job job2 = hz().getJet().newJob(pipeline2);
// then
assertTrueEventually(() -> assertEquals(JobStatus.RUNNING, job.getStatus()));
assertTrueEventually(() -> assertEquals(JobStatus.RUNNING, job2.getStatus()));
assertTrueEventually(() -> assertTrue(testObserver.getNoOfValues() > 10));
assertTrueEventually(() -> {
List<Long> sortedValues = testObserver.getSortedValues();
assertEquals(0, (long) sortedValues.get(0));
assertEquals(1, (long) sortedValues.get(1));
});
assertError(testObserver, null);
assertCompletions(testObserver, 0);
job.cancel();
job2.cancel();
}
Aggregations