use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.
the class JobTimeoutTest method when_jobIsCompletedBeforeTimeout_jobIsNotCancelled.
@Test
public void when_jobIsCompletedBeforeTimeout_jobIsNotCancelled() {
final HazelcastInstance hz = createHazelcastInstance();
final DAG dag = new DAG();
dag.newVertex("normal", MockP::new);
final JobConfig jobConfig = new JobConfig().setTimeoutMillis(1000L);
final Job job = hz.getJet().newJob(dag, jobConfig);
job.join();
assertEquals(JobStatus.COMPLETED, job.getStatus());
}
use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.
the class JobMetrics_MiscTest method when_jobMetricsDisabled_then_emptyMetrics.
@Test
public void when_jobMetricsDisabled_then_emptyMetrics() throws Throwable {
DAG dag = new DAG();
dag.newVertex("v1", MockP::new);
dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
// init
JobConfig config = new JobConfig().setMetricsEnabled(// enable metric collection
true).setStoreMetricsAfterJobCompletion(// disable metric saving on completion
false);
Job job = hz().getJet().newJob(dag, config);
// when
NoOutputSourceP.executionStarted.await();
assertJobStatusEventually(job, JobStatus.RUNNING);
// then
assertTrueEventually(() -> assertJobHasMetrics(job, false));
// when
NoOutputSourceP.proceedLatch.countDown();
job.join();
// then
assertJobStatusEventually(job, JobStatus.COMPLETED);
assertEmptyJobMetrics(job, false);
}
use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.
the class JobMetrics_MiscTest method when_jobRunning_then_nonEmptyMetrics.
@Test
public void when_jobRunning_then_nonEmptyMetrics() throws Throwable {
DAG dag = new DAG();
dag.newVertex("v1", MockP::new);
dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
Job job = hz().getJet().newJob(dag, JOB_CONFIG_WITH_METRICS);
// when
NoOutputSourceP.executionStarted.await();
assertJobStatusEventually(job, JobStatus.RUNNING);
// then
assertTrueEventually(() -> assertJobHasMetrics(job, false));
// when
NoOutputSourceP.proceedLatch.countDown();
job.join();
// then
assertJobStatusEventually(job, JobStatus.COMPLETED);
assertJobHasMetrics(job, true);
assertTrue(hz().getMap(JobRepository.JOB_METRICS_MAP_NAME).containsKey(job.getId()));
}
use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.
the class MemberReconnectionStressTest method test.
@Test
public void test() {
/*
The test will start 2 thread:
- one will submit short batch jobs, serially, after joining the previous job
- the other will keep dropping the member-to-member connection.
The small jobs will often fail due to the reconnection, we check
that the job completes in a limited time. We drop the connection
at a rate lower than the normal job duration so there's
typically at most 1 restart per job. We assert that the jobs
eventually successfully complete.
*/
Config config = defaultInstanceConfigWithJetEnabled();
// The connection drop often causes regular IMap operations to fail - shorten the timeout so that
// it recovers more quickly
config.setProperty(ClusterProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "2000");
config.setClusterName(randomName());
HazelcastInstance inst1 = createHazelcastInstance(config);
HazelcastInstance inst2 = createHazelcastInstance(config);
logger.info("Instances started");
new Thread(() -> {
while (!terminated.get()) {
Connection connection = null;
while (connection == null) {
connection = ImdgUtil.getMemberConnection(getNodeEngineImpl(inst1), getNodeEngineImpl(inst2).getThisAddress());
}
connection.close("test", new Exception("test failure"));
logger.info("connection closed");
sleepMillis(300);
}
}).start();
DAG dag = new DAG();
Vertex v1 = dag.newVertex("v1", () -> new MockP()).localParallelism(2);
Vertex v2 = dag.newVertex("v2", () -> new MockP()).localParallelism(2);
dag.edge(between(v1, v2).distributed());
AtomicInteger jobCount = new AtomicInteger();
new Thread(() -> {
while (!terminated.get()) {
try {
inst1.getJet().newJob(dag).getFuture().join();
logger.info("job completed");
jobCount.incrementAndGet();
} catch (Exception e) {
logger.info("Job failed, ignoring it", e);
}
}
}).start();
// in a loop check that the `jobCount` is incremented at least every N seconds
long lastIncrement = System.nanoTime();
long lastJobCount = 0;
long testEndTime = System.nanoTime() + MINUTES.toNanos(3);
for (long now; (now = System.nanoTime()) < testEndTime; ) {
if (jobCount.get() > lastJobCount) {
lastIncrement = now;
lastJobCount++;
}
if (NANOSECONDS.toSeconds(now - lastIncrement) > 30) {
fail("jobCount didn't increment for 30 seconds");
}
sleepMillis(100);
}
}
use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.
the class OperationLossTest method lightJob_when_terminateExecutionOperationLost_then_jobTerminates.
@Test
public void lightJob_when_terminateExecutionOperationLost_then_jobTerminates() {
DAG dag = new DAG();
dag.newVertex("v", () -> new MockP().streaming());
Job job = instance().getJet().newLightJob(dag);
// When
PacketFiltersUtil.dropOperationsFrom(instance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(JetInitDataSerializerHook.TERMINATE_EXECUTION_OP));
job.cancel();
// Then
assertThatThrownBy(job::join).isInstanceOf(CancellationException.class);
}
Aggregations