Search in sources :

Example 46 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class WriteFilePTest method when_slowSource_then_fileFlushedAfterEachItem.

@Test
public void when_slowSource_then_fileFlushedAfterEachItem() {
    // Given
    int numItems = 10;
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", () -> new SlowSourceP(semaphore, numItems)).localParallelism(1);
    Vertex sink = dag.newVertex("sink", writeFileP(directory.toString(), StandardCharsets.UTF_8, null, DISABLE_ROLLING, true, Object::toString)).localParallelism(1);
    dag.edge(between(source, sink));
    Job job = instance().getJet().newJob(dag);
    for (int i = 0; i < numItems; i++) {
        // When
        semaphore.release();
        int finalI = i;
        // Then
        assertTrueEventually(() -> checkFileContents(0, finalI + 1, false, false, true), 5);
    }
    // wait for the job to finish
    job.join();
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class AbstractDeploymentTest method testDeployment_whenZipAddedAsResource_thenClassesFromAllJarsAvailableOnClassLoader.

@Test
public void testDeployment_whenZipAddedAsResource_thenClassesFromAllJarsAvailableOnClassLoader() throws Throwable {
    DAG dag = new DAG();
    List<String> onClasspath = new ArrayList<>();
    onClasspath.add("com.sample.pojo.person.Person$Appereance");
    onClasspath.add("com.sample.pojo.car.Car");
    List<String> notOnClasspath = new ArrayList<>();
    notOnClasspath.add("com.sample.pojo.address.Address");
    dag.newVertex("load class", () -> new LoadClassesIsolated(onClasspath, notOnClasspath, true));
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJarsInZip(this.getClass().getResource("/zip-resources/person-car-jar.zip"));
    executeAndPeel(getJet().newJob(dag, jobConfig));
}
Also used : ArrayList(java.util.ArrayList) DAG(com.hazelcast.jet.core.DAG) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class AbstractDeploymentTest method testDeployment_whenJarAddedAsResource_thenClassesAvailableOnClassLoader.

@Test
public void testDeployment_whenJarAddedAsResource_thenClassesAvailableOnClassLoader() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("load class", () -> new LoadClassesIsolated(true));
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJar(this.getClass().getResource("/deployment/sample-pojo-1.0-person.jar"));
    executeAndPeel(getJet().newJob(dag, jobConfig));
}
Also used : DAG(com.hazelcast.jet.core.DAG) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class AbstractDeploymentTest method testDeployment_whenAddClass_thenNestedClassesAreAddedAsWell.

@Test
public void testDeployment_whenAddClass_thenNestedClassesAreAddedAsWell() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("executes lambda from a nested class", NestedClassIsLoaded::new);
    JobConfig jobConfig = new JobConfig();
    URL classUrl = new File(CLASS_DIRECTORY).toURI().toURL();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { classUrl }, null);
    Class<?> worker = urlClassLoader.loadClass("com.sample.lambda.Worker");
    jobConfig.addClass(worker);
    executeAndPeel(getJet().newJob(dag, jobConfig));
}
Also used : URLClassLoader(java.net.URLClassLoader) DAG(com.hazelcast.jet.core.DAG) File(java.io.File) JobConfig(com.hazelcast.jet.config.JobConfig) URL(java.net.URL) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with DAG

use of com.hazelcast.jet.core.DAG in project hazelcast by hazelcast.

the class JobMetrics_MiscTest method when_jobSuspended_andMetricsNotStored_then_onlyPeriodicMetricsReturned.

@Test
public void when_jobSuspended_andMetricsNotStored_then_onlyPeriodicMetricsReturned() throws Throwable {
    DAG dag = new DAG();
    Vertex v1 = dag.newVertex("v1", TestProcessors.MockP::new);
    Vertex v2 = dag.newVertex("v2", (SupplierEx<Processor>) TestProcessors.NoOutputSourceP::new);
    dag.edge(between(v1, v2));
    // 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
    TestProcessors.NoOutputSourceP.executionStarted.await();
    // then
    assertJobStatusEventually(job, JobStatus.RUNNING);
    assertTrueEventually(() -> assertJobHasMetrics(job, false));
    // when
    job.suspend();
    // then
    assertJobStatusEventually(job, SUSPENDED);
    assertTrueEventually(() -> assertEmptyJobMetrics(job, false));
    // when
    job.resume();
    // then
    assertJobStatusEventually(job, RUNNING);
    assertTrueEventually(() -> assertJobHasMetrics(job, false));
    // when
    TestProcessors.NoOutputSourceP.proceedLatch.countDown();
    job.join();
    // then
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    assertEmptyJobMetrics(job, false);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) TestProcessors(com.hazelcast.jet.core.TestProcessors) Processor(com.hazelcast.jet.core.Processor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) 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

DAG (com.hazelcast.jet.core.DAG)211 Test (org.junit.Test)159 Vertex (com.hazelcast.jet.core.Vertex)127 QuickTest (com.hazelcast.test.annotation.QuickTest)100 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)91 Job (com.hazelcast.jet.Job)64 Entry (java.util.Map.Entry)51 List (java.util.List)38 Assert.assertEquals (org.junit.Assert.assertEquals)37 Map (java.util.Map)36 JobConfig (com.hazelcast.jet.config.JobConfig)35 Assert.assertTrue (org.junit.Assert.assertTrue)31 Edge (com.hazelcast.jet.core.Edge)29 IntStream (java.util.stream.IntStream)29 Category (org.junit.experimental.categories.Category)28 Collectors.toList (java.util.stream.Collectors.toList)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 FunctionEx (com.hazelcast.function.FunctionEx)23 ArrayList (java.util.ArrayList)22 Nonnull (javax.annotation.Nonnull)21