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");
}
}
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);
}
Aggregations