use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast by hazelcast.
the class TopologyChangeTest method when_addAndRemoveNodeDuringExecution_then_completeSuccessfully.
@Test
public void when_addAndRemoveNodeDuringExecution_then_completeSuccessfully() throws Throwable {
// Given
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
// When
Job job = instances[0].getJet().newJob(dag);
NoOutputSourceP.executionStarted.await();
HazelcastInstance instance = createHazelcastInstance(config);
instance.shutdown();
NoOutputSourceP.proceedLatch.countDown();
job.join();
// Then
assertEquals(nodeCount, MockPS.initCount.get());
assertTrueEventually(() -> {
assertEquals(nodeCount, MockPS.closeCount.get());
assertThat(MockPS.receivedCloseErrors, empty());
});
}
use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast by hazelcast.
the class TopologyChangeTest method when_nonCoordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends.
private void when_nonCoordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends(boolean snapshotted) throws Throwable {
// Given
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
JobConfig config = new JobConfig();
config.setAutoScaling(false);
config.setProcessingGuarantee(snapshotted ? EXACTLY_ONCE : NONE);
// When
Job job = instances[0].getJet().newJob(dag, config);
NoOutputSourceP.executionStarted.await();
instances[2].getLifecycleService().terminate();
NoOutputSourceP.proceedLatch.countDown();
assertJobStatusEventually(job, snapshotted ? SUSPENDED : FAILED, 10);
if (!snapshotted) {
try {
job.join();
fail("join didn't fail");
} catch (Exception e) {
assertContains(e.getMessage(), TopologyChangedException.class.getName());
assertContains(e.getMessage(), "[127.0.0.1]:5703=" + MemberLeftException.class.getName());
}
}
}
use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast by hazelcast.
the class ScaleUpTest method setup.
private void setup(long scaleUpDelay) {
TestProcessors.reset(NODE_COUNT * LOCAL_PARALLELISM);
dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, NODE_COUNT)));
config = smallInstanceConfig();
config.getJetConfig().setScaleUpDelayMillis(scaleUpDelay);
instances = createHazelcastInstances(config, NODE_COUNT);
}
use of com.hazelcast.jet.core.TestProcessors.MockPS 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);
}
use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast by hazelcast.
the class SplitBrainTest method when_newMemberIsAddedAfterClusterSizeFallsBelowQuorumSize_then_jobRestartDoesNotSucceed.
@Test
public void when_newMemberIsAddedAfterClusterSizeFallsBelowQuorumSize_then_jobRestartDoesNotSucceed() {
int clusterSize = 5;
HazelcastInstance[] instances = new HazelcastInstance[clusterSize];
for (int i = 0; i < clusterSize; i++) {
instances[i] = createHazelcastInstance(createConfig());
}
NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
DAG dag = new DAG().vertex(new Vertex("test", processorSupplier).localParallelism(PARALLELISM));
Job job = instances[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
assertOpenEventually(NoOutputSourceP.executionStarted);
for (int i = 1; i < clusterSize; i++) {
instances[i].shutdown();
}
NoOutputSourceP.proceedLatch.countDown();
assertJobStatusEventually(job, NOT_RUNNING, 10);
HazelcastInstance instance6 = createHazelcastInstance(createConfig());
assertTrueAllTheTime(() -> assertStatusNotRunningOrStarting(job.getStatus()), 5);
// The test ends with a cluster size 2, which is below quorum
// Start another instance so the job can restart and be cleaned up correctly
HazelcastInstance instance7 = createHazelcastInstance(createConfig());
waitAllForSafeState(newArrayList(instances[0], instance6, instance7));
assertTrueEventually(() -> assertStatusRunningOrCompleted(job.getStatus()), 5);
}
Aggregations