Search in sources :

Example 1 with Condition

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

the class TupleCollection method stringContentsUnordered.

@Override
public Condition<List<String>> stringContentsUnordered(TStream<String> stream, String... values) {
    final List<String> sortedValues = Arrays.asList(values);
    Collections.sort(sortedValues);
    final StreamCollector<LinkedList<Tuple>, Tuple> tuples = StreamCollector.newLinkedListCollector();
    addHandler(stream, tuples);
    return new Condition<List<String>>() {

        @Override
        public List<String> getResult() {
            List<String> strings = new ArrayList<>(tuples.getTupleCount());
            synchronized (tuples.getTuples()) {
                for (Tuple tuple : tuples.getTuples()) {
                    strings.add(tuple.getString(0));
                }
            }
            return strings;
        }

        @Override
        public boolean valid() {
            List<String> strings = getResult();
            if (strings.size() != sortedValues.size())
                return false;
            Collections.sort(strings);
            return sortedValues.equals(strings);
        }

        @Override
        public String toString() {
            return "Received Tuples: " + getResult();
        }
    };
}
Also used : Condition(com.ibm.streamsx.topology.tester.Condition) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Example 2 with Condition

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

the class TupleCollection method stringContents.

@Override
public Condition<List<String>> stringContents(TStream<String> stream, final String... values) {
    stream = stream.asType(String.class);
    final StreamCollector<LinkedList<Tuple>, Tuple> tuples = StreamCollector.newLinkedListCollector();
    addHandler(stream, tuples);
    return new Condition<List<String>>() {

        @Override
        public List<String> getResult() {
            List<String> strings = new ArrayList<>(tuples.getTupleCount());
            synchronized (tuples.getTuples()) {
                for (Tuple tuple : tuples.getTuples()) {
                    strings.add(tuple.getString(0));
                }
            }
            return strings;
        }

        @Override
        public boolean valid() {
            if (tuples.getTupleCount() != values.length)
                return false;
            List<Tuple> sc = tuples.getTuples();
            for (int i = 0; i < values.length; i++) {
                if (!sc.get(i).getString(0).equals(values[i]))
                    return false;
            }
            return true;
        }

        @Override
        public String toString() {
            return "Received Tuples: " + getResult();
        }
    };
}
Also used : Condition(com.ibm.streamsx.topology.tester.Condition) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Example 3 with Condition

use of com.ibm.streamsx.topology.tester.Condition 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 4 with Condition

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

Aggregations

Condition (com.ibm.streamsx.topology.tester.Condition)4 ArrayList (java.util.ArrayList)4 OutputTuple (com.ibm.streams.operator.OutputTuple)2 Tuple (com.ibm.streams.operator.Tuple)2 TStream (com.ibm.streamsx.topology.TStream)2 Topology (com.ibm.streamsx.topology.Topology)2 TestTopology (com.ibm.streamsx.topology.test.TestTopology)2 Tester (com.ibm.streamsx.topology.tester.Tester)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 JSONObject (com.ibm.json.java.JSONObject)1 PERuntime (com.ibm.streams.operator.PERuntime)1 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)1 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)1 Supplier (com.ibm.streamsx.topology.function.Supplier)1 ToIntFunction (com.ibm.streamsx.topology.function.ToIntFunction)1 UnaryOperator (com.ibm.streamsx.topology.function.UnaryOperator)1 CONFIG (com.ibm.streamsx.topology.generator.operator.OpProperties.CONFIG)1