Search in sources :

Example 1 with BeaconTuple

use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.

the class AutoTypeTest method _testAutoLimitedSourceClass.

private static void _testAutoLimitedSourceClass() {
    Topology t = newTopology();
    TStream<BeaconTuple> stream = t.limitedSource(new Supplier<BeaconTuple>() {

        @Override
        public BeaconTuple get() {
            return new BeaconTuple(0);
        }
    }, 8);
    assertEquals(BeaconTuple.class, stream.getTupleClass());
}
Also used : BeaconTuple(com.ibm.streamsx.topology.tuple.BeaconTuple) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology)

Example 2 with BeaconTuple

use of com.ibm.streamsx.topology.tuple.BeaconTuple 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 3 with BeaconTuple

use of com.ibm.streamsx.topology.tuple.BeaconTuple 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)

Example 4 with BeaconTuple

use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelSubmissionParamDefault.

@Test
public void testParallelSubmissionParamDefault() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testParallelSubmissionParamDefault");
    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, submissionWidth));
    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());
    complete(tester, allConditions(regionCount, expectedCount), 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(regionCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) 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 BeaconTuple

use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.

the class ParallelTest method testParallelPartitioned.

@Test
public void testParallelPartitioned() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testParallelPartition");
    final int count = new Random().nextInt(10) + 37;
    TStream<BeaconTuple> kb = topology.source(keyableBeacon5Counter(count));
    TStream<BeaconTuple> pb = kb.parallel(new Value<Integer>(5), keyBeacon());
    TStream<ChannelAndSequence> cs = pb.transform(channelSeqTransformer());
    TStream<ChannelAndSequence> joined = cs.endParallel();
    TStream<String> valid_count = joined.transform(partitionCounter(count));
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(valid_count, 1);
    Condition<List<String>> validCount = tester.stringContents(valid_count, "5");
    complete(tester, allConditions(expectedCount, validCount), 10, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(validCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) 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)

Aggregations

BeaconTuple (com.ibm.streamsx.topology.tuple.BeaconTuple)14 Test (org.junit.Test)12 Topology (com.ibm.streamsx.topology.Topology)11 TestTopology (com.ibm.streamsx.topology.test.TestTopology)10 Tester (com.ibm.streamsx.topology.tester.Tester)9 Random (java.util.Random)9 ArrayList (java.util.ArrayList)6 List (java.util.List)6 HashMap (java.util.HashMap)2 JSONObject (com.ibm.json.java.JSONObject)1 StreamSchema (com.ibm.streams.operator.StreamSchema)1 Factory.getStreamSchema (com.ibm.streams.operator.Type.Factory.getStreamSchema)1 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)1 File (java.io.File)1 IOException (java.io.IOException)1