Search in sources :

Example 16 with DAG

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

the class HazelcastRemoteConnectorTest method when_writeRemoteCache.

@Test
public void when_writeRemoteCache() {
    populateCache(jet.getCacheManager().getCache(SOURCE_NAME));
    DAG dag = new DAG();
    Vertex producer = dag.newVertex(SOURCE_NAME, readCacheP(SOURCE_NAME));
    Vertex consumer = dag.newVertex(SINK_NAME, writeRemoteCacheP(SINK_NAME, clientConfig));
    dag.edge(between(producer, consumer));
    executeAndWait(dag);
    assertEquals(ITEM_COUNT, hz.getCacheManager().getCache(SINK_NAME).size());
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) Test(org.junit.Test)

Example 17 with DAG

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

the class ReadFilesPTest method when_directory_then_ignore.

@Test
public void when_directory_then_ignore() {
    DAG dag = buildDag(null);
    File file1 = new File(directory, randomName());
    assertTrue(file1.mkdir());
    instance.newJob(dag).join();
    assertEquals(0, list.size());
    finishDirectory(file1);
}
Also used : DAG(com.hazelcast.jet.core.DAG) File(java.io.File) Test(org.junit.Test)

Example 18 with DAG

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

the class ReadFilesPTest method when_glob_the_useGlob.

@Test
public void when_glob_the_useGlob() throws Exception {
    DAG dag = buildDag("file2.*");
    File file1 = new File(directory, "file1.txt");
    appendToFile(file1, "hello", "world");
    File file2 = new File(directory, "file2.txt");
    appendToFile(file2, "hello2", "world2");
    instance.newJob(dag).join();
    assertEquals(Arrays.asList(entry("file2.txt", "hello2"), entry("file2.txt", "world2")), new ArrayList<>(list));
    finishDirectory(file1, file2);
}
Also used : DAG(com.hazelcast.jet.core.DAG) File(java.io.File) Test(org.junit.Test)

Example 19 with DAG

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

the class ReadFilesPTest method buildDag.

private DAG buildDag(String glob) {
    if (glob == null) {
        glob = "*";
    }
    DAG dag = new DAG();
    Vertex reader = dag.newVertex("reader", readFilesP(directory.getPath(), StandardCharsets.UTF_8, glob, Util::entry)).localParallelism(1);
    Vertex writer = dag.newVertex("writer", writeListP(list.getName())).localParallelism(1);
    dag.edge(between(reader, writer));
    return dag;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Util(com.hazelcast.jet.Util) DAG(com.hazelcast.jet.core.DAG)

Example 20 with DAG

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

the class StreamFilesP_integrationTest method when_withCrlf_then_pickupCompleteLines.

@Test
public void when_withCrlf_then_pickupCompleteLines() throws Exception {
    DAG dag = buildDag();
    // this is a pre-existing file, should not be picked up
    File file = createNewFile();
    try (PrintWriter writer = new PrintWriter(new FileOutputStream(file, true))) {
        // note: no newline appended
        writer.write("hello world\r");
    }
    sleepAtLeastMillis(50);
    Future<Void> jobFuture = instance.newJob(dag).getFuture();
    // wait for the processor to initialize
    sleepAtLeastSeconds(2);
    // pre-existing file should not be picked up
    assertEquals(0, list.size());
    // this completes the first line and a second one - only the second one should be picked
    try (PrintWriter writer = new PrintWriter(new FileOutputStream(file, true))) {
        // note: no newline appended
        writer.write("\nsecond line\r\n");
    }
    // now, all three lines are picked up
    assertTrueEventually(() -> assertEquals(1, list.size()));
    assertEquals(entry(file.getName(), "second line"), list.get(0));
    finishDirectory(jobFuture, file);
}
Also used : FileOutputStream(java.io.FileOutputStream) DAG(com.hazelcast.jet.core.DAG) File(java.io.File) PrintWriter(java.io.PrintWriter) 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