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);
}
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());
}
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\"}");
}
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);
}
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;
}
Aggregations