Search in sources :

Example 16 with TStream

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

the class KafkaSPLStreamsUtils method union.

public static SPLStream union(List<SPLStream> streams, StreamSchema schema) {
    if (streams.size() == 0)
        throw new IllegalArgumentException("At least one stream must be provided.");
    if (streams.size() == 1) {
        return streams.get(0);
    } else {
        SPLStream stream1 = streams.get(0);
        Set<TStream<Tuple>> streamSet = new HashSet<TStream<Tuple>>(streams);
        streamSet.remove(stream1);
        return SPLStreams.convertStream(stream1.union(streamSet), getTupleStreamConvert(), schema);
    }
}
Also used : TStream(com.ibm.streamsx.topology.TStream) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Tuple(com.ibm.streams.operator.Tuple) OutputTuple(com.ibm.streams.operator.OutputTuple) HashSet(java.util.HashSet)

Example 17 with TStream

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

the class FunctionalSubmissionParamsTest method PeriodicSourceTest.

@Test
public void PeriodicSourceTest() throws Exception {
    Topology topology = newTopology("PeriodicSourceTest");
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    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)

Example 18 with TStream

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

the class FunctionalSubmissionParamsTest method AllTypesTest.

@Test
public void AllTypesTest() throws Exception {
    Topology topology = newTopology("AllTypesTest");
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    // verify functional with all SP types
    Supplier<String> strSp = topology.createSubmissionParameter("strSp", String.class);
    Supplier<String> strSpD = topology.createSubmissionParameter("strSpD", "dude");
    Supplier<Byte> byteSp = topology.createSubmissionParameter("byteSp", Byte.class);
    Supplier<Byte> byteSpD = topology.createSubmissionParameter("byteSpD", (byte) 2);
    Supplier<Short> shortSp = topology.createSubmissionParameter("shortSp", Short.class);
    Supplier<Short> shortSpD = topology.createSubmissionParameter("shortSpD", (short) 4);
    Supplier<Integer> intSp = topology.createSubmissionParameter("intSp", Integer.class);
    Supplier<Integer> intSpD = topology.createSubmissionParameter("intSpD", 6);
    Supplier<Long> longSp = topology.createSubmissionParameter("longSp", Long.class);
    Supplier<Long> longSpD = topology.createSubmissionParameter("longSpD", (long) 8);
    Supplier<Float> floatSp = topology.createSubmissionParameter("floatSp", Float.class);
    Supplier<Float> floatSpD = topology.createSubmissionParameter("floatSpD", 10.0f);
    Supplier<Double> doubleSp = topology.createSubmissionParameter("doubleSp", Double.class);
    Supplier<Double> doubleSpD = topology.createSubmissionParameter("doubleSpD", 12.0d);
    List<Integer> data = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5 });
    int expectedCnt = 5;
    TStream<Integer> s = topology.constants(data);
    // The test's functional logic asserts it receives the expected SP value.
    TStream<Integer> strSpFiltered = s.filter(predicateFn(strSp, "yo"));
    TStream<Integer> strSpDFiltered = s.filter(predicateFn(strSpD, "dude"));
    TStream<Integer> byteSpFiltered = s.filter(predicateFn(byteSp, (byte) 1));
    TStream<Integer> byteSpDFiltered = s.filter(predicateFn(byteSpD, (byte) 2));
    TStream<Integer> shortSpFiltered = s.filter(predicateFn(shortSp, (short) 3));
    TStream<Integer> shortSpDFiltered = s.filter(predicateFn(shortSpD, (short) 4));
    TStream<Integer> intSpFiltered = s.filter(predicateFn(intSp, 5));
    TStream<Integer> intSpDFiltered = s.filter(predicateFn(intSpD, 6));
    TStream<Integer> longSpFiltered = s.filter(predicateFn(longSp, (long) 7));
    TStream<Integer> longSpDFiltered = s.filter(predicateFn(longSpD, (long) 8));
    TStream<Integer> floatSpFiltered = s.filter(predicateFn(floatSp, 9.0f));
    TStream<Integer> floatSpDFiltered = s.filter(predicateFn(floatSpD, 10.0f));
    TStream<Integer> doubleSpFiltered = s.filter(predicateFn(doubleSp, 11.0d));
    TStream<Integer> doubleSpDFiltered = s.filter(predicateFn(doubleSpD, 12.0d));
    Map<String, Object> params = new HashMap<>();
    params.put("strSp", "yo");
    params.put("byteSp", (byte) 1);
    params.put("shortSp", (short) 3);
    params.put("intSp", 5);
    params.put("longSp", (long) 7);
    params.put("floatSp", 9.0f);
    params.put("doubleSp", 11.0d);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    ////////////////////
    Set<TStream<Integer>> all = new HashSet<>(Arrays.asList(strSpFiltered, strSpDFiltered, byteSpFiltered, byteSpDFiltered, shortSpFiltered, shortSpDFiltered, intSpFiltered, intSpDFiltered, longSpFiltered, longSpDFiltered, floatSpFiltered, floatSpDFiltered, doubleSpFiltered, doubleSpDFiltered));
    TStream<Integer> union = strSpFiltered.union(all);
    Tester tester = topology.getTester();
    Condition<Long> expectedCount0 = tester.tupleCount(union, all.size() * expectedCnt);
    Condition<Long> expectedCount1 = tester.tupleCount(strSpFiltered, expectedCnt);
    Condition<Long> expectedCount2 = tester.tupleCount(strSpDFiltered, expectedCnt);
    Condition<Long> expectedCount3 = tester.tupleCount(byteSpFiltered, expectedCnt);
    Condition<Long> expectedCount4 = tester.tupleCount(byteSpDFiltered, expectedCnt);
    Condition<Long> expectedCount5 = tester.tupleCount(shortSpFiltered, expectedCnt);
    Condition<Long> expectedCount6 = tester.tupleCount(shortSpDFiltered, expectedCnt);
    Condition<Long> expectedCount7 = tester.tupleCount(intSpFiltered, expectedCnt);
    Condition<Long> expectedCount8 = tester.tupleCount(intSpDFiltered, expectedCnt);
    Condition<Long> expectedCount9 = tester.tupleCount(longSpFiltered, expectedCnt);
    Condition<Long> expectedCount10 = tester.tupleCount(longSpDFiltered, expectedCnt);
    Condition<Long> expectedCount11 = tester.tupleCount(floatSpFiltered, expectedCnt);
    Condition<Long> expectedCount12 = tester.tupleCount(floatSpDFiltered, expectedCnt);
    Condition<Long> expectedCount13 = tester.tupleCount(doubleSpFiltered, expectedCnt);
    Condition<Long> expectedCount14 = tester.tupleCount(doubleSpDFiltered, expectedCnt);
    complete(tester, expectedCount0, 15, TimeUnit.SECONDS);
    assertTrue(expectedCount1.toString(), expectedCount1.valid());
    assertTrue(expectedCount2.toString(), expectedCount2.valid());
    assertTrue(expectedCount3.toString(), expectedCount3.valid());
    assertTrue(expectedCount4.toString(), expectedCount4.valid());
    assertTrue(expectedCount5.toString(), expectedCount5.valid());
    assertTrue(expectedCount6.toString(), expectedCount6.valid());
    assertTrue(expectedCount7.toString(), expectedCount7.valid());
    assertTrue(expectedCount8.toString(), expectedCount8.valid());
    assertTrue(expectedCount9.toString(), expectedCount9.valid());
    assertTrue(expectedCount10.toString(), expectedCount10.valid());
    assertTrue(expectedCount11.toString(), expectedCount11.valid());
    assertTrue(expectedCount12.toString(), expectedCount12.valid());
    assertTrue(expectedCount13.toString(), expectedCount13.valid());
    assertTrue(expectedCount14.toString(), expectedCount14.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) TStream(com.ibm.streamsx.topology.TStream) Test(org.junit.Test)

Example 19 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 20 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("Union");
    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)

Aggregations

TStream (com.ibm.streamsx.topology.TStream)29 Topology (com.ibm.streamsx.topology.Topology)24 Test (org.junit.Test)24 Tester (com.ibm.streamsx.topology.tester.Tester)22 List (java.util.List)20 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)16 HashMap (java.util.HashMap)16 Condition (com.ibm.streamsx.topology.tester.Condition)15 TimeUnit (java.util.concurrent.TimeUnit)14 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)13 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)13 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)13 SPLStreams (com.ibm.streamsx.topology.spl.SPLStreams)13 Map (java.util.Map)13 Constants (com.ibm.streamsx.kafka.test.utils.Constants)12 KafkaSPLStreamsUtils (com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils)12 SPL (com.ibm.streamsx.topology.spl.SPL)12 Assert (org.junit.Assert)12 Delay (com.ibm.streamsx.kafka.test.utils.Delay)11 TestTopology (com.ibm.streamsx.topology.test.TestTopology)11