Search in sources :

Example 31 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class JobConfigOverlaysFileTest method testWithIsolate.

@Test
public void testWithIsolate() throws Exception {
    // Just a simple graph, which won't be executed.
    Topology topology = newTopology("testNoConfig");
    topology.constants(Collections.emptyList()).isolate().sink(tuple -> {
    });
    sab = bundler().submit(topology).get();
    JsonObject jcos = assertSabGetJcos(topology);
    assertLegacyDeployment(jcos);
    JsonObject jco = jobConfigOverlay(jcos);
    assertMissing(jco, "jobConfig");
    assertMissing(jco, "operatorConfigs");
    assertMissing(jco, "configInstructions");
}
Also used : JsonObject(com.google.gson.JsonObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 32 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class JobConfigSubmissionTest method testItDirect.

private List<String> testItDirect(String topologyName, JobConfig config) throws Exception {
    // JobConfig only apply to DISTRIBUTED submit
    assumeTrue(getTesterType() == StreamsContext.Type.DISTRIBUTED_TESTER);
    assumeTrue(SC_OK);
    config.addToConfig(getConfig());
    Topology topology = newTopology(topologyName);
    topology.addClassDependency(JobPropertiesTestOp.class);
    SPLStream sourceSPL = JavaPrimitive.invokeJavaPrimitiveSource(topology, JobPropertiesTestOp.class, Schemas.STRING, null);
    TStream<String> source = sourceSPL.toStringStream();
    Condition<Long> end = topology.getTester().tupleCount(source, 4);
    Condition<List<String>> result = topology.getTester().stringContents(source);
    complete(topology.getTester(), end, 10, TimeUnit.SECONDS);
    return result.getResult();
}
Also used : 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 33 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class JSONStreamsTest method testJSONAble.

@Test
public void testJSONAble() throws IOException, Exception {
    Topology topology = new Topology();
    final TestJSONAble value = new TestJSONAble(42, QUESTION);
    TStream<TestJSONAble> s = topology.constants(Collections.singletonList(value)).asType(TestJSONAble.class);
    TStream<JSONObject> js = JSONStreams.toJSON(s);
    JSONObject ev = new JSONObject();
    ev.put("b", QUESTION);
    ev.put("a", 42l);
    checkJsonOutput(ev, JSONStreams.serialize(js));
}
Also used : JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 34 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class JSONStreamsTest method testFlattenNoObjects.

@Test
public void testFlattenNoObjects() throws Exception {
    final Topology t = new Topology();
    final JSONObject value = new JSONObject();
    final JSONArray array = new JSONArray();
    array.add("hello");
    value.put("greetings", array);
    TStream<JSONObject> s = t.constants(Collections.singletonList(value));
    TStream<JSONObject> jsonm = JSONStreams.flattenArray(s, "greetings");
    TStream<String> output = JSONStreams.serialize(jsonm);
    JSONObject payload = new JSONObject();
    payload.put("payload", "hello");
    completeAndValidate(output, 10, payload.toString());
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 35 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class KafkaStreamsTest method testReusableApp.

@Test
public void testReusableApp() throws Exception {
    // Threads per topic not supported in 4.2 onwards
    skipVersion("kafka.threadsPerTopic", 4, 2);
    checkAssumes();
    Topology top = new Topology("testReusableApp");
    MsgGenerator mgen = new MsgGenerator(top.getName());
    String groupId = newGroupId(top.getName());
    String topicVal = getKafkaTopics()[0];
    Supplier<String> topic = top.createSubmissionParameter("kafka.topic", topicVal);
    Supplier<Integer> threadsPerTopic = top.createSubmissionParameter("kafka.consumer.threadsPerTopic", 1);
    KafkaProducer producer = new KafkaProducer(top, createProducerConfig());
    KafkaConsumer consumer = new KafkaConsumer(top, createConsumerConfig(groupId));
    // Test producer that takes an arbitrary TStream<T> and explicit topic
    List<Vals> msgs = new ArrayList<>();
    msgs.add(new Vals(mgen.create(topicVal, "Hello"), null, null));
    msgs.add(new Vals(mgen.create(topicVal, "key1", "Are you there?"), "key1", null));
    msgs.add(new Vals(mgen.create(topicVal, "Msg with an empty key"), "", null));
    msgs.add(new Vals("", mgen.create(topicVal, null, "Msg with an empty msg (this is the key)"), null));
    TStream<Vals> valsToPublish = top.constants(msgs).asType(Vals.class);
    TStream<Message> msgsToPublish = valsToPublish.transform(msgFromValsFunc(null));
    msgsToPublish = msgsToPublish.modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
    producer.publish(msgsToPublish, topic);
    TStream<Message> rcvdMsgs = consumer.subscribe(threadsPerTopic, topic);
    // for validation...
    rcvdMsgs.print();
    // just our msgs
    rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
    TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
    List<Message> expectedAsMessage = mapList(msgs, msgFromValsFunc(topicVal));
    expectedAsMessage = modifyList(expectedAsMessage, adjustKey());
    List<String> expectedAsString = mapList(expectedAsMessage, msgToJSONStringFunc());
    setupDebug();
    if (testBuildOnly(top))
        return;
    completeAndValidate(groupId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
}
Also used : KafkaProducer(com.ibm.streamsx.topology.messaging.kafka.KafkaProducer) InitialDelay(com.ibm.streamsx.topology.test.InitialDelay) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) ArrayList(java.util.ArrayList) KafkaConsumer(com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)282 TestTopology (com.ibm.streamsx.topology.test.TestTopology)235 Test (org.junit.Test)227 List (java.util.List)80 Tester (com.ibm.streamsx.topology.tester.Tester)75 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)53 ArrayList (java.util.ArrayList)50 HashMap (java.util.HashMap)33 JSONObject (com.ibm.json.java.JSONObject)25 TStream (com.ibm.streamsx.topology.TStream)23 Message (com.ibm.streamsx.topology.tuple.Message)20 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)20 Random (java.util.Random)19 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)16 File (java.io.File)16 Map (java.util.Map)16 OutputTuple (com.ibm.streams.operator.OutputTuple)14 StreamSchema (com.ibm.streams.operator.StreamSchema)14 Value (com.ibm.streamsx.topology.logic.Value)14 Condition (com.ibm.streamsx.topology.tester.Condition)14