use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class WriteBufferedPTest method when_writeBufferedJobFailed_then_bufferDisposed.
@Test
public void when_writeBufferedJobFailed_then_bufferDisposed() throws Exception {
JetInstance instance = createJetMember();
try {
DAG dag = new DAG();
Vertex source = dag.newVertex("source", StuckForeverSourceP::new);
Vertex sink = dag.newVertex("sink", getLoggingBufferedWriter()).localParallelism(1);
dag.edge(Edge.between(source, sink));
Job job = instance.newJob(dag);
// wait for the job to initialize
Thread.sleep(5000);
job.cancel();
assertTrueEventually(() -> assertTrue("No \"dispose\", only: " + events, events.contains("dispose")), 60);
System.out.println(events);
} finally {
instance.shutdown();
}
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class WriteSocketTest method integrationTest.
@Test
public void integrationTest() throws Exception {
AtomicInteger counter = new AtomicInteger();
ServerSocket serverSocket = new ServerSocket(0);
new Thread(() -> uncheckRun(() -> {
while (!serverSocket.isClosed()) {
Socket socket = serverSocket.accept();
new Thread(() -> uncheckRun(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
while (reader.readLine() != null) {
counter.incrementAndGet();
}
}
})).start();
}
})).start();
JetInstance jetInstance = createJetMember();
createJetMember();
IMapJet<Integer, String> map = jetInstance.getMap("map");
range(0, ITEM_COUNT).forEach(i -> map.put(i, String.valueOf(i)));
Pipeline p = Pipeline.create();
p.drawFrom(Sources.map("map")).drainTo(Sinks.socket("localhost", serverSocket.getLocalPort()));
jetInstance.newJob(p).join();
assertTrueEventually(() -> assertEquals(ITEM_COUNT, counter.get()));
serverSocket.close();
// wait a little to check, if the counter doesn't get too far
Thread.sleep(500);
assertEquals(ITEM_COUNT, counter.get());
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class CancellationTest method when_jobCancelledOnMultipleNodes_then_terminatedEventually.
@Test
public void when_jobCancelledOnMultipleNodes_then_terminatedEventually() {
// Given
newInstance();
JetInstance instance = newInstance();
DAG dag = new DAG();
dag.newVertex("slow", StuckSource::new);
Job job = instance.newJob(dag);
assertExecutionStarted();
// When
job.cancel();
// Then
assertExecutionTerminated();
expectedException.expect(CancellationException.class);
job.join();
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class CancellationTest method when_jobFailsOnOnNonInitiatorNode_then_cancelledOnInitiatorNode.
@Test
public void when_jobFailsOnOnNonInitiatorNode_then_cancelledOnInitiatorNode() throws Throwable {
// Given
JetInstance instance = newInstance();
JetInstance other = newInstance();
RuntimeException fault = new RuntimeException("fault");
DAG dag = new DAG();
dag.newVertex("faulty", new SingleNodeFaultSupplier(getAddress(other.getHazelcastInstance()), fault)).localParallelism(4);
Job job = instance.newJob(dag);
assertExecutionStarted();
// Then
FaultyProcessor.failNow = true;
assertExecutionTerminated();
expectedException.expect(fault.getClass());
expectedException.expectMessage(fault.getMessage());
try {
job.join();
} catch (Exception e) {
throw peel(e);
}
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class CancellationTest method when_jobCancelled_then_trackedJobsGetNotified.
@Test
public void when_jobCancelled_then_trackedJobsGetNotified() {
// Given
JetInstance instance1 = newInstance();
JetInstance instance2 = newInstance();
DAG dag = new DAG();
dag.newVertex("slow", StuckSource::new);
Job job = instance1.newJob(dag);
assertExecutionStarted();
// When
job.cancel();
// Then
assertExecutionTerminated();
expectedException.expect(CancellationException.class);
Job tracked = instance2.getJobs().iterator().next();
tracked.join();
}
Aggregations