Search in sources :

Example 31 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class SplitBrainTest method when_splitBrainProtectionIsDisabled_then_jobCompletesOnBothSides.

@Test
public void when_splitBrainProtectionIsDisabled_then_jobCompletesOnBothSides() {
    int firstSubClusterSize = 2;
    int secondSubClusterSize = 2;
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    StuckProcessor.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    Consumer<JetInstance[]> beforeSplit = instances -> {
        MockPS processorSupplier = new MockPS(StuckProcessor::new, clusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = instances[0].newJob(dag);
        assertOpenEventually(StuckProcessor.executionStarted);
    };
    BiConsumer<JetInstance[], JetInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        StuckProcessor.proceedLatch.countDown();
        long jobId = jobRef[0].getId();
        assertTrueEventually(() -> {
            JetService service1 = getJetService(firstSubCluster[0]);
            JetService service2 = getJetService(secondSubCluster[0]);
            assertEquals(COMPLETED, service1.getJobCoordinationService().getJobStatus(jobId));
            assertEquals(COMPLETED, service2.getJobCoordinationService().getJobStatus(jobId));
        });
    };
    Consumer<JetInstance[]> afterMerge = instances -> {
        assertTrueEventually(() -> {
            assertEquals(clusterSize * 2, MockPS.initCount.get());
            assertEquals(clusterSize * 2, MockPS.closeCount.get());
        });
        assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
        MockPS.receivedCloseErrors.forEach(t -> assertTrue(t instanceof TopologyChangedException));
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
Also used : MasterContext(com.hazelcast.jet.impl.MasterContext) JetInstance(com.hazelcast.jet.JetInstance) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Future(java.util.concurrent.Future) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) BiConsumer(java.util.function.BiConsumer) Assert.fail(org.junit.Assert.fail) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JetConfig(com.hazelcast.jet.config.JetConfig) MAX_BACKUP_COUNT(com.hazelcast.spi.partition.IPartition.MAX_BACKUP_COUNT) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) CancellationException(java.util.concurrent.CancellationException) RESTARTING(com.hazelcast.jet.core.JobStatus.RESTARTING) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) JetService(com.hazelcast.jet.impl.JetService) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) JobRecord(com.hazelcast.jet.impl.JobRecord) Assert.assertEquals(org.junit.Assert.assertEquals) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JetService(com.hazelcast.jet.impl.JetService) CountDownLatch(java.util.concurrent.CountDownLatch) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 32 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class TopologyChangeDuringJobSubmissionTest method when_coordinatorLeavesDuringSubmission_then_submissionCallReturnsSuccessfully.

@Test
public void when_coordinatorLeavesDuringSubmission_then_submissionCallReturnsSuccessfully() throws Throwable {
    // Given that the job has submitted
    dropOperationsBetween(instance1.getHazelcastInstance(), instance2.getHazelcastInstance(), SpiDataSerializerHook.F_ID, singletonList(SpiDataSerializerHook.NORMAL_RESPONSE));
    Future<Job> future = spawn(() -> {
        DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, 1)));
        return instance2.newJob(dag);
    });
    StuckProcessor.executionStarted.await();
    // When the coordinator leaves before the submission response is received
    instance1.getHazelcastInstance().getLifecycleService().terminate();
    Job job = future.get();
    // Then the job completes successfully
    StuckProcessor.proceedLatch.countDown();
    job.join();
    assertEquals(2, MockPS.initCount.get());
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 33 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class TopologyChangeTest method when_addNodeDuringExecution_then_completeSuccessfully.

@Test
public void when_addNodeDuringExecution_then_completeSuccessfully() throws Throwable {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
    // When
    Job job = instances[0].newJob(dag);
    StuckProcessor.executionStarted.await();
    createJetMember();
    StuckProcessor.proceedLatch.countDown();
    job.join();
    // Then
    assertEquals(nodeCount, MockPS.initCount.get());
    assertTrueEventually(() -> {
        assertEquals(nodeCount, MockPS.closeCount.get());
        assertThat(MockPS.receivedCloseErrors, empty());
    });
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 34 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class TopologyChangeTest method when_nonCoordinatorLeavesDuringExecutionAndNoRestartConfigured_then_jobFails.

@Test
public void when_nonCoordinatorLeavesDuringExecutionAndNoRestartConfigured_then_jobFails() throws Throwable {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
    JobConfig config = new JobConfig().setAutoRestartOnMemberFailure(false);
    // When
    Job job = instances[0].newJob(dag, config);
    StuckProcessor.executionStarted.await();
    instances[2].getHazelcastInstance().getLifecycleService().terminate();
    StuckProcessor.proceedLatch.countDown();
    Throwable ex = job.getFuture().handle((r, e) -> e).get();
    assertInstanceOf(TopologyChangedException.class, ex);
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) Arrays(java.util.Arrays) INIT_EXECUTION_OP(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook.INIT_EXECUTION_OP) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) PacketFiltersUtil.dropOperationsBetween(com.hazelcast.test.PacketFiltersUtil.dropOperationsBetween) PacketFiltersUtil.rejectOperationsBetween(com.hazelcast.test.PacketFiltersUtil.rejectOperationsBetween) Future(java.util.concurrent.Future) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) Assert.fail(org.junit.Assert.fail) ClusterDataSerializerHook(com.hazelcast.internal.cluster.impl.ClusterDataSerializerHook) Parameterized(org.junit.runners.Parameterized) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MEMBER_INFO_UPDATE(com.hazelcast.internal.cluster.impl.ClusterDataSerializerHook.MEMBER_INFO_UPDATE) Collection(java.util.Collection) START_EXECUTION_OP(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook.START_EXECUTION_OP) JobConfig(com.hazelcast.jet.config.JobConfig) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Set(java.util.Set) PartitionDataSerializerHook(com.hazelcast.internal.partition.impl.PartitionDataSerializerHook) JobResult(com.hazelcast.jet.impl.JobResult) CountDownLatch(java.util.concurrent.CountDownLatch) Assert.assertFalse(org.junit.Assert.assertFalse) MasterContext(com.hazelcast.jet.impl.MasterContext) JetInstance(com.hazelcast.jet.JetInstance) RunWith(org.junit.runner.RunWith) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) HashSet(java.util.HashSet) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) Before(org.junit.Before) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JetConfig(com.hazelcast.jet.config.JetConfig) Matchers.empty(org.hamcrest.Matchers.empty) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) JetService(com.hazelcast.jet.impl.JetService) HazelcastParametersRunnerFactory(com.hazelcast.test.HazelcastParametersRunnerFactory) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Assert(org.junit.Assert) PacketFiltersUtil.resetPacketFiltersFrom(com.hazelcast.test.PacketFiltersUtil.resetPacketFiltersFrom) Assert.assertEquals(org.junit.Assert.assertEquals) SHUTDOWN_REQUEST(com.hazelcast.internal.partition.impl.PartitionDataSerializerHook.SHUTDOWN_REQUEST) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Example 35 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.

the class TopologyChangeTest method when_coordinatorLeavesDuringExecutionAndNoRestartConfigured_then_jobFails.

@Test
public void when_coordinatorLeavesDuringExecutionAndNoRestartConfigured_then_jobFails() throws Throwable {
    // Given
    JetInstance client = createJetClient();
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
    JobConfig config = new JobConfig().setAutoRestartOnMemberFailure(false);
    // When
    Job job = client.newJob(dag, config);
    StuckProcessor.executionStarted.await();
    instances[0].getHazelcastInstance().getLifecycleService().terminate();
    StuckProcessor.proceedLatch.countDown();
    Throwable ex = job.getFuture().handle((r, e) -> e).get();
    assertInstanceOf(TopologyChangedException.class, ex);
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) Arrays(java.util.Arrays) INIT_EXECUTION_OP(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook.INIT_EXECUTION_OP) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) PacketFiltersUtil.dropOperationsBetween(com.hazelcast.test.PacketFiltersUtil.dropOperationsBetween) PacketFiltersUtil.rejectOperationsBetween(com.hazelcast.test.PacketFiltersUtil.rejectOperationsBetween) Future(java.util.concurrent.Future) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) Assert.fail(org.junit.Assert.fail) ClusterDataSerializerHook(com.hazelcast.internal.cluster.impl.ClusterDataSerializerHook) Parameterized(org.junit.runners.Parameterized) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MEMBER_INFO_UPDATE(com.hazelcast.internal.cluster.impl.ClusterDataSerializerHook.MEMBER_INFO_UPDATE) Collection(java.util.Collection) START_EXECUTION_OP(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook.START_EXECUTION_OP) JobConfig(com.hazelcast.jet.config.JobConfig) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Set(java.util.Set) PartitionDataSerializerHook(com.hazelcast.internal.partition.impl.PartitionDataSerializerHook) JobResult(com.hazelcast.jet.impl.JobResult) CountDownLatch(java.util.concurrent.CountDownLatch) Assert.assertFalse(org.junit.Assert.assertFalse) MasterContext(com.hazelcast.jet.impl.MasterContext) JetInstance(com.hazelcast.jet.JetInstance) RunWith(org.junit.runner.RunWith) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) HashSet(java.util.HashSet) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) Before(org.junit.Before) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JetConfig(com.hazelcast.jet.config.JetConfig) Matchers.empty(org.hamcrest.Matchers.empty) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) JetService(com.hazelcast.jet.impl.JetService) HazelcastParametersRunnerFactory(com.hazelcast.test.HazelcastParametersRunnerFactory) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Assert(org.junit.Assert) PacketFiltersUtil.resetPacketFiltersFrom(com.hazelcast.test.PacketFiltersUtil.resetPacketFiltersFrom) Assert.assertEquals(org.junit.Assert.assertEquals) SHUTDOWN_REQUEST(com.hazelcast.internal.partition.impl.PartitionDataSerializerHook.SHUTDOWN_REQUEST) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) JetInstance(com.hazelcast.jet.JetInstance) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Aggregations

MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)37 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)37 Job (com.hazelcast.jet.Job)36 Test (org.junit.Test)32 JobConfig (com.hazelcast.jet.config.JobConfig)20 JetInstance (com.hazelcast.jet.JetInstance)12 JetConfig (com.hazelcast.jet.config.JetConfig)8 JobRepository (com.hazelcast.jet.impl.JobRepository)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JetService (com.hazelcast.jet.impl.JetService)7 STARTING (com.hazelcast.jet.core.JobStatus.STARTING)6 MasterContext (com.hazelcast.jet.impl.MasterContext)6 Future (java.util.concurrent.Future)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertNotNull (org.junit.Assert.assertNotNull)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 Assert.fail (org.junit.Assert.fail)6 Rule (org.junit.Rule)6 ExpectedException (org.junit.rules.ExpectedException)6 RunWith (org.junit.runner.RunWith)6