use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class ManualRestartTest method testJobRestartWhenJobIsRunning.
private void testJobRestartWhenJobIsRunning(boolean autoRestartOnMemberFailureEnabled) {
// Given that the job is running
JetInstance client = createJetClient();
Job job = client.newJob(dag, new JobConfig().setAutoRestartOnMemberFailure(autoRestartOnMemberFailureEnabled));
assertTrueEventually(() -> {
assertEquals(NODE_COUNT, MockPS.initCount.get());
});
// When the job is restarted after new members join to the cluster
int newMemberCount = 2;
for (int i = 0; i < newMemberCount; i++) {
createJetMember();
}
job.restart();
// Then, the job restarts
int initCount = NODE_COUNT * 2 + newMemberCount;
assertTrueEventually(() -> {
assertEquals(initCount, MockPS.initCount.get());
});
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class OperationTimeoutTest method when_slowRunningOperationOnSingleNode_then_doesNotTimeout.
@Test
public void when_slowRunningOperationOnSingleNode_then_doesNotTimeout() throws Throwable {
// Given
JetInstance instance = createJetMember(config);
DAG dag = new DAG();
dag.newVertex("slow", SlowProcessor::new);
// When
executeAndPeel(instance.newJob(dag));
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class HazelcastConnectorTest method setup.
@Before
public void setup() {
JetConfig jetConfig = new JetConfig();
Config hazelcastConfig = jetConfig.getHazelcastConfig();
hazelcastConfig.addCacheConfig(new CacheSimpleConfig().setName("*"));
hazelcastConfig.addEventJournalConfig(new EventJournalConfig().setCacheName("stream*").setMapName("stream*"));
jetInstance = createJetMember(jetConfig);
JetInstance jetInstance2 = createJetMember(jetConfig);
sourceName = randomString();
sinkName = randomString();
streamSourceName = "stream" + sourceName;
streamSinkName = "stream" + sinkName;
// workaround for `cache is not created` exception, create cache locally on all nodes
JetCacheManager cacheManager = jetInstance2.getCacheManager();
cacheManager.getCache(sourceName);
cacheManager.getCache(sinkName);
cacheManager.getCache(streamSourceName);
cacheManager.getCache(streamSinkName);
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class SplitBrainTest method when_quorumIsLostOnMinority_then_jobRestartsUntilMerge.
@Test
public void when_quorumIsLostOnMinority_then_jobRestartsUntilMerge() {
int firstSubClusterSize = 3;
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, new JobConfig().setSplitBrainProtection(true));
assertOpenEventually(StuckProcessor.executionStarted);
};
Future[] minorityJobFutureRef = new Future[1];
BiConsumer<JetInstance[], JetInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
StuckProcessor.proceedLatch.countDown();
assertTrueEventually(() -> assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get()));
long jobId = jobRef[0].getId();
assertTrueEventually(() -> {
JetService service = getJetService(firstSubCluster[0]);
assertEquals(COMPLETED, service.getJobCoordinationService().getJobStatus(jobId));
});
JetService service2 = getJetService(secondSubCluster[0]);
assertTrueEventually(() -> {
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
});
MasterContext masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
assertNotNull(masterContext);
minorityJobFutureRef[0] = masterContext.completionFuture();
assertTrueAllTheTime(() -> {
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
}, 20);
};
Consumer<JetInstance[]> afterMerge = instances -> {
assertTrueEventually(() -> {
assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get());
assertEquals(clusterSize + firstSubClusterSize, MockPS.closeCount.get());
});
assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
MockPS.receivedCloseErrors.forEach(t -> assertTrue(t instanceof TopologyChangedException));
try {
minorityJobFutureRef[0].get();
fail();
} catch (CancellationException ignored) {
} catch (Exception e) {
throw new AssertionError(e);
}
};
testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class SplitBrainTest method when_quorumIsLostOnBothSides_then_jobRestartsUntilMerge.
@Test
public void when_quorumIsLostOnBothSides_then_jobRestartsUntilMerge() {
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, new JobConfig().setSplitBrainProtection(true));
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(RESTARTING, service1.getJobCoordinationService().getJobStatus(jobId));
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
});
assertTrueAllTheTime(() -> {
JetService service1 = getJetService(firstSubCluster[0]);
JetService service2 = getJetService(secondSubCluster[0]);
assertEquals(RESTARTING, service1.getJobCoordinationService().getJobStatus(jobId));
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
}, 20);
};
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);
}
Aggregations