Search in sources :

Example 41 with TStream

use of com.ibm.streamsx.topology.TStream in project streamsx.topology by IBMStreams.

the class StreamTest method testUnionNops.

@Test
public void testUnionNops() throws Exception {
    assumeTrue(isMainRun());
    final Topology f = newTopology("Union");
    TStream<String> s1 = f.strings("A1", "B1", "C1", "D1");
    Set<TStream<String>> empty = Collections.emptySet();
    assertSame(s1, s1.union(s1));
    assertSame(s1, s1.union(empty));
    assertSame(s1, s1.union(Collections.singleton(s1)));
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 42 with TStream

use of com.ibm.streamsx.topology.TStream in project streamsx.topology by IBMStreams.

the class StreamTest method testSplit.

@Test
public void testSplit() throws Exception {
    final Topology topology = newTopology("testSplit");
    TStream<String> s1 = topology.strings("ch0", "ch1", "ch2", "omit", "another-ch2", "another-ch1", "another-ch0", "another-omit");
    List<TStream<String>> splits = s1.split(3, myStringSplitter());
    assertEquals("list size", 3, splits.size());
    Tester tester = topology.getTester();
    List<Condition<List<String>>> contents = new ArrayList<>();
    for (int i = 0; i < splits.size(); i++) {
        TStream<String> ch = splits.get(i);
        Condition<List<String>> chContents = tester.stringContents(ch, "ch" + i, "another-ch" + i);
        contents.add(chContents);
    }
    TStream<String> all = splits.get(0).union(new HashSet<>(splits.subList(1, splits.size())));
    Condition<Long> uCount = tester.tupleCount(all, 6);
    complete(tester, uCount, 10, TimeUnit.SECONDS);
    for (int i = 0; i < splits.size(); i++) {
        assertTrue("chContents[" + i + "]:" + contents.get(i), contents.get(i).valid());
    }
}
Also used : Condition(com.ibm.streamsx.topology.tester.Condition) Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) TStream(com.ibm.streamsx.topology.TStream) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 43 with TStream

use of com.ibm.streamsx.topology.TStream in project streamsx.topology by IBMStreams.

the class StreamTest method testUnionSet.

@Test
public void testUnionSet() throws Exception {
    final Topology topology = newTopology();
    TStream<String> s1 = topology.strings("A1", "B1", "C1");
    TStream<String> s2 = topology.strings("A2", "B2", "C2", "D2");
    TStream<String> s3 = topology.strings("A3", "B3", "C3");
    Set<TStream<String>> streams = new HashSet<TStream<String>>();
    streams.add(s2);
    streams.add(s3);
    TStream<String> su = s1.union(streams);
    // TODO - testing doesn't work against union streams in embedded.
    su = su.filter(new AllowAll<String>());
    Tester tester = topology.getTester();
    Condition<Long> suCount = tester.tupleCount(su, 10);
    Condition<List<String>> suContents = tester.stringContentsUnordered(su, "A1", "B1", "C1", "A2", "B2", "C2", "D2", "A3", "B3", "C3");
    assertTrue(complete(tester, suCount, 10, TimeUnit.SECONDS));
    // assertTrue("SU:" + suContents, suContents.valid());
    assertTrue("SU:" + suCount, suCount.valid());
    assertTrue("SUContents:" + suContents, suContents.valid());
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Tester(com.ibm.streamsx.topology.tester.Tester) AllowAll(com.ibm.streamsx.topology.test.AllowAll) ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with TStream

use of com.ibm.streamsx.topology.TStream in project streamsx.topology by IBMStreams.

the class FileStreamsTest method runDirectoryWatcher.

private void runDirectoryWatcher(final Topology t, int numberOfFiles, int repeat) throws Exception {
    // final Path dir = Files.createTempDirectory("testdw");
    final String[] files = new String[numberOfFiles];
    for (int i = 0; i < files.length; i++) {
        files[i] = PREFIX + (numberOfFiles - i);
    }
    String dir;
    dir = ".";
    this.getConfig().put(JobProperties.DATA_DIRECTORY, dir);
    TStream<String> rawFileNames = FileStreams.directoryWatcher(t, dir);
    TStream<String> fileNames = rawFileNames.modify(fn -> new File(fn).getName());
    fileNames = fileNames.filter(fn -> fn.startsWith(PREFIX));
    // fileNames.print();
    // Create the files from within the topology to ensure it works
    // in distributed and standalone.
    // 
    // Due to vagaries / delays that can occur in operator startup
    // in different processes (distributed mode), delay the initial
    // file creation process to give the watcher a chance to startup.
    // 
    // e.g., with numberOfFiles=20 & repeat=1, each group of files
    // only lasts 20*(10ms*2) => 200ms.  That can easily happen before
    // the watcher is started and has done its first dir.listFiles(),
    // with the result being not seeing/processing the expected number
    // of files.
    TSink creator = addStartupDelay(BeaconStreams.single(t)).forEach(createFiles(dir, files, repeat));
    creator.colocate(rawFileNames);
    Tester tester = t.getTester();
    Condition<Long> expectedCount = tester.tupleCount(fileNames, numberOfFiles * repeat);
    String[] expectedFileNames = files;
    if (repeat != 1) {
        expectedFileNames = new String[files.length * repeat];
        for (int r = 0; r < repeat; r++) System.arraycopy(files, 0, expectedFileNames, r * files.length, files.length);
    }
    Condition<List<String>> expectedNames = tester.stringContentsUnordered(fileNames.filter(x -> true), expectedFileNames);
    complete(tester, expectedCount, 60, TimeUnit.SECONDS);
    if (!".".equals(dir)) {
    // Files.d
    }
}
Also used : TSink(com.ibm.streamsx.topology.TSink) TStream(com.ibm.streamsx.topology.TStream) PERuntime(com.ibm.streams.operator.PERuntime) Tester(com.ibm.streamsx.topology.tester.Tester) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) BeaconStreams(com.ibm.streamsx.topology.streams.BeaconStreams) Assert.assertTrue(org.junit.Assert.assertTrue) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FileStreams(com.ibm.streamsx.topology.file.FileStreams) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) Consumer(com.ibm.streamsx.topology.function.Consumer) Condition(com.ibm.streamsx.topology.tester.Condition) Type(com.ibm.streamsx.topology.context.StreamsContext.Type) OutputStreamWriter(java.io.OutputStreamWriter) JobProperties(com.ibm.streamsx.topology.context.JobProperties) Assume.assumeTrue(org.junit.Assume.assumeTrue) Path(java.nio.file.Path) TestTopology(com.ibm.streamsx.topology.test.TestTopology) TSink(com.ibm.streamsx.topology.TSink) Tester(com.ibm.streamsx.topology.tester.Tester) List(java.util.List) File(java.io.File)

Example 45 with TStream

use of com.ibm.streamsx.topology.TStream in project streamsx.topology by IBMStreams.

the class FunctionalSubmissionParamsTest method testPeriodicSourceWithSubmissionParams.

@Test
public void testPeriodicSourceWithSubmissionParams() throws Exception {
    Topology topology = newTopology();
    Supplier<Integer> someInt = topology.createSubmissionParameter("someInt", Integer.class);
    Supplier<Integer> someIntD = topology.createSubmissionParameter("someIntD", 20);
    // The test's functional logic asserts it receives the expected SP value.
    // HEADS UP.  issue#213 - exceptions in the supplier get silently eaten
    // and the stream just ends up with 0 tuples.
    TStream<Integer> s = topology.periodicSource(sourceSupplier(someInt, 10), 100, TimeUnit.MILLISECONDS);
    TStream<Integer> sD = topology.periodicSource(sourceSupplier(someIntD, 20), 100, TimeUnit.MILLISECONDS);
    TStream<Integer> ms = topology.periodicMultiSource(sourceIterableSupplier(someInt, 10), 100, TimeUnit.MILLISECONDS);
    TStream<Integer> msD = topology.periodicMultiSource(sourceIterableSupplier(someIntD, 20), 100, TimeUnit.MILLISECONDS);
    Map<String, Object> params = new HashMap<>();
    params.put("someInt", 10);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    // //////////////////
    Set<TStream<Integer>> all = new HashSet<>(Arrays.asList(s, sD, ms, msD));
    TStream<Integer> union = s.union(all);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount1 = tester.tupleCount(s, 5);
    Condition<Long> expectedCount2 = tester.tupleCount(sD, 5);
    Condition<Long> expectedCount3 = tester.tupleCount(ms, 5);
    Condition<Long> expectedCount4 = tester.tupleCount(msD, 5);
    Condition<Long> expectedCount = tester.tupleCount(union, 20);
    complete(tester, expectedCount, 15, TimeUnit.SECONDS);
    assertTrue(expectedCount1.toString(), expectedCount1.valid());
    assertTrue(expectedCount2.toString(), expectedCount2.valid());
    assertTrue(expectedCount3.toString(), expectedCount3.valid());
    assertTrue(expectedCount4.toString(), expectedCount4.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) TStream(com.ibm.streamsx.topology.TStream) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TStream (com.ibm.streamsx.topology.TStream)52 Topology (com.ibm.streamsx.topology.Topology)44 Test (org.junit.Test)44 Tester (com.ibm.streamsx.topology.tester.Tester)41 List (java.util.List)36 TestTopology (com.ibm.streamsx.topology.test.TestTopology)30 Condition (com.ibm.streamsx.topology.tester.Condition)28 TimeUnit (java.util.concurrent.TimeUnit)27 HashSet (java.util.HashSet)25 HashMap (java.util.HashMap)23 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)19 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)17 ArrayList (java.util.ArrayList)17 SPLStreams (com.ibm.streamsx.topology.spl.SPLStreams)16 Map (java.util.Map)16 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)15 SPL (com.ibm.streamsx.topology.spl.SPL)15 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 Assume.assumeTrue (org.junit.Assume.assumeTrue)14