use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class SPLOperatorsTest method testSPLOperator.
/**
* Test we can invoke an SPL operator.
*/
@Test
public void testSPLOperator() throws Exception {
Topology topology = new Topology("testSPLOperator");
SPLStream tuples = SPLStreamsTest.testTupleStream(topology);
// Filter on the vi attribute, passing the value 321.
Map<String, Object> params = new HashMap<>();
params.put("attr", tuples.getSchema().getAttribute("vi"));
params.put("value", 321);
SPL.addToolkit(tuples, new File(getTestRoot(), "spl/testtk"));
SPL.addToolkitDependency(tuples, "com.ibm.streamsx.topology.testing.testtk", "0.9.9");
SPLStream int32Filtered = SPL.invokeOperator("testspl::Int32Filter", tuples, tuples.getSchema(), params);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(int32Filtered, 2);
Condition<List<Tuple>> expectedTuples = tester.tupleContents(int32Filtered, SPLStreamsTest.TEST_TUPLES[0], SPLStreamsTest.TEST_TUPLES[2]);
if (isStreamingAnalyticsRun())
getConfig().put(ContextProperties.FORCE_REMOTE_BUILD, true);
complete(tester, expectedCount, 10, TimeUnit.SECONDS);
assertTrue(expectedCount.toString(), expectedCount.valid());
assertTrue(expectedTuples.toString(), expectedTuples.valid());
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class SPLOperatorsTest method testOpParamsOptionalTypes.
/**
* Test we can invoke an SPL operator with various parameter types,
* where the type is an optional type.
*/
private void testOpParamsOptionalTypes(String testName, OpParamAdder opParamAdder) throws Exception {
Topology topology = new Topology(testName);
opParamAdder.init(topology, getConfig());
StreamSchema schema = Type.Factory.getStreamSchema("tuple<" + "rstring r" + ", optional<rstring> orv" + ", optional<rstring> ornv" + ", int32 i32" + ", optional<int32> oi32v" + ", optional<int32> oi32nv" + " >");
Map<String, Object> expectedValues = new HashMap<>();
Random rand = new Random();
String r = "test X\tY\"Lit\nerals\\nX\\tY " + rand.nextInt();
opParamAdder.put("r", r);
expectedValues.put("r", new RString(r));
String orv = "test X\tY\"Lit\nerals\\nX\\tY " + rand.nextInt();
opParamAdder.put("orv", orv);
// test setting optional type to null by using null in Map
opParamAdder.put("ornv", null);
expectedValues.put("orv", new RString(orv));
expectedValues.put("ornv", null);
int i32 = rand.nextInt();
opParamAdder.put("i32", i32);
int oi32v = rand.nextInt();
opParamAdder.put("oi32v", oi32v);
// test setting optional type to null by using createNullValue() in Map
opParamAdder.put("oi32nv", SPL.createNullValue());
expectedValues.put("i32", i32);
expectedValues.put("oi32v", oi32v);
expectedValues.put("oi32nv", null);
SPL.addToolkit(topology, new File(getTestRoot(), "spl/testtkopt"));
SPLStream paramTuple = SPL.invokeSource(topology, "testgen::TypeLiteralTester", opParamAdder.getParams(), schema);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(paramTuple, 1);
Condition<?> contents = tester.tupleContents(paramTuple, schema.getTuple(expectedValues));
complete(tester, expectedCount.and(contents), 10, TimeUnit.SECONDS);
assertTrue(contents.valid());
assertTrue(expectedCount.valid());
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class SPLOperatorsTest method testOpParams.
/**
* Test we can invoke an SPL operator with various parameter types.
*/
private void testOpParams(String testName, OpParamAdder opParamAdder) throws Exception {
Topology topology = new Topology(testName);
opParamAdder.init(topology, getConfig());
StreamSchema schema = Type.Factory.getStreamSchema("tuple<" + "rstring r" + ", ustring u" + ", boolean b" + ", int8 i8, int16 i16, int32 i32, int64 i64" + ", uint8 ui8, uint16 ui16, uint32 ui32, uint64 ui64" + ", float32 f32, float64 f64" + " >");
Map<String, Object> expectedValues = new HashMap<>();
Random rand = new Random();
String r = "test X\tY\"Lit\nerals\\nX\\tY " + rand.nextInt();
opParamAdder.put("r", r);
String u = "test X\tY\"Lit\nerals\\nX\\tY " + rand.nextInt();
opParamAdder.put("u", SPL.createValue(u, MetaType.USTRING));
expectedValues.put("r", new RString(r));
expectedValues.put("u", u);
boolean b = rand.nextBoolean();
opParamAdder.put("b", b);
expectedValues.put("b", b);
byte i8 = (byte) rand.nextInt();
short i16 = (short) rand.nextInt();
int i32 = rand.nextInt();
long i64 = rand.nextLong();
opParamAdder.put("i8", i8);
opParamAdder.put("i16", i16);
opParamAdder.put("i32", i32);
opParamAdder.put("i64", i64);
expectedValues.put("i8", i8);
expectedValues.put("i16", i16);
expectedValues.put("i32", i32);
expectedValues.put("i64", i64);
// 255 => -1
byte ui8 = (byte) 0xFF;
// 65534 => -2
short ui16 = (short) 0xFFFE;
// 4294967293 => -3
int ui32 = 0xFFFFFFFD;
// 18446744073709551612 => -4
long ui64 = 0xFFFFFFFFFFFFFFFCL;
opParamAdder.put("ui8", SPL.createValue(ui8, MetaType.UINT8));
opParamAdder.put("ui16", SPL.createValue(ui16, MetaType.UINT16));
opParamAdder.put("ui32", SPL.createValue(ui32, MetaType.UINT32));
opParamAdder.put("ui64", SPL.createValue(ui64, MetaType.UINT64));
expectedValues.put("ui8", ui8);
expectedValues.put("ui16", ui16);
expectedValues.put("ui32", ui32);
expectedValues.put("ui64", ui64);
float f32 = 4.0f;
double f64 = 32.0;
opParamAdder.put("f32", f32);
opParamAdder.put("f64", f64);
expectedValues.put("f32", f32);
expectedValues.put("f64", f64);
SPL.addToolkit(topology, new File(getTestRoot(), "spl/testtk"));
SPLStream paramTuple = SPL.invokeSource(topology, "testgen::TypeLiteralTester", opParamAdder.getParams(), schema);
Tuple expectedTuple = schema.getTuple(expectedValues);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(paramTuple, 1);
Condition<?> contents = tester.tupleContents(paramTuple, expectedTuple);
;
complete(tester, expectedCount.and(contents), 10, TimeUnit.SECONDS);
assertTrue(contents.valid());
assertTrue(expectedCount.valid());
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class SPLStreamsTest method testConversionFromSPLToString.
@Test
public void testConversionFromSPLToString() throws Exception {
final Topology topology = new Topology();
SPLStream splStream = testTupleStream(topology);
TStream<String> strings = SPLStreams.toStringStream(splStream);
assertEquals(String.class, strings.getTupleClass());
completeAndValidate(strings, 10, "0", "1", "2", "3");
}
use of com.ibm.streamsx.topology.spl.SPLStream in project streamsx.topology by IBMStreams.
the class StatefulAppCR method createApp.
public static TStream<Long> createApp(Topology topology, boolean fail) {
Map<String, Object> params = new HashMap<>();
params.put("period", 0.0005);
params.put("iterations", 512_345);
SPLStream b = SPL.invokeSource(topology, "spl.utility::Beacon", params, com.ibm.streams.operator.Type.Factory.getStreamSchema("tuple<int64 a>"));
b.setConsistent(ConsistentRegionConfig.periodic(30));
TStream<Long> s = b.map(t -> t.getLong(0));
s = s.isolate().filter(new StatefulApp.Stateful.Filter(fail));
s = s.isolate().map(new StatefulApp.Stateful.Map(fail));
s.isolate().forEach(new StatefulApp.Stateful.ForEach(fail));
return s;
}
Aggregations