Search in sources :

Example 36 with TStream

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

the class LowLatencyTest method testNested.

@Test
public void testNested() throws Exception {
    // ensure nested low latency yields all fns in the same container
    final Topology topology = newTopology();
    final Tester tester = topology.getTester();
    String[] s1Strs = { "a" };
    TStream<String> s1 = topology.strings(s1Strs);
    TStream<String> s2 = s1.isolate().lowLatency().modify(getContainerIdAppend()).invocationName("OuterStart").lowLatency().modify(getContainerIdAppend()).invocationName("Inner").endLowLatency().modify(getContainerIdAppend()).invocationName("OuterEnd").endLowLatency();
    s2 = s2.filter(v -> true);
    TStream<String> ids = s2.flatMap(v -> getContainerIds(v)).invocationName("Flatten");
    ids = TestTopology.uniqueValues(ids);
    Condition<Long> uCount = tester.tupleCount(s2, 1);
    Condition<Long> uIds = tester.tupleCount(ids, 1);
    complete(tester, uCount.and(uIds), 10, TimeUnit.SECONDS);
    assertTrue(uCount.valid());
    assertTrue(uIds.valid());
}
Also used : TStream(com.ibm.streamsx.topology.TStream) PlaceableTest.adlAssertColocated(com.ibm.streamsx.topology.test.api.PlaceableTest.adlAssertColocated) Arrays(java.util.Arrays) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Document(org.w3c.dom.Document) Logic.identity(com.ibm.streamsx.topology.logic.Logic.identity) UnaryOperator(com.ibm.streamsx.topology.function.UnaryOperator) PERuntime(com.ibm.streams.operator.PERuntime) Tester(com.ibm.streamsx.topology.tester.Tester) PlaceableTest.produceADL(com.ibm.streamsx.topology.test.api.PlaceableTest.produceADL) IsolateTest.getContainerIdAppend(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerIdAppend) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) PlaceableTest.adlAssertDefaultHostpool(com.ibm.streamsx.topology.test.api.PlaceableTest.adlAssertDefaultHostpool) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) ToIntFunction(com.ibm.streamsx.topology.function.ToIntFunction) ContextProperties(com.ibm.streamsx.topology.context.ContextProperties) Supplier(com.ibm.streamsx.topology.function.Supplier) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 37 with TStream

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

the class LowLatencyTest method testLowLatencySplit.

@Test
public void testLowLatencySplit() throws Exception {
    assumeTrue(!isStreamingAnalyticsRun());
    // lowLatency().split() is an interesting case because split()
    // has >1 oports.
    final Topology topology = newTopology("testLowLatencySplit");
    int splitWidth = 3;
    String[] strs = { "ch0", "ch1", "ch2" };
    TStream<String> s1 = topology.strings(strs);
    s1 = s1.isolate();
    s1 = s1.lowLatency();
    // ///////////////////////////////////
    // assume that if s1.modify and the split().[modify()] are
    // in the same PE, that s1.split() is in the same too
    TStream<String> s2 = s1.modify(unaryGetPEId()).endLowLatency();
    List<TStream<String>> splits = s1.split(splitWidth, roundRobinSplitter());
    List<TStream<String>> splitChResults = new ArrayList<>();
    for (int i = 0; i < splits.size(); i++) {
        splitChResults.add(splits.get(i).modify(unaryGetPEId()));
    }
    TStream<String> splitChFanin = splitChResults.get(0).union(new HashSet<>(splitChResults.subList(1, splitChResults.size())));
    // ///////////////////////////////////
    TStream<String> all = splitChFanin.endLowLatency();
    TStream<String> peIds = all.filter(v -> true).union(s2.filter(v -> true));
    peIds = TestTopology.uniqueValues(peIds);
    Tester tester = topology.getTester();
    Condition<Long> uCount = tester.tupleCount(all, strs.length);
    Condition<Long> uniqueIds = tester.tupleCount(peIds, 1);
    complete(tester, uCount.and(uniqueIds), 10, TimeUnit.SECONDS);
    assertTrue(uniqueIds.valid());
    assertTrue(uCount.valid());
}
Also used : TStream(com.ibm.streamsx.topology.TStream) PlaceableTest.adlAssertColocated(com.ibm.streamsx.topology.test.api.PlaceableTest.adlAssertColocated) Arrays(java.util.Arrays) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Document(org.w3c.dom.Document) Logic.identity(com.ibm.streamsx.topology.logic.Logic.identity) UnaryOperator(com.ibm.streamsx.topology.function.UnaryOperator) PERuntime(com.ibm.streams.operator.PERuntime) Tester(com.ibm.streamsx.topology.tester.Tester) PlaceableTest.produceADL(com.ibm.streamsx.topology.test.api.PlaceableTest.produceADL) IsolateTest.getContainerIdAppend(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerIdAppend) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) PlaceableTest.adlAssertDefaultHostpool(com.ibm.streamsx.topology.test.api.PlaceableTest.adlAssertDefaultHostpool) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) ToIntFunction(com.ibm.streamsx.topology.function.ToIntFunction) ContextProperties(com.ibm.streamsx.topology.context.ContextProperties) Supplier(com.ibm.streamsx.topology.function.Supplier) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) TestTopology(com.ibm.streamsx.topology.test.TestTopology) 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) Test(org.junit.Test)

Example 38 with TStream

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

the class PlaceableTest method testSimpleColocate.

/**
 */
@Test
public void testSimpleColocate() throws Exception {
    adlOk();
    Topology t = newTopology();
    TStream<String> sa = t.strings("a");
    TStream<String> sb = t.strings("b");
    sa = sa.transform(tuple -> tuple).invocationName("SA");
    sb = sb.transform(tuple -> tuple).invocationName("SB");
    sa.colocate(sb);
    sa = sa.isolate().filter(tuple -> true);
    sb = sb.isolate().filter(tuple -> true);
    sa = sa.union(sb);
    Document adl = produceADL(t);
    adlAssertDefaultHostpool(adl);
    adlAssertColocated(adl, false, "SA", "SB");
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Arrays(java.util.Arrays) StringStreams(com.ibm.streamsx.topology.streams.StringStreams) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) HashSet(java.util.HashSet) AllowAll(com.ibm.streamsx.topology.test.AllowAll) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) Logic.identity(com.ibm.streamsx.topology.logic.Logic.identity) TSink(com.ibm.streamsx.topology.TSink) InputSource(org.xml.sax.InputSource) Tester(com.ibm.streamsx.topology.tester.Tester) NodeList(org.w3c.dom.NodeList) Placeable(com.ibm.streamsx.topology.context.Placeable) Assert.assertNotNull(org.junit.Assert.assertNotNull) Redirect(java.lang.ProcessBuilder.Redirect) StreamsContextFactory(com.ibm.streamsx.topology.context.StreamsContextFactory) IsolateTest.getContainerIdAppend(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerIdAppend) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) Assert.assertNull(org.junit.Assert.assertNull) Element(org.w3c.dom.Element) Ignore(org.junit.Ignore) ContextProperties(com.ibm.streamsx.topology.context.ContextProperties) Assert.assertFalse(org.junit.Assert.assertFalse) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Collections(java.util.Collections) TopologyElement(com.ibm.streamsx.topology.TopologyElement) Assert.assertEquals(org.junit.Assert.assertEquals) TestTopology(com.ibm.streamsx.topology.test.TestTopology) InputStream(java.io.InputStream) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 39 with TStream

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

the class PlaceableTest method testNoColocate.

@Test
public void testNoColocate() throws Exception {
    adlOk();
    Topology t = newTopology();
    TStream<String> sa = t.strings("a");
    TStream<String> sb = t.strings("b");
    sa = sa.transform(identity());
    sb = sb.transform(tuple -> tuple);
    sa = sa.union(sb);
    sa.forEach(tuple -> {
    });
    Document adl = produceADL(t);
    adlAssertDefaultHostpool(adl);
    adlAssertNoColocated(adl);
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Arrays(java.util.Arrays) StringStreams(com.ibm.streamsx.topology.streams.StringStreams) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) HashSet(java.util.HashSet) AllowAll(com.ibm.streamsx.topology.test.AllowAll) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) Logic.identity(com.ibm.streamsx.topology.logic.Logic.identity) TSink(com.ibm.streamsx.topology.TSink) InputSource(org.xml.sax.InputSource) Tester(com.ibm.streamsx.topology.tester.Tester) NodeList(org.w3c.dom.NodeList) Placeable(com.ibm.streamsx.topology.context.Placeable) Assert.assertNotNull(org.junit.Assert.assertNotNull) Redirect(java.lang.ProcessBuilder.Redirect) StreamsContextFactory(com.ibm.streamsx.topology.context.StreamsContextFactory) IsolateTest.getContainerIdAppend(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerIdAppend) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) Assert.assertNull(org.junit.Assert.assertNull) Element(org.w3c.dom.Element) Ignore(org.junit.Ignore) ContextProperties(com.ibm.streamsx.topology.context.ContextProperties) Assert.assertFalse(org.junit.Assert.assertFalse) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Collections(java.util.Collections) TopologyElement(com.ibm.streamsx.topology.TopologyElement) Assert.assertEquals(org.junit.Assert.assertEquals) TestTopology(com.ibm.streamsx.topology.test.TestTopology) InputStream(java.io.InputStream) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 40 with TStream

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

the class PlaceableTest method testSplit.

@Test
public void testSplit() {
    assumeTrue(isMainRun());
    Topology t = newTopology();
    TStream<String> s = t.strings("3");
    List<TStream<String>> splits = s.split(3, x -> 0);
    splits.get(0).addResourceTags("tag1");
    for (TStream<String> l : splits) {
        assertEquals(1, l.getResourceTags().size());
        assertTrue(l.getResourceTags().contains("tag1"));
    }
    splits.get(2).addResourceTags("tag921");
    for (TStream<String> l : splits) {
        assertEquals(2, l.getResourceTags().size());
        assertTrue(l.getResourceTags().contains("tag1"));
        assertTrue(l.getResourceTags().contains("tag921"));
    }
}
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)

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