Search in sources :

Example 6 with GeneratorFunction

use of com.hazelcast.jet.pipeline.test.GeneratorFunction in project hazelcast by hazelcast.

the class OrderedProcessingMergingStagesTest method when_innerJoin2_applied_primary_stream_order_is_preserved.

@Test
public void when_innerJoin2_applied_primary_stream_order_is_preserved() {
    int validatedItemCountPerGenerator = ITEM_COUNT;
    int eventsPerSecondPerGenerator = 5 * ITEM_COUNT;
    int generatorCount = 2;
    // Generate monotonic increasing items that are distinct for each generator.
    GeneratorFunction<Map.Entry<Long, Long>> generator1 = (ts, seq) -> Util.entry(0L, generatorCount * seq);
    GeneratorFunction<Map.Entry<Long, Long>> generator2 = (ts, seq) -> Util.entry(1L, generatorCount * seq + 1);
    StreamStage<Map.Entry<Long, Long>> srcStage = p.readFrom(itemsParallel(eventsPerSecondPerGenerator, Arrays.asList(generator1, generator2))).withIngestionTimestamps().setLocalParallelism(HIGH_LOCAL_PARALLELISM);
    BatchStage<Map.Entry<Long, Long>> batchStage = p.readFrom(TestSources.items(Util.entry(0L, 0L), Util.entry(1L, 0L)));
    BatchStage<Map.Entry<Long, Long>> batchStage2 = p.readFrom(TestSources.items(Util.entry(0L, 0L), Util.entry(1L, 0L)));
    StreamStage<Map.Entry<Long, Long>> joined = srcStage.innerHashJoin2(batchStage, JoinClause.onKeys(Map.Entry::getKey, Map.Entry::getKey), batchStage2, JoinClause.onKeys(Map.Entry::getKey, Map.Entry::getKey), (primary, stg1, stg2) -> primary).setLocalParallelism(HIGH_LOCAL_PARALLELISM);
    joined.groupingKey(Map.Entry::getKey).mapStateful(() -> create(generatorCount), this::orderValidator).writeTo(AssertionSinks.assertCollectedEventually(60, list -> {
        assertTrue("when", validatedItemCountPerGenerator <= list.size());
        assertFalse("There is some reordered items in the list", list.contains(false));
    }));
    Job job = hz.getJet().newJob(p);
    try {
        job.join();
        fail("Job should have completed with an AssertionCompletedException, but completed normally");
    } catch (CompletionException e) {
        String errorMsg = e.getCause().getMessage();
        assertTrue("Job was expected to complete with AssertionCompletedException, but completed with: " + e.getCause(), errorMsg.contains(AssertionCompletedException.class.getName()));
    }
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) ParallelStreamP(com.hazelcast.jet.pipeline.test.ParallelStreamP) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) JetAssert.assertFalse(com.hazelcast.jet.core.test.JetAssert.assertFalse) JetAssert.assertTrue(com.hazelcast.jet.core.test.JetAssert.assertTrue) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AfterClass(org.junit.AfterClass) LongStream(java.util.stream.LongStream) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Category(org.junit.experimental.categories.Category) Serializable(java.io.Serializable) Objects(java.util.Objects) JetAssert.fail(com.hazelcast.jet.core.test.JetAssert.fail) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GeneratorFunction(com.hazelcast.jet.pipeline.test.GeneratorFunction) Hazelcast(com.hazelcast.core.Hazelcast) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Assert(org.junit.Assert) Util(com.hazelcast.jet.Util) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) CompletionException(java.util.concurrent.CompletionException) Job(com.hazelcast.jet.Job) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with GeneratorFunction

use of com.hazelcast.jet.pipeline.test.GeneratorFunction in project hazelcast by hazelcast.

the class OrderedProcessingMergingStagesTest method when_hashJoin_applied_primary_stream_order_is_preserved.

@Test
public void when_hashJoin_applied_primary_stream_order_is_preserved() {
    int validatedItemCountPerGenerator = ITEM_COUNT;
    int eventsPerSecondPerGenerator = 5 * ITEM_COUNT;
    int generatorCount = 2;
    // Generate monotonic increasing items that are distinct for each generator.
    GeneratorFunction<Map.Entry<Long, Long>> generator1 = (ts, seq) -> Util.entry(0L, generatorCount * seq);
    GeneratorFunction<Map.Entry<Long, Long>> generator2 = (ts, seq) -> Util.entry(1L, generatorCount * seq + 1);
    StreamStage<Map.Entry<Long, Long>> srcStage = p.readFrom(itemsParallel(eventsPerSecondPerGenerator, Arrays.asList(generator1, generator2))).withIngestionTimestamps().setLocalParallelism(HIGH_LOCAL_PARALLELISM);
    BatchStage<Map.Entry<Long, Long>> batchStage = p.readFrom(TestSources.items(Util.entry(0L, 0L), Util.entry(1L, 0L)));
    StreamStage<Map.Entry<Long, Long>> joined = srcStage.hashJoin(batchStage, JoinClause.onKeys(Map.Entry::getKey, Map.Entry::getKey), (primary, stage) -> primary).setLocalParallelism(HIGH_LOCAL_PARALLELISM);
    joined.groupingKey(Map.Entry::getKey).mapStateful(() -> create(generatorCount), this::orderValidator).writeTo(AssertionSinks.assertCollectedEventually(60, list -> {
        assertTrue("when", validatedItemCountPerGenerator <= list.size());
        assertFalse("There is some reordered items in the list", list.contains(false));
    }));
    Job job = hz.getJet().newJob(p);
    try {
        job.join();
        fail("Job should have completed with an AssertionCompletedException, but completed normally");
    } catch (CompletionException e) {
        String errorMsg = e.getCause().getMessage();
        assertTrue("Job was expected to complete with AssertionCompletedException, but completed with: " + e.getCause(), errorMsg.contains(AssertionCompletedException.class.getName()));
    }
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) ParallelStreamP(com.hazelcast.jet.pipeline.test.ParallelStreamP) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) JetAssert.assertFalse(com.hazelcast.jet.core.test.JetAssert.assertFalse) JetAssert.assertTrue(com.hazelcast.jet.core.test.JetAssert.assertTrue) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AfterClass(org.junit.AfterClass) LongStream(java.util.stream.LongStream) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Category(org.junit.experimental.categories.Category) Serializable(java.io.Serializable) Objects(java.util.Objects) JetAssert.fail(com.hazelcast.jet.core.test.JetAssert.fail) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GeneratorFunction(com.hazelcast.jet.pipeline.test.GeneratorFunction) Hazelcast(com.hazelcast.core.Hazelcast) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Assert(org.junit.Assert) Util(com.hazelcast.jet.Util) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) CompletionException(java.util.concurrent.CompletionException) Job(com.hazelcast.jet.Job) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Hazelcast (com.hazelcast.core.Hazelcast)7 Job (com.hazelcast.jet.Job)7 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)7 JetTestSupport (com.hazelcast.jet.core.JetTestSupport)7 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)7 JetAssert.assertFalse (com.hazelcast.jet.core.test.JetAssert.assertFalse)7 JetAssert.assertTrue (com.hazelcast.jet.core.test.JetAssert.assertTrue)7 JetAssert.fail (com.hazelcast.jet.core.test.JetAssert.fail)7 AssertionCompletedException (com.hazelcast.jet.pipeline.test.AssertionCompletedException)7 AssertionSinks (com.hazelcast.jet.pipeline.test.AssertionSinks)7 GeneratorFunction (com.hazelcast.jet.pipeline.test.GeneratorFunction)7 ParallelStreamP (com.hazelcast.jet.pipeline.test.ParallelStreamP)7 TestSources (com.hazelcast.jet.pipeline.test.TestSources)7 HazelcastSerialParametersRunnerFactory (com.hazelcast.test.HazelcastSerialParametersRunnerFactory)7 Serializable (java.io.Serializable)7 Arrays (java.util.Arrays)7 List (java.util.List)7 Objects (java.util.Objects)7 CompletionException (java.util.concurrent.CompletionException)7 Collectors.toList (java.util.stream.Collectors.toList)7