Search in sources :

Example 26 with JetServiceBackend

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

the class SplitBrainTest method when_quorumIsLostOnBothSides_then_jobRestartsAfterMerge.

@Test
public void when_quorumIsLostOnBothSides_then_jobRestartsAfterMerge() {
    int firstSubClusterSize = 2;
    int secondSubClusterSize = 2;
    int clusterSize = firstSubClusterSize + secondSubClusterSize;
    NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    Consumer<HazelcastInstance[]> beforeSplit = instances -> {
        MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = instances[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
        assertOpenEventually(NoOutputSourceP.executionStarted);
    };
    BiConsumer<HazelcastInstance[], HazelcastInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        NoOutputSourceP.proceedLatch.countDown();
        long jobId = jobRef[0].getId();
        assertTrueEventually(() -> {
            JetServiceBackend service1 = getJetServiceBackend(firstSubCluster[0]);
            JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
            MasterContext masterContext = service1.getJobCoordinationService().getMasterContext(jobId);
            assertNotNull(masterContext);
            masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
            assertNotNull(masterContext);
        });
        assertTrueAllTheTime(() -> {
            JetServiceBackend service1 = getJetServiceBackend(firstSubCluster[0]);
            JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
            JobStatus status1 = service1.getJobCoordinationService().getJobStatus(jobId).get();
            JobStatus status2 = service2.getJobCoordinationService().getJobStatus(jobId).get();
            assertStatusNotRunningOrStarting(status1);
            assertStatusNotRunningOrStarting(status2);
        }, 20);
    };
    Consumer<HazelcastInstance[]> 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("received " + t, t instanceof CancellationException));
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
Also used : MasterContext(com.hazelcast.jet.impl.MasterContext) NOT_RUNNING(com.hazelcast.jet.core.JobStatus.NOT_RUNNING) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClusterService(com.hazelcast.internal.cluster.ClusterService) 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) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NightlyTest(com.hazelcast.test.annotation.NightlyTest) CancellationException(java.util.concurrent.CancellationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) CountDownLatch(java.util.concurrent.CountDownLatch) JobConfig(com.hazelcast.jet.config.JobConfig) CancellationException(java.util.concurrent.CancellationException) Job(com.hazelcast.jet.Job) MasterContext(com.hazelcast.jet.impl.MasterContext) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 27 with JetServiceBackend

use of com.hazelcast.jet.impl.JetServiceBackend in project hazelcast 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;
    NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
    Job[] jobRef = new Job[1];
    Consumer<HazelcastInstance[]> beforeSplit = instances -> {
        MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
        DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
        jobRef[0] = instances[0].getJet().newJob(dag);
        assertOpenEventually(NoOutputSourceP.executionStarted);
    };
    BiConsumer<HazelcastInstance[], HazelcastInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
        NoOutputSourceP.proceedLatch.countDown();
        long jobId = jobRef[0].getId();
        assertTrueEventually(() -> {
            JetServiceBackend service1 = getJetServiceBackend(firstSubCluster[0]);
            JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
            assertEquals(COMPLETED, service1.getJobCoordinationService().getJobStatus(jobId).get());
            assertEquals(COMPLETED, service2.getJobCoordinationService().getJobStatus(jobId).get());
        });
    };
    Consumer<HazelcastInstance[]> afterMerge = instances -> {
        assertTrueEventually(() -> {
            assertEquals("init count", clusterSize * 2, MockPS.initCount.get());
            assertEquals("close count", clusterSize * 2, MockPS.closeCount.get());
        });
        assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
        MockPS.receivedCloseErrors.forEach(t -> assertTrue("received " + t, t instanceof CancellationException));
    };
    testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
Also used : MasterContext(com.hazelcast.jet.impl.MasterContext) NOT_RUNNING(com.hazelcast.jet.core.JobStatus.NOT_RUNNING) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClusterService(com.hazelcast.internal.cluster.ClusterService) 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) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NightlyTest(com.hazelcast.test.annotation.NightlyTest) CancellationException(java.util.concurrent.CancellationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) CancellationException(java.util.concurrent.CancellationException) CountDownLatch(java.util.concurrent.CountDownLatch) Job(com.hazelcast.jet.Job) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 28 with JetServiceBackend

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

the class ExecutionLifecycleTest method getJobResult.

private JobResult getJobResult(Job job) {
    JetServiceBackend jetServiceBackend = getJetServiceBackend(instance());
    assertNull(jetServiceBackend.getJobRepository().getJobRecord(job.getId()));
    JobResult jobResult = jetServiceBackend.getJobRepository().getJobResult(job.getId());
    assertNotNull(jobResult);
    return jobResult;
}
Also used : JobResult(com.hazelcast.jet.impl.JobResult) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 29 with JetServiceBackend

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

the class VertexDef_HigherPrioritySourceTest method assertHigherPriorityVertices.

private void assertHigherPriorityVertices(Vertex... vertices) {
    JobConfig jobConfig = new JobConfig();
    Map<MemberInfo, ExecutionPlan> executionPlans = createExecutionPlans(nodeEngineImpl, membersView, dag, 0, 0, jobConfig, 0, false, null);
    ExecutionPlan plan = executionPlans.values().iterator().next();
    SnapshotContext ssContext = new SnapshotContext(mock(ILogger.class), "job", 0, EXACTLY_ONCE);
    // In the production code the plan#initialize is only called from places where we have already set up the
    // processor classloaders
    JetServiceBackend jetService = nodeEngineImpl.getService(JetServiceBackend.SERVICE_NAME);
    jetService.getJobClassLoaderService().getOrCreateClassLoader(jobConfig, 0, JobPhase.EXECUTION);
    try {
        jetService.getJobClassLoaderService().prepareProcessorClassLoaders(0);
        plan.initialize(nodeEngineImpl, 0, 0, ssContext, null, (InternalSerializationService) nodeEngineImpl.getSerializationService());
    } finally {
        jetService.getJobClassLoaderService().clearProcessorClassLoaders();
    }
    jetService.getJobClassLoaderService().tryRemoveClassloadersForJob(0, JobPhase.EXECUTION);
    Set<Integer> higherPriorityVertices = VertexDef.getHigherPriorityVertices(plan.getVertices());
    String actualHigherPriorityVertices = plan.getVertices().stream().filter(v -> higherPriorityVertices.contains(v.vertexId())).map(VertexDef::name).sorted().collect(joining("\n"));
    String expectedVertices = Arrays.stream(vertices).map(Vertex::getName).sorted().collect(joining("\n"));
    assertEquals(expectedVertices, actualHigherPriorityVertices);
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) ExecutionPlanBuilder.createExecutionPlans(com.hazelcast.jet.impl.execution.init.ExecutionPlanBuilder.createExecutionPlans) SnapshotContext(com.hazelcast.jet.impl.execution.SnapshotContext) BeforeClass(org.junit.BeforeClass) MasterJobContext(com.hazelcast.jet.impl.MasterJobContext) QuickTest(com.hazelcast.test.annotation.QuickTest) ILogger(com.hazelcast.logging.ILogger) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) Edge.from(com.hazelcast.jet.core.Edge.from) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) JobPhase(com.hazelcast.jet.impl.JobClassLoaderService.JobPhase) Collections.nCopies(java.util.Collections.nCopies) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Field(java.lang.reflect.Field) Collectors.joining(java.util.stream.Collectors.joining) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) Edge.between(com.hazelcast.jet.core.Edge.between) Mockito.mock(org.mockito.Mockito.mock) Vertex(com.hazelcast.jet.core.Vertex) JobConfig(com.hazelcast.jet.config.JobConfig) SnapshotContext(com.hazelcast.jet.impl.execution.SnapshotContext) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) ILogger(com.hazelcast.logging.ILogger) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 30 with JetServiceBackend

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

the class NonSmartClientTest method when_lightJobSubmittedToNonMaster_then_coordinatedByNonMaster.

@Test
public void when_lightJobSubmittedToNonMaster_then_coordinatedByNonMaster() {
    Job job = nonMasterClient.getJet().newLightJob(streamingDag());
    JetServiceBackend service = getNodeEngineImpl(nonMasterInstance).getService(JetServiceBackend.SERVICE_NAME);
    assertTrueEventually(() -> assertNotNull(service.getJobCoordinationService().getLightMasterContexts().get(job.getId())));
}
Also used : Job(com.hazelcast.jet.Job) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)32 JobConfig (com.hazelcast.jet.config.JobConfig)14 Test (org.junit.Test)14 Job (com.hazelcast.jet.Job)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)9 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 JobRepository (com.hazelcast.jet.impl.JobRepository)8 Map (java.util.Map)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Config (com.hazelcast.config.Config)7 Category (org.junit.experimental.categories.Category)7 RunWith (org.junit.runner.RunWith)7 Address (com.hazelcast.cluster.Address)6 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)6 HazelcastSerialClassRunner (com.hazelcast.test.HazelcastSerialClassRunner)6 CancellationException (java.util.concurrent.CancellationException)6 Collectors (java.util.stream.Collectors)6 Assert.assertTrue (org.junit.Assert.assertTrue)6