Search in sources :

Example 56 with JetInstance

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();
    }
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) StuckForeverSourceP(com.hazelcast.jet.core.TestProcessors.StuckForeverSourceP) JetInstance(com.hazelcast.jet.JetInstance) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 57 with JetInstance

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStreamReader(java.io.InputStreamReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JetInstance(com.hazelcast.jet.JetInstance) BufferedReader(java.io.BufferedReader) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 58 with JetInstance

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();
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 59 with JetInstance

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);
    }
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) CancellationException(java.util.concurrent.CancellationException) UnknownHostException(java.net.UnknownHostException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 60 with JetInstance

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();
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Aggregations

JetInstance (com.hazelcast.jet.JetInstance)84 Test (org.junit.Test)45 Job (com.hazelcast.jet.Job)32 JetConfig (com.hazelcast.jet.config.JetConfig)22 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 JobConfig (com.hazelcast.jet.config.JobConfig)13 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)12 DAG (com.hazelcast.jet.core.DAG)10 ExpectedException (org.junit.rules.ExpectedException)10 Jet (com.hazelcast.jet.Jet)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 JetService (com.hazelcast.jet.impl.JetService)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobRepository (com.hazelcast.jet.impl.JobRepository)7 Sources (com.hazelcast.jet.pipeline.Sources)7 CancellationException (java.util.concurrent.CancellationException)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Before (org.junit.Before)7