Search in sources :

Example 1 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class TestTopology method completeAndValidate.

public void completeAndValidate(Map<String, Object> config, TStream<?> output, int seconds, String... contents) throws Exception {
    Tester tester = output.topology().getTester();
    if (getTesterType() == Type.DISTRIBUTED_TESTER)
        seconds += getStartupDelay();
    Condition<List<String>> expectedContents = tester.completeAndTestStringOutput(getTesterContext(), config, output, seconds, TimeUnit.SECONDS, contents);
    assertTrue(expectedContents.toString(), expectedContents.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class LowLatencyTest method testSameThread.

/**
     * Test the same thread executes the low latency section.
     */
@Test
public void testSameThread() throws Exception {
    final int tc = 2000;
    final Topology topology = newTopology("testSameThread");
    final Tester tester = topology.getTester();
    TStream<Long> s1 = topology.limitedSource(new Rnd(), tc);
    TStream<Long> s2 = topology.limitedSource(new Rnd(), tc);
    TStream<Long> s3 = topology.limitedSource(new Rnd(), tc);
    TStream<Long> s4 = topology.limitedSource(new Rnd(), tc);
    TStream<Long> s = s1.union(new HashSet<>(Arrays.asList(s2, s3, s4)));
    s = s.lowLatency();
    s = s.transform(new SetThread());
    for (int i = 0; i < 20; i++) s = s.transform(new CheckThread());
    s = s.transform(new ClearThread());
    s = s.endLowLatency();
    s = s.filter(t -> true);
    this.getConfig().put(com.ibm.streamsx.topology.context.ContextProperties.KEEP_ARTIFACTS, Boolean.TRUE);
    Condition<Long> endCondition = tester.tupleCount(s, 4 * tc);
    this.complete(tester, endCondition, 30, TimeUnit.SECONDS);
}
Also used : TStream(com.ibm.streamsx.topology.TStream) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) Random(java.util.Random) ArrayList(java.util.ArrayList) GsonUtilities.jstring(com.ibm.streamsx.topology.internal.gson.GsonUtilities.jstring) HashSet(java.util.HashSet) AllowAll(com.ibm.streamsx.topology.test.AllowAll) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) IsolateTest.getContainerIds(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerIds) UnaryOperator(com.ibm.streamsx.topology.function.UnaryOperator) PERuntime(com.ibm.streams.operator.PERuntime) Tester(com.ibm.streamsx.topology.tester.Tester) CONFIG(com.ibm.streamsx.topology.generator.operator.OpProperties.CONFIG) PLACEMENT_LOW_LATENCY_REGION_ID(com.ibm.streamsx.topology.generator.operator.OpProperties.PLACEMENT_LOW_LATENCY_REGION_ID) StreamsContextFactory(com.ibm.streamsx.topology.context.StreamsContextFactory) IsolateTest.getContainerIdAppend(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerIdAppend) JSON4JUtilities(com.ibm.streamsx.topology.internal.json4j.JSON4JUtilities) Set(java.util.Set) Test(org.junit.Test) SPLGenerator(com.ibm.streamsx.topology.generator.spl.SPLGenerator) GsonUtilities.object(com.ibm.streamsx.topology.internal.gson.GsonUtilities.object) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) ToIntFunction(com.ibm.streamsx.topology.function.ToIntFunction) GsonUtilities(com.ibm.streamsx.topology.internal.gson.GsonUtilities) Supplier(com.ibm.streamsx.topology.function.Supplier) JSONObject(com.ibm.json.java.JSONObject) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) IsolateTest.getContainerId(com.ibm.streamsx.topology.test.api.IsolateTest.getContainerId) Assert.assertEquals(org.junit.Assert.assertEquals) TestTopology(com.ibm.streamsx.topology.test.TestTopology) PLACEMENT(com.ibm.streamsx.topology.generator.operator.OpProperties.PLACEMENT) 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 3 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelIsolate.

@Test
public void testParallelIsolate() throws Exception {
    assumeTrue(getTesterType() == StreamsContext.Type.DISTRIBUTED_TESTER);
    skipVersion("udp-fusing", 4, 2);
    Topology topology = newTopology();
    TStream<String> strings = topology.strings("A", "B", "C", "D", "E", "F", "G", "H", "I");
    TStream<String> stringsP = strings.parallel(3);
    TStream<Map<Integer, String>> channelPe = stringsP.transform(new ChannelAndPEid());
    channelPe = channelPe.endParallel();
    TStream<String> result = channelPe.transform(new CheckSeparatePE());
    Tester tester = topology.getTester();
    Condition<Long> singleResult = tester.tupleCount(result, 1);
    Condition<List<String>> contents = tester.stringContents(result, "true");
    complete(tester, allConditions(singleResult, contents), 10, TimeUnit.SECONDS);
    assertTrue("contents: " + contents, contents.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelSubmissionParam.

@Test
public void testParallelSubmissionParam() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testParallelSubmissionParam");
    final int count = new Random().nextInt(1000) + 37;
    String submissionWidthName = "width";
    Integer submissionWidth = 5;
    TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
    TStream<BeaconTuple> pb = fb.parallel(topology.createSubmissionParameter(submissionWidthName, Integer.class));
    TStream<Integer> is = pb.transform(randomHashProducer());
    TStream<Integer> joined = is.endParallel();
    TStream<String> numRegions = joined.transform(uniqueIdentifierMap(count));
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(numRegions, 1);
    Condition<List<String>> regionCount = tester.stringContents(numRegions, submissionWidth.toString());
    Map<String, Object> params = new HashMap<>();
    params.put(submissionWidthName, submissionWidth);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    complete(tester, allConditions(regionCount, regionCount), 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(regionCount.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) Random(java.util.Random) BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with Tester

use of com.ibm.streamsx.topology.tester.Tester in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelSubmissionParamInner.

@Test
public void testParallelSubmissionParamInner() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testParallelSubmissionParamInner");
    final int count = new Random().nextInt(1000) + 37;
    String submissionWidthName = "width";
    Integer submissionWidth = 5;
    String submissionAppendName = "append";
    boolean submissionAppend = true;
    String submissionFlushName = "flush";
    Integer submissionFlush = 1;
    String submissionThresholdName = "threshold";
    String submissionDefaultedThresholdName = "defaultedTreshold";
    Integer submissionThreshold = -1;
    // getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    Supplier<Integer> threshold = topology.createSubmissionParameter(submissionThresholdName, Integer.class);
    Supplier<Integer> defaultedThreshold = topology.createSubmissionParameter(submissionDefaultedThresholdName, submissionThreshold);
    TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
    TStream<BeaconTuple> pb = fb.parallel(topology.createSubmissionParameter(submissionWidthName, Integer.class));
    TStream<Integer> is = pb.transform(randomHashProducer());
    // submission param use within a parallel region
    StreamSchema schema = getStreamSchema("tuple<int32 i>");
    SPLStream splStream = SPLStreams.convertStream(is, cvtMsgFunc(), schema);
    File tmpFile = File.createTempFile("parallelTest", null);
    tmpFile.deleteOnExit();
    Map<String, Object> splParams = new HashMap<>();
    splParams.put("file", tmpFile.getAbsolutePath());
    splParams.put("append", topology.createSubmissionParameter(submissionAppendName, submissionAppend));
    splParams.put("flush", SPL.createSubmissionParameter(topology, submissionFlushName, SPL.createValue(0, Type.MetaType.UINT32), false));
    SPL.invokeSink("spl.adapter::FileSink", splStream, splParams);
    // use a submission parameter in "inner" functional logic
    is = is.filter(thresholdFilter(threshold));
    is = is.filter(thresholdFilter(defaultedThreshold));
    // avoid another parallel impl limitation noted in issue#173
    is = is.filter(passthru());
    TStream<Integer> joined = is.endParallel();
    TStream<String> numRegions = joined.transform(uniqueIdentifierMap(count));
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(numRegions, 1);
    Condition<List<String>> regionCount = tester.stringContents(numRegions, submissionWidth.toString());
    Map<String, Object> params = new HashMap<>();
    params.put(submissionWidthName, submissionWidth);
    params.put(submissionFlushName, submissionFlush);
    params.put(submissionThresholdName, submissionThreshold);
    getConfig().put(ContextProperties.SUBMISSION_PARAMS, params);
    complete(tester, allConditions(expectedCount, regionCount), 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(regionCount.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) StreamSchema(com.ibm.streams.operator.StreamSchema) Factory.getStreamSchema(com.ibm.streams.operator.Type.Factory.getStreamSchema) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Random(java.util.Random) BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Aggregations

Tester (com.ibm.streamsx.topology.tester.Tester)68 Topology (com.ibm.streamsx.topology.Topology)61 TestTopology (com.ibm.streamsx.topology.test.TestTopology)60 Test (org.junit.Test)60 List (java.util.List)50 ArrayList (java.util.ArrayList)28 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)20 Random (java.util.Random)13 Tuple (com.ibm.streams.operator.Tuple)12 HashMap (java.util.HashMap)10 TStream (com.ibm.streamsx.topology.TStream)9 BeaconTuple (com.ibm.streamsx.topology.tuple.BeaconTuple)9 JSONObject (com.ibm.json.java.JSONObject)8 AllowAll (com.ibm.streamsx.topology.test.AllowAll)8 HashSet (java.util.HashSet)8 OutputTuple (com.ibm.streams.operator.OutputTuple)6 StreamSchema (com.ibm.streams.operator.StreamSchema)6 LinkedList (java.util.LinkedList)6 File (java.io.File)4 JSONArray (com.ibm.json.java.JSONArray)3