Search in sources :

Example 66 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class JSONStreamsTest method testJsonSPL.

@Test
public void testJsonSPL() throws Exception {
    final Topology t = new Topology();
    TStream<String> example = t.strings(JSON_EXAMPLE);
    TStream<JSONObject> json = JSONStreams.deserialize(example);
    SPLStream spl = JSONStreams.toSPL(json);
    assertEquals(JSONSchemas.JSON, spl.getSchema());
    TStream<JSONObject> jsonFromSPL = spl.toJSON();
    assertEquals(JSONObject.class, jsonFromSPL.getTupleClass());
    assertEquals(JSONObject.class, jsonFromSPL.getTupleType());
    TStream<String> jsonString = JSONStreams.serialize(jsonFromSPL);
    checkJsonOutput(JSON.parse(JSON_EXAMPLE), jsonString);
}
Also used : JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 67 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class JobPropertiesTest method testItDirect.

private void testItDirect(String topologyName, String propName, Object value, String... expected) throws Exception {
    // Primitive op has direct dependency on Java Operator API
    assumeTrue(hasStreamsInstall());
    // JobProperties only apply to DISTRIBUTED submit
    assumeTrue(isDistributedOrService());
    getConfig().put(propName, value);
    Topology topology = newTopology(topologyName);
    topology.addClassDependency(JobPropertiesTestOp.class);
    SPLStream sourceSPL = JavaPrimitive.invokeJavaPrimitiveSource(topology, JobPropertiesTestOp.class, SPLSchemas.STRING, null);
    TStream<String> source = sourceSPL.toStringStream();
    Condition<Long> end = topology.getTester().tupleCount(source, 4);
    Condition<List<String>> result = topology.getTester().stringContents(source, expected);
    complete(topology.getTester(), end.and(result), 10, TimeUnit.SECONDS);
    assertTrue(result.valid());
    assertTrue(end.valid());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Example 68 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testConversionToSPL.

@Test
public void testConversionToSPL() throws Exception {
    final Topology topology = new Topology("ConvertSPLStream");
    SPLStream splStream = createSPLFlowFromStream(topology, false);
    TStream<String> tupleString = splStream.toTupleString();
    assertEquals(String.class, tupleString.getTupleClass());
    assertEquals(String.class, tupleString.getTupleType());
    completeAndValidate(tupleString, 10, "{ii=418,ss=\"325\"}", "{ii=550,ss=\"457\"}", "{ii=9418,ss=\"9325\"}");
}
Also used : Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) Test(org.junit.Test)

Example 69 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method testMaintainSPLStream.

@Test
public void testMaintainSPLStream() {
    assumeTrue(isMainRun());
    Topology t = new Topology();
    SPLStream splStreamA = testTupleStream(t);
    assertSPLStream(splStreamA, TEST_SCHEMA);
    SPLStream splStreamB = splStreamA.filter(new AllowAll<Tuple>());
    assertSPLStream(splStreamB, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamA = splStreamB.sample(1.0);
    assertSPLStream(splStreamA, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamB = splStreamA.throttle(1, TimeUnit.MICROSECONDS);
    assertSPLStream(splStreamB, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamA = splStreamB.lowLatency();
    assertSPLStream(splStreamA, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamA = splStreamA.filter(new AllowAll<Tuple>());
    splStreamB = splStreamA.endLowLatency();
    assertSPLStream(splStreamB, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamA = splStreamB.parallel(3);
    assertSPLStream(splStreamA, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamA = splStreamA.filter(new AllowAll<Tuple>());
    splStreamB = splStreamA.endParallel();
    assertSPLStream(splStreamB, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamB = splStreamB.filter(new AllowAll<Tuple>());
    splStreamA = splStreamB.parallel(of(2), Routing.ROUND_ROBIN);
    assertSPLStream(splStreamA, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamA = splStreamA.filter(new AllowAll<Tuple>());
    splStreamB = splStreamA.endParallel();
    assertSPLStream(splStreamB, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamB = splStreamB.filter(new AllowAll<Tuple>());
    splStreamA = splStreamB.isolate();
    assertSPLStream(splStreamA, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
    splStreamB = splStreamA.autonomous();
    assertSPLStream(splStreamB, TEST_SCHEMA);
    assertNotSame(splStreamA, splStreamB);
}
Also used : AllowAll(com.ibm.streamsx.topology.test.AllowAll) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple) Test(org.junit.Test)

Example 70 with SPLStream

use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.

the class PythonFunctionalOperatorsTest method testTupleStream.

public static SPLStream testTupleStream(Topology topology, boolean withSets) {
    TStream<Long> beacon = BeaconStreams.longBeacon(topology, TUPLE_COUNT);
    SPLStream tuples = SPLStreams.convertStream(beacon, new BiFunction<Long, OutputTuple, OutputTuple>() {

        private static final long serialVersionUID = 1L;

        private transient TupleType type;

        private transient Random rand;

        @Override
        public OutputTuple apply(Long v1, OutputTuple v2) {
            if (type == null) {
                type = Type.Factory.getTupleType(getPythonTypesSchema(withSets).getLanguageType());
                rand = new Random();
            }
            Tuple randTuple = (Tuple) type.randomValue(rand);
            v2.assign(randTuple);
            return v2;
        }
    }, getPythonTypesSchema(withSets));
    return tuples;
}
Also used : Random(java.util.Random) TupleType(com.ibm.streams.operator.meta.TupleType) OutputTuple(com.ibm.streams.operator.OutputTuple) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Aggregations

SPLStream (com.ibm.streamsx.topology.spl.SPLStream)86 Topology (com.ibm.streamsx.topology.Topology)66 Test (org.junit.Test)56 TestTopology (com.ibm.streamsx.topology.test.TestTopology)49 Tester (com.ibm.streamsx.topology.tester.Tester)40 List (java.util.List)38 HashMap (java.util.HashMap)33 StreamSchema (com.ibm.streams.operator.StreamSchema)25 OutputTuple (com.ibm.streams.operator.OutputTuple)20 Tuple (com.ibm.streams.operator.Tuple)19 Map (java.util.Map)17 TStream (com.ibm.streamsx.topology.TStream)15 SPL (com.ibm.streamsx.topology.spl.SPL)14 Condition (com.ibm.streamsx.topology.tester.Condition)14 TimeUnit (java.util.concurrent.TimeUnit)14 Constants (com.ibm.streamsx.kafka.test.utils.Constants)12 KafkaSPLStreamsUtils (com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils)12 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)12 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)12 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)12