Search in sources :

Example 21 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class SuspendResumeTest method when_cancelSuspendedJob_then_jobCancels.

@Test
public void when_cancelSuspendedJob_then_jobCancels() throws Exception {
    Job job = instances[0].getJet().newJob(dag);
    NoOutputSourceP.executionStarted.await();
    job.suspend();
    assertJobStatusEventually(job, SUSPENDED);
    // When-Then
    cancelAndJoin(job);
    assertJobStatusEventually(job, FAILED);
    // check that job resources are deleted
    JobRepository jobRepository = new JobRepository(instances[0]);
    assertTrueEventually(() -> {
        assertNull("JobRecord", jobRepository.getJobRecord(job.getId()));
        JobResult jobResult = jobRepository.getJobResult(job.getId());
        assertContains(jobResult.getFailureText(), CancellationException.class.getName());
        assertFalse("Job result successful", jobResult.isSuccessful());
    });
}
Also used : JobResult(com.hazelcast.jet.impl.JobResult) CancellationException(java.util.concurrent.CancellationException) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 22 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class SourceBuilder_TopologyChangeTest method testTopologyChange.

private void testTopologyChange(Supplier<HazelcastInstance> secondMemberSupplier, Consumer<HazelcastInstance> changeTopologyFn, boolean assertMonotonicity) {
    stateRestored = false;
    StreamSource<Integer> source = SourceBuilder.timestampedStream("src", ctx -> new NumberGeneratorContext()).<Integer>fillBufferFn((src, buffer) -> {
        long expectedCount = NANOSECONDS.toMillis(System.nanoTime() - src.startTime);
        expectedCount = Math.min(expectedCount, src.current + 100);
        while (src.current < expectedCount) {
            buffer.add(src.current, src.current);
            src.current++;
        }
    }).createSnapshotFn(src -> {
        System.out.println("Will save " + src.current + " to snapshot");
        return src;
    }).restoreSnapshotFn((src, states) -> {
        stateRestored = true;
        assert states.size() == 1;
        src.restore(states.get(0));
        System.out.println("Restored " + src.current + " from snapshot");
    }).build();
    Config config = smallInstanceConfig();
    // restart sooner after member add
    config.getJetConfig().setScaleUpDelayMillis(1000);
    HazelcastInstance hz = createHazelcastInstance(config);
    HazelcastInstance possibleSecondNode = secondMemberSupplier.get();
    long windowSize = 100;
    IList<WindowResult<Long>> result = hz.getList("result-" + UuidUtil.newUnsecureUuidString());
    Pipeline p = Pipeline.create();
    p.readFrom(source).withNativeTimestamps(0).window(tumbling(windowSize)).aggregate(AggregateOperations.counting()).peek().writeTo(Sinks.list(result));
    Job job = hz.getJet().newJob(p, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(500));
    assertTrueEventually(() -> assertFalse("result list is still empty", result.isEmpty()));
    assertJobStatusEventually(job, JobStatus.RUNNING);
    JobRepository jr = new JobRepository(hz);
    waitForFirstSnapshot(jr, job.getId(), 10, false);
    assertFalse(stateRestored);
    changeTopologyFn.accept(possibleSecondNode);
    assertTrueEventually(() -> assertTrue("restoreSnapshotFn was not called", stateRestored));
    // wait until more results are added
    int oldSize = result.size();
    assertTrueEventually(() -> assertTrue("no more results added to the list", result.size() > oldSize));
    cancelAndJoin(job);
    // results should contain sequence of results, each with count=windowSize, monotonic, if job was
    // allowed to terminate gracefully
    Iterator<WindowResult<Long>> iterator = result.iterator();
    for (int i = 0; i < result.size(); i++) {
        WindowResult<Long> next = iterator.next();
        assertEquals(windowSize, (long) next.result());
        if (assertMonotonicity) {
            assertEquals(i * windowSize, next.start());
        }
    }
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) RunWith(org.junit.runner.RunWith) Supplier(java.util.function.Supplier) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) UuidUtil(com.hazelcast.internal.util.UuidUtil) JobStatus(com.hazelcast.jet.core.JobStatus) Job(com.hazelcast.jet.Job) IList(com.hazelcast.collection.IList) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Iterator(java.util.Iterator) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) JobConfig(com.hazelcast.jet.config.JobConfig) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) Config(com.hazelcast.config.Config) JobConfig(com.hazelcast.jet.config.JobConfig) JobRepository(com.hazelcast.jet.impl.JobRepository) JobConfig(com.hazelcast.jet.config.JobConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) WindowResult(com.hazelcast.jet.datamodel.WindowResult) Job(com.hazelcast.jet.Job)

Example 23 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class JobRestartStressTestBase method stressTest.

// has sub-classes in jet-enterprise
@SuppressWarnings("WeakerAccess")
protected void stressTest(Function<Tuple3<HazelcastInstance, DAG, Job>, Job> action) throws Exception {
    JobRepository jobRepository = new JobRepository(instance1);
    TestProcessors.reset(2);
    DAG dag = new DAG();
    dag.newVertex("dummy-stateful-p", DummyStatefulP::new).localParallelism(1);
    Job[] job = { instance1.getJet().newJob(dag, new JobConfig().setSnapshotIntervalMillis(10).setProcessingGuarantee(EXACTLY_ONCE)) };
    logger.info("waiting for 1st snapshot");
    waitForFirstSnapshot(jobRepository, job[0].getId(), 5, false);
    logger.info("first snapshot found");
    for (int i = 0; i < 10; i++) {
        job[0] = action.apply(tuple3(instance1, dag, job[0]));
        waitForNextSnapshot(jobRepository, job[0].getId(), 5, false);
    }
    cancelAndJoin(job[0]);
}
Also used : JobRepository(com.hazelcast.jet.impl.JobRepository) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 24 with JobRepository

use of com.hazelcast.jet.impl.JobRepository in project hazelcast by hazelcast.

the class JmsSourceIntegrationTestBase method when_exactlyOnceTopicDefaultConsumer_then_noGuaranteeUsed.

@Test
public void when_exactlyOnceTopicDefaultConsumer_then_noGuaranteeUsed() {
    SupplierEx<ConnectionFactory> mockSupplier = () -> {
        ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
        Connection mockConn = mock(Connection.class);
        Session mockSession = mock(Session.class);
        MessageConsumer mockConsumer = mock(MessageConsumer.class);
        when(mockConnectionFactory.createConnection()).thenReturn(mockConn);
        when(mockConn.createSession(anyBoolean(), anyInt())).thenReturn(mockSession);
        when(mockSession.createConsumer(any())).thenReturn(mockConsumer);
        // throw, if commit is called
        doThrow(new AssertionError("commit must not be called")).when(mockSession).commit();
        return (ConnectionFactory) mockConnectionFactory;
    };
    p.readFrom(Sources.jmsTopic(destinationName, mockSupplier)).withoutTimestamps().writeTo(Sinks.logger());
    Job job = instance().getJet().newJob(p, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(10));
    assertJobStatusEventually(job, RUNNING);
    JobRepository jr = new JobRepository(instance());
    waitForFirstSnapshot(jr, job.getId(), 5, true);
    assertTrueAllTheTime(() -> assertEquals(RUNNING, job.getStatus()), 1);
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JobConfig(com.hazelcast.jet.config.JobConfig) Session(javax.jms.Session) Test(org.junit.Test)

Example 25 with JobRepository

use of com.hazelcast.jet.impl.JobRepository 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

Job (com.hazelcast.jet.Job)26 JobRepository (com.hazelcast.jet.impl.JobRepository)26 JobConfig (com.hazelcast.jet.config.JobConfig)22 Test (org.junit.Test)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 EXACTLY_ONCE (com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE)7 JobExecutionRecord (com.hazelcast.jet.impl.JobExecutionRecord)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)5 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Category (org.junit.experimental.categories.Category)5 Config (com.hazelcast.config.Config)4 Edge.between (com.hazelcast.jet.core.Edge.between)4 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)4