Search in sources :

Example 16 with EXACTLY_ONCE

use of com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE in project hazelcast by hazelcast.

the class JmsSourceIntegrationTestBase method when_messageIdFn_then_used.

@Test
public void when_messageIdFn_then_used() throws JMSException {
    StreamSource<String> source = Sources.jmsQueueBuilder(getConnectionFactory()).destinationName(destinationName).messageIdFn(m -> {
        throw new RuntimeException("mock exception");
    }).build(TEXT_MESSAGE_FN);
    p.readFrom(source).withoutTimestamps().writeTo(Sinks.logger());
    Job job = instance().getJet().newJob(p, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE));
    sendMessages(true);
    try {
        job.join();
        fail("job didn't fail");
    } catch (Exception e) {
        assertContains(e.toString(), "mock exception");
    }
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Mockito.doThrow(org.mockito.Mockito.doThrow) Session(javax.jms.Session) Future(java.util.concurrent.Future) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) MessageProducer(javax.jms.MessageProducer) JobStatus(com.hazelcast.jet.core.JobStatus) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) PredicateEx.alwaysFalse(com.hazelcast.function.PredicateEx.alwaysFalse) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Instant(java.time.Instant) DUPS_OK_ACKNOWLEDGE(javax.jms.Session.DUPS_OK_ACKNOWLEDGE) JMSException(javax.jms.JMSException) Collectors(java.util.stream.Collectors) SupplierEx(com.hazelcast.function.SupplierEx) ZoneId(java.time.ZoneId) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) MessageConsumer(javax.jms.MessageConsumer) Assert.assertFalse(org.junit.Assert.assertFalse) WindowResult(com.hazelcast.jet.datamodel.WindowResult) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeClass(org.junit.BeforeClass) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) AUTO_ACKNOWLEDGE(javax.jms.Session.AUTO_ACKNOWLEDGE) MINUTES(java.util.concurrent.TimeUnit.MINUTES) JobProxy(com.hazelcast.jet.impl.JobProxy) StreamSource(com.hazelcast.jet.pipeline.StreamSource) ExceptionUtil.sneakyThrow(com.hazelcast.jet.impl.util.ExceptionUtil.sneakyThrow) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MapWatermarksToString.mapWatermarksToString(com.hazelcast.jet.core.TestProcessors.MapWatermarksToString.mapWatermarksToString) JmsSourceBuilder(com.hazelcast.jet.pipeline.JmsSourceBuilder) Message(javax.jms.Message) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) JobRepository(com.hazelcast.jet.impl.JobRepository) Connection(javax.jms.Connection) TextMessage(javax.jms.TextMessage) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) NONE(com.hazelcast.jet.config.ProcessingGuarantee.NONE) TreeMap(java.util.TreeMap) JmsTestUtil.consumeMessages(com.hazelcast.jet.impl.connector.JmsTestUtil.consumeMessages) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) AT_LEAST_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.AT_LEAST_ONCE) ConnectionFactory(javax.jms.ConnectionFactory) Assert.assertEquals(org.junit.Assert.assertEquals) MapWatermarksToString.mapWatermarksToString(com.hazelcast.jet.core.TestProcessors.MapWatermarksToString.mapWatermarksToString) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 17 with EXACTLY_ONCE

use of com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE in project hazelcast by hazelcast.

the class WriteFilePTest method stressTest.

private void stressTest(boolean graceful, boolean exactlyOnce) throws Exception {
    int numItems = 500;
    Pipeline p = Pipeline.create();
    p.readFrom(SourceBuilder.stream("src", procCtx -> tuple2(new int[1], procCtx.logger())).fillBufferFn((ctx, buf) -> {
        if (ctx.f0()[0] < numItems) {
            buf.add(ctx.f0()[0]++);
            sleepMillis(5);
        }
    }).createSnapshotFn(ctx -> {
        ctx.f1().fine("src vertex saved to snapshot: " + ctx.f0()[0]);
        return ctx.f0()[0];
    }).restoreSnapshotFn((ctx, state) -> {
        ctx.f0()[0] = state.get(0);
        ctx.f1().fine("src vertex restored from snapshot: " + ctx.f0()[0]);
    }).build()).withoutTimestamps().writeTo(Sinks.filesBuilder(directory.toString()).exactlyOnce(exactlyOnce).build()).setLocalParallelism(2);
    JobConfig config = new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(50);
    JobProxy job = (JobProxy) instance().getJet().newJob(p, config);
    long endTime = System.nanoTime() + SECONDS.toNanos(60);
    do {
        assertJobStatusEventually(job, RUNNING);
        sleepMillis(100);
        job.restart(graceful);
        try {
            checkFileContents(0, numItems, exactlyOnce, true, false);
            // if content matches, break the loop. Otherwise restart and try again
            break;
        } catch (AssertionError ignored) {
        }
    } while (System.nanoTime() < endTime);
    waitForNextSnapshot(new JobRepository(instance()), job.getId(), 10, true);
    ditchJob(job, instances());
    // when the job is cancelled, there should be no temporary files
    checkFileContents(0, numItems, exactlyOnce, false, false);
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) LongSupplier(java.util.function.LongSupplier) QuickTest(com.hazelcast.test.annotation.QuickTest) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) After(org.junit.After) Map(java.util.Map) DAG(com.hazelcast.jet.core.DAG) Path(java.nio.file.Path) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) TestSupport(com.hazelcast.jet.core.test.TestSupport) DISABLE_ROLLING(com.hazelcast.jet.pipeline.FileSinkBuilder.DISABLE_ROLLING) Util.uncheckCall(com.hazelcast.jet.impl.util.Util.uncheckCall) TEMP_FILE_SUFFIX(com.hazelcast.jet.pipeline.FileSinkBuilder.TEMP_FILE_SUFFIX) IntStream(java.util.stream.IntStream) BeforeClass(org.junit.BeforeClass) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) JobProxy(com.hazelcast.jet.impl.JobProxy) Function(java.util.function.Function) Charset(java.nio.charset.Charset) TestPerson(com.hazelcast.jet.impl.connector.ReadFilesPTest.TestPerson) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) TestInbox(com.hazelcast.jet.core.test.TestInbox) JobRepository(com.hazelcast.jet.impl.JobRepository) IOUtil(com.hazelcast.internal.nio.IOUtil) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Semaphore(java.util.concurrent.Semaphore) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) Vertex(com.hazelcast.jet.core.Vertex) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestSources(com.hazelcast.jet.pipeline.test.TestSources) SinkProcessors.writeFileP(com.hazelcast.jet.core.processor.SinkProcessors.writeFileP) JSON(com.fasterxml.jackson.jr.ob.JSON) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) HOURS(java.util.concurrent.TimeUnit.HOURS) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Comparator(java.util.Comparator) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) JobProxy(com.hazelcast.jet.impl.JobProxy) JobRepository(com.hazelcast.jet.impl.JobRepository) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Aggregations

EXACTLY_ONCE (com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE)17 JobConfig (com.hazelcast.jet.config.JobConfig)16 Assert.assertEquals (org.junit.Assert.assertEquals)16 Test (org.junit.Test)15 Job (com.hazelcast.jet.Job)14 Assert.assertTrue (org.junit.Assert.assertTrue)13 JobRepository (com.hazelcast.jet.impl.JobRepository)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)12 Map (java.util.Map)12 Category (org.junit.experimental.categories.Category)12 Before (org.junit.Before)11 List (java.util.List)10 Config (com.hazelcast.config.Config)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 FunctionEx (com.hazelcast.function.FunctionEx)9 Edge.between (com.hazelcast.jet.core.Edge.between)9 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)9 Collectors (java.util.stream.Collectors)9 IntStream (java.util.stream.IntStream)9 IList (com.hazelcast.collection.IList)8