Search in sources :

Example 1 with SimpleEvent

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);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) CustomSpringJUnit4ClassRunner(com.hazelcast.spring.CustomSpringJUnit4ClassRunner) AssertionSinks.assertCollectedEventually(com.hazelcast.jet.pipeline.test.AssertionSinks.assertCollectedEventually) RunWith(org.junit.runner.RunWith) Resource(javax.annotation.Resource) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) JetService(com.hazelcast.jet.JetService) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Hazelcast(com.hazelcast.core.Hazelcast) Arrays.asList(java.util.Arrays.asList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Assert.fail(org.junit.Assert.fail) JetSpringServiceFactories.bean(com.hazelcast.spring.jet.JetSpringServiceFactories.bean) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 2 with SimpleEvent

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);
}
Also used : SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) 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 3 with SimpleEvent

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);
}
Also used : SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) 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 4 with SimpleEvent

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);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) CustomSpringJUnit4ClassRunner(com.hazelcast.spring.CustomSpringJUnit4ClassRunner) AssertionSinks.assertCollectedEventually(com.hazelcast.jet.pipeline.test.AssertionSinks.assertCollectedEventually) RunWith(org.junit.runner.RunWith) Resource(javax.annotation.Resource) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) JetService(com.hazelcast.jet.JetService) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Hazelcast(com.hazelcast.core.Hazelcast) Arrays.asList(java.util.Arrays.asList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Assert.fail(org.junit.Assert.fail) JetSpringServiceFactories.bean(com.hazelcast.spring.jet.JetSpringServiceFactories.bean) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 5 with SimpleEvent

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();
}
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) SimpleEvent(com.hazelcast.jet.pipeline.test.SimpleEvent) 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

Job (com.hazelcast.jet.Job)6 Pipeline (com.hazelcast.jet.pipeline.Pipeline)6 SimpleEvent (com.hazelcast.jet.pipeline.test.SimpleEvent)6 Test (org.junit.Test)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 TestSources (com.hazelcast.jet.pipeline.test.TestSources)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Assert.fail (org.junit.Assert.fail)3 Hazelcast (com.hazelcast.core.Hazelcast)2 JetService (com.hazelcast.jet.JetService)2 AssertionSinks.assertAnyOrder (com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder)2 AssertionSinks.assertCollectedEventually (com.hazelcast.jet.pipeline.test.AssertionSinks.assertCollectedEventually)2 CustomSpringJUnit4ClassRunner (com.hazelcast.spring.CustomSpringJUnit4ClassRunner)2 JetSpringServiceFactories.bean (com.hazelcast.spring.jet.JetSpringServiceFactories.bean)2 Arrays.asList (java.util.Arrays.asList)2 CompletionException (java.util.concurrent.CompletionException)2 HazelcastException (com.hazelcast.core.HazelcastException)1 ConsumerEx (com.hazelcast.function.ConsumerEx)1