use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet 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(StuckProcessor::new, nodeCount)));
// When
Job job = instances[0].newJob(dag);
StuckProcessor.executionStarted.await();
JetInstance instance = createJetMember();
instance.shutdown();
StuckProcessor.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.StuckProcessor in project hazelcast-jet by hazelcast.
the class TopologyChangeTest method when_coordinatorLeavesDuringExecution_then_jobCompletes.
@Test
public void when_coordinatorLeavesDuringExecution_then_jobCompletes() throws Throwable {
// Given
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
// When
Long jobId = null;
try {
Job job = instances[0].newJob(dag);
Future<Void> future = job.getFuture();
jobId = job.getId();
StuckProcessor.executionStarted.await();
instances[0].getHazelcastInstance().getLifecycleService().terminate();
StuckProcessor.proceedLatch.countDown();
future.get();
fail();
} catch (ExecutionException expected) {
assertTrue(expected.getCause() instanceof HazelcastInstanceNotActiveException);
}
// Then
assertNotNull(jobId);
final long completedJobId = jobId;
JobRepository jobRepository = getJetService(instances[1]).getJobRepository();
assertTrueEventually(() -> {
JobResult jobResult = jobRepository.getJobResult(completedJobId);
assertNotNull(jobResult);
assertTrue(jobResult.isSuccessful());
});
final int count = liteMemberFlags[0] ? (2 * nodeCount) : (2 * nodeCount - 1);
assertEquals(count, MockPS.initCount.get());
assertTrueEventually(() -> {
assertEquals(count, MockPS.closeCount.get());
assertEquals(nodeCount, MockPS.receivedCloseErrors.size());
for (int i = 0; i < MockPS.receivedCloseErrors.size(); i++) {
Throwable error = MockPS.receivedCloseErrors.get(i);
assertTrue(error instanceof TopologyChangedException || error instanceof HazelcastInstanceNotActiveException);
}
});
}
use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.
the class TopologyChangeTest method when_coordinatorLeavesDuringExecution_then_clientStillGetsJobResult.
@Test
public void when_coordinatorLeavesDuringExecution_then_clientStillGetsJobResult() throws Throwable {
// Given
JetInstance client = createJetClient();
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, nodeCount)));
// When
Job job = client.newJob(dag);
StuckProcessor.executionStarted.await();
instances[0].getHazelcastInstance().getLifecycleService().terminate();
StuckProcessor.proceedLatch.countDown();
// Then
job.join();
}
use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.
the class TopologyChangeTest method when_nonCoordinatorLeavesDuringExecution_then_jobRestarts.
@Test
public void when_nonCoordinatorLeavesDuringExecution_then_jobRestarts() 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();
instances[2].getHazelcastInstance().getLifecycleService().terminate();
StuckProcessor.proceedLatch.countDown();
job.join();
// upon non-coordinator member leave, remaining members restart and complete the job
final int count = nodeCount * 2 - 1;
assertEquals(count, MockPS.initCount.get());
assertTrueEventually(() -> {
assertEquals(count, MockPS.closeCount.get());
assertEquals(nodeCount, MockPS.receivedCloseErrors.size());
for (int i = 0; i < MockPS.receivedCloseErrors.size(); i++) {
Throwable error = MockPS.receivedCloseErrors.get(i);
assertTrue(error instanceof TopologyChangedException || error instanceof HazelcastInstanceNotActiveException);
}
});
}
use of com.hazelcast.jet.core.TestProcessors.StuckProcessor in project hazelcast-jet by hazelcast.
the class ExecutionLifecycleTest method when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute.
@Test
public void when_executionCancelledBeforeStart_then_jobFutureIsCancelledOnExecute() {
// Given
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance.getHazelcastInstance());
Address localAddress = nodeEngineImpl.getThisAddress();
ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngineImpl.getClusterService();
MembersView membersView = clusterService.getMembershipManager().getMembersView();
int memberListVersion = membersView.getVersion();
JetService jetService = getJetService(instance);
final Map<MemberInfo, ExecutionPlan> executionPlans = ExecutionPlanBuilder.createExecutionPlans(nodeEngineImpl, membersView, dag, new JobConfig(), NO_SNAPSHOT);
ExecutionPlan executionPlan = executionPlans.get(membersView.getMember(localAddress));
long jobId = 0;
long executionId = 1;
Set<MemberInfo> participants = new HashSet<>(membersView.getMembers());
jetService.getJobExecutionService().initExecution(jobId, executionId, localAddress, memberListVersion, participants, executionPlan);
ExecutionContext executionContext = jetService.getJobExecutionService().getExecutionContext(executionId);
executionContext.cancelExecution();
// When
CompletableFuture<Void> future = executionContext.beginExecution();
// Then
expectedException.expect(CancellationException.class);
future.join();
}
Aggregations