Search in sources :

Example 1 with JetService

use of com.hazelcast.jet.JetService in project hazelcast by hazelcast.

the class HazelcastBootstrapTest method testHazelcast_bootstrappedInstance.

@Test
public void testHazelcast_bootstrappedInstance() {
    HazelcastInstance hz = Hazelcast.bootstrappedInstance();
    JetService jet = hz.getJet();
    executeWithBootstrappedInstance(jet);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) JetService(com.hazelcast.jet.JetService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with JetService

use of com.hazelcast.jet.JetService in project hazelcast by hazelcast.

the class JetTestSupport method shutdownJobsAndGetLeakedClassLoaders.

@Nonnull
private Map<Long, String> shutdownJobsAndGetLeakedClassLoaders() {
    Map<Long, String> leakedClassloaders = new HashMap<>();
    Collection<HazelcastInstance> instances = instanceFactory.getAllHazelcastInstances();
    for (HazelcastInstance instance : instances) {
        if (instance.getConfig().getJetConfig().isEnabled()) {
            // Some tests leave jobs running, which keeps job classloader, shut down all running/starting jobs
            JetService jet = instance.getJet();
            List<Job> jobs = jet.getJobs();
            for (Job job : jobs) {
                ditchJob(job, instances.toArray(new HazelcastInstance[instances.size()]));
            }
            JobClassLoaderService jobClassLoaderService = ((HazelcastInstanceImpl) instance).node.getNodeEngine().<JetServiceBackend>getService(SERVICE_NAME).getJobClassLoaderService();
            Map<Long, ?> classLoaders = jobClassLoaderService.getClassLoaders();
            // The classloader cleanup is done asynchronously in some cases, wait up to 10s
            for (int i = 0; i < 100 && !classLoaders.isEmpty(); i++) {
                sleepMillis(100);
            }
            for (Entry<Long, ?> entry : classLoaders.entrySet()) {
                leakedClassloaders.put(entry.getKey(), entry.toString());
            }
        }
    }
    return leakedClassloaders;
}
Also used : JetService(com.hazelcast.jet.JetService) HashMap(java.util.HashMap) Util.idToString(com.hazelcast.jet.Util.idToString) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JobClassLoaderService(com.hazelcast.jet.impl.JobClassLoaderService) Job(com.hazelcast.jet.Job) Nonnull(javax.annotation.Nonnull)

Example 3 with JetService

use of com.hazelcast.jet.JetService in project hazelcast by hazelcast.

the class ObservableRingbufferContainerLeakTest method testLeakingRingbufferContainerWhenUsingObservableIterator.

/**
 * Regression test for #19580
 */
@Test
@Repeat(100)
public void testLeakingRingbufferContainerWhenUsingObservableIterator() {
    Config config = smallInstanceConfig();
    config.setProperty("hazelcast.partition.count", "1");
    config.getJetConfig().setEnabled(true);
    HazelcastInstance hz = createHazelcastInstance(config);
    JetService jet = hz.getJet();
    Ringbuffer<Object> ringbuffer = hz.getRingbuffer("__jet.observables.my-observable");
    Observable<Object> obs = jet.getObservable("my-observable");
    ringbuffer.add(42);
    ringbuffer.addAsync(DoneItem.DONE_ITEM, OverflowPolicy.OVERWRITE);
    Iterator<Object> it = obs.iterator();
    it.hasNext();
    it.next();
    it.hasNext();
    obs.destroy();
    RingbufferService ringbufferService = Accessors.getService(hz, RingbufferService.SERVICE_NAME);
    Map<ObjectNamespace, RingbufferContainer> containers = ringbufferService.getContainers().values().iterator().next();
    assertThat(containers).hasSize(0);
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JetService(com.hazelcast.jet.JetService) Config(com.hazelcast.config.Config) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) Repeat(com.hazelcast.test.annotation.Repeat)

Example 4 with JetService

use of com.hazelcast.jet.JetService in project hazelcast by hazelcast.

the class JobTest method test_manyJobs.

private void test_manyJobs(HazelcastInstance inst) {
    JetService jet = inst.getJet();
    DAG streamingDag = new DAG();
    streamingDag.newVertex("v", () -> new MockP().streaming());
    DAG batchDag = new DAG();
    batchDag.newVertex("v", MockP::new);
    // normal streaming job
    Job streamingJob = jet.newJob(streamingDag);
    assertJobStatusEventually(streamingJob, RUNNING);
    // two normal batch job
    Job batchJob1 = jet.newJob(batchDag);
    batchJob1.join();
    Job batchJob2 = jet.newJob(batchDag);
    batchJob2.join();
    // named streaming job name1
    Job namedStreamingJob1 = jet.newJob(streamingDag, new JobConfig().setName("name1"));
    assertJobStatusEventually(namedStreamingJob1, RUNNING);
    // named streaming job name2, cancelled
    Job namedStreamingJob2 = jet.newJob(streamingDag, new JobConfig().setName("name2"));
    namedStreamingJob2.cancel();
    joinAndExpectCancellation(namedStreamingJob2);
    // named streaming job name2, again, not cancelled
    Job namedStreamingJob2_1 = jet.newJob(streamingDag, new JobConfig().setName("name2"));
    assertJobStatusEventually(namedStreamingJob2_1, RUNNING);
    // light streaming job
    Job lightStreamingJob = inst.getJet().newLightJob(streamingDag);
    // light streaming job, cancelled
    Job lightStreamingJobCancelled = jet.newLightJob(streamingDag);
    lightStreamingJobCancelled.cancel();
    joinAndExpectCancellation(lightStreamingJobCancelled);
    // two light batch jobs
    Job lightBatchJob1 = jet.newLightJob(batchDag);
    Job lightBatchJob2 = jet.newLightJob(batchDag);
    lightBatchJob1.join();
    lightBatchJob2.join();
    List<Job> allJobsExceptCompletedLightJobs = asList(streamingJob, batchJob1, batchJob2, namedStreamingJob1, namedStreamingJob2, namedStreamingJob2_1, lightStreamingJob);
    List<Job> allJobs = new ArrayList<>();
    allJobs.addAll(allJobsExceptCompletedLightJobs);
    allJobs.add(lightStreamingJobCancelled);
    allJobs.add(lightBatchJob1);
    allJobs.add(lightBatchJob2);
    // Then
    // getJobs must include all submitted all jobs, except for the light batch jobs that are done
    assertThat(toList(jet.getJobs(), this::jobEqualityString)).containsExactlyInAnyOrderElementsOf(toList(allJobsExceptCompletedLightJobs, this::jobEqualityString));
    for (Job job : allJobs) {
        Job trackedJobById = jet.getJob(job.getId());
        Job trackedJobByName = job.getName() != null ? jet.getJob(job.getName()) : null;
        if (allJobsExceptCompletedLightJobs.contains(job)) {
            assertEquals(jobEqualityString(job), jobEqualityString(trackedJobById));
            if (job.getName() != null && job != namedStreamingJob2) {
                assertEquals(jobEqualityString(job), jobEqualityString(trackedJobByName));
            }
        } else {
            assertNull(trackedJobById);
            assertNull(trackedJobByName);
        }
    }
    assertThat(toList(jet.getJobs("name1"), this::jobEqualityString)).containsExactlyElementsOf(toList(singletonList(namedStreamingJob1), this::jobEqualityString));
    assertThat(toList(jet.getJobs("name2"), this::jobEqualityString)).containsExactlyElementsOf(toList(asList(namedStreamingJob2_1, namedStreamingJob2), this::jobEqualityString));
}
Also used : JetService(com.hazelcast.jet.JetService) MockP(com.hazelcast.jet.core.TestProcessors.MockP) ArrayList(java.util.ArrayList) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 5 with JetService

use of com.hazelcast.jet.JetService in project hazelcast by hazelcast.

the class NonSmartClientTest method when_jobSubmitted_then_jobCanBeFetchedByIdOrName.

@Test
public void when_jobSubmitted_then_jobCanBeFetchedByIdOrName() {
    // Given
    String jobName = randomName();
    // When
    DAG dag = streamingDag();
    JetService jet = nonMasterClient.getJet();
    Job job = jet.newJob(dag, new JobConfig().setName(jobName));
    long jobId = job.getId();
    // Then
    assertTrueEventually(() -> {
        assertNotNull(jet.getJob(jobId));
        assertNotNull(jet.getJob(jobName));
        assertTrue(jet.getJobs().stream().anyMatch(j -> j.getId() == jobId));
        assertFalse(jet.getJobs(jobName).isEmpty());
        assertNotNull(jet.getJob(jobId).getStatus());
        assertEquals(jet.getJob(jobId).getStatus(), JobStatus.RUNNING);
        Job j = jet.getJob(jobName);
        assertNotNull(j.getConfig());
        assertGreaterOrEquals("submissionTime", j.getSubmissionTime(), 0);
    }, 10);
}
Also used : JobSummary(com.hazelcast.jet.impl.JobSummary) Address(com.hazelcast.cluster.Address) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) JetService(com.hazelcast.jet.JetService) ClientConfig(com.hazelcast.client.config.ClientConfig) Assert.fail(org.junit.Assert.fail) DAG(com.hazelcast.jet.core.DAG) JetClientInstanceImpl(com.hazelcast.jet.impl.JetClientInstanceImpl) JobStatus(com.hazelcast.jet.core.JobStatus) Job(com.hazelcast.jet.Job) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) CancellationException(java.util.concurrent.CancellationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) TestProcessors.streamingDag(com.hazelcast.jet.core.TestProcessors.streamingDag) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) JetService(com.hazelcast.jet.JetService) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

JetService (com.hazelcast.jet.JetService)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Job (com.hazelcast.jet.Job)3 Test (org.junit.Test)3 JobConfig (com.hazelcast.jet.config.JobConfig)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 Address (com.hazelcast.cluster.Address)1 Config (com.hazelcast.config.Config)1 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)1 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)1 Util.idToString (com.hazelcast.jet.Util.idToString)1 DAG (com.hazelcast.jet.core.DAG)1 JobStatus (com.hazelcast.jet.core.JobStatus)1 MockP (com.hazelcast.jet.core.TestProcessors.MockP)1 TestProcessors.streamingDag (com.hazelcast.jet.core.TestProcessors.streamingDag)1 JetClientInstanceImpl (com.hazelcast.jet.impl.JetClientInstanceImpl)1 JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)1 JobClassLoaderService (com.hazelcast.jet.impl.JobClassLoaderService)1