Search in sources :

Example 16 with StreamsContext

use of com.ibm.streamsx.topology.context.StreamsContext in project streamsx.topology by IBMStreams.

the class PlaceableTest method produceADL.

public static Document produceADL(TopologyElement te) throws Exception {
    @SuppressWarnings("unchecked") StreamsContext<File> ctx = (StreamsContext<File>) StreamsContextFactory.getStreamsContext(StreamsContext.Type.TOOLKIT);
    File tkDir = ctx.submit(te.topology()).get();
    System.out.println("TKDIR:" + tkDir);
    String topoTkDir = System.getProperty("topology.toolkit.release");
    List<String> cmd = new ArrayList<>();
    cmd.add(System.getenv("STREAMS_INSTALL") + "/bin/sc");
    cmd.add("--suppress-all-but-the-application-model");
    cmd.add("--spl-path");
    cmd.add(topoTkDir);
    cmd.add("--main-composite");
    cmd.add(te.topology().getNamespace() + "::" + te.topology().getName());
    ProcessBuilder pb = new ProcessBuilder(cmd);
    pb.directory(tkDir);
    pb.redirectInput(Redirect.INHERIT);
    pb.redirectOutput(Redirect.INHERIT);
    pb.redirectError(Redirect.INHERIT);
    Process p = pb.start();
    int rc = p.waitFor();
    System.out.println("RC:" + rc);
    assertEquals(0, rc);
    File adl = new File(tkDir, "output/" + te.topology().getNamespace() + "." + te.topology().getName() + ".adl");
    assertTrue(adl.exists());
    assertTrue(adl.isFile());
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    try (InputStream adlIn = new FileInputStream(adl)) {
        return db.parse(new InputSource(adlIn));
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) File(java.io.File)

Example 17 with StreamsContext

use of com.ibm.streamsx.topology.context.StreamsContext in project streamsx.topology by IBMStreams.

the class ToolkitTest method testParallel.

@Test
public void testParallel() throws Exception {
    final Topology topology = newTopology("TKParallel");
    TStream<Number> s1 = topology.numbers(1, 2, 3, 94, 5, 6).parallel(6).filter(new AllowAll<Number>()).endParallel();
    @SuppressWarnings("unused") TStream<String> sp = StringStreams.toString(s1);
    @SuppressWarnings("unchecked") StreamsContext<File> tkContext = (StreamsContext<File>) StreamsContextFactory.getStreamsContext(Type.TOOLKIT);
    File tkRoot = tkContext.submit(topology).get();
    assertNotNull(tkRoot);
    assertTrue(tkRoot.exists());
}
Also used : AllowAll(com.ibm.streamsx.topology.test.AllowAll) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) File(java.io.File) Test(org.junit.Test)

Example 18 with StreamsContext

use of com.ibm.streamsx.topology.context.StreamsContext in project streamsx.topology by IBMStreams.

the class ServiceSubmissionAPITest method submitFromBundle.

private void submitFromBundle(Topology topology) throws Exception {
    @SuppressWarnings("unchecked") StreamsContext<BigInteger> ctx = (StreamsContext<BigInteger>) StreamsContextFactory.getStreamsContext("STREAMING_ANALYTICS_SERVICE");
    BigInteger jobId = ctx.submit(topology, getConfig()).get();
    assertNotNull(jobId);
    cancel(jobId);
}
Also used : StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) BigInteger(java.math.BigInteger)

Example 19 with StreamsContext

use of com.ibm.streamsx.topology.context.StreamsContext in project streamsx.topology by IBMStreams.

the class ServiceSubmissionAPITest method testNoResults.

@Test
public void testNoResults() throws Exception {
    TStream<String> stream = createTopology("testNoResults");
    @SuppressWarnings("unchecked") StreamsContext<BigInteger> ctx = (StreamsContext<BigInteger>) StreamsContextFactory.getStreamsContext("STREAMING_ANALYTICS_SERVICE");
    Map<String, Object> config = new HashMap<>();
    BigInteger jobId = ctx.submit(stream.topology(), config).get();
    cancel(jobId);
    assertFalse(config.containsKey(ResultProperties.JOB_SUBMISSION));
}
Also used : HashMap(java.util.HashMap) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) BigInteger(java.math.BigInteger) JsonObject(com.google.gson.JsonObject) StreamingAnalyticsServiceTest(com.ibm.streamsx.rest.test.StreamingAnalyticsServiceTest) Test(org.junit.Test)

Example 20 with StreamsContext

use of com.ibm.streamsx.topology.context.StreamsContext in project streamsx.topology by IBMStreams.

the class ServiceSubmissionAPITest method testResults.

@Test
public void testResults() throws Exception {
    TStream<String> stream = createTopology("testResults");
    @SuppressWarnings("unchecked") StreamsContext<BigInteger> ctx = (StreamsContext<BigInteger>) StreamsContextFactory.getStreamsContext("STREAMING_ANALYTICS_SERVICE");
    Map<String, Object> config = new HashMap<>();
    config.put(ResultProperties.JOB_SUBMISSION, false);
    BigInteger jobId = ctx.submit(stream.topology(), config).get();
    cancel(jobId);
    assertTrue(config.containsKey(ResultProperties.JOB_SUBMISSION));
    Object r = config.get(ResultProperties.JOB_SUBMISSION);
    assertTrue(r.getClass().getName(), r instanceof JsonObject);
    JsonObject sr = (JsonObject) r;
    assertTrue(sr.has(SubmissionResultsKeys.CONSOLE_APPLICATION_URL));
    assertTrue(sr.has(SubmissionResultsKeys.CONSOLE_APPLICATION_JOB_URL));
}
Also used : HashMap(java.util.HashMap) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) BigInteger(java.math.BigInteger) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) StreamingAnalyticsServiceTest(com.ibm.streamsx.rest.test.StreamingAnalyticsServiceTest) Test(org.junit.Test)

Aggregations

StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)22 Topology (com.ibm.streamsx.topology.Topology)18 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 Constants (com.ibm.streamsx.kafka.test.utils.Constants)13 TStream (com.ibm.streamsx.topology.TStream)13 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)13 StreamsContextFactory (com.ibm.streamsx.topology.context.StreamsContextFactory)13 SPL (com.ibm.streamsx.topology.spl.SPL)13 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)13 SPLStreams (com.ibm.streamsx.topology.spl.SPLStreams)13 Condition (com.ibm.streamsx.topology.tester.Condition)13 Tester (com.ibm.streamsx.topology.tester.Tester)13 List (java.util.List)13 Map (java.util.Map)13 TimeUnit (java.util.concurrent.TimeUnit)13 Assert (org.junit.Assert)13 Delay (com.ibm.streamsx.kafka.test.utils.Delay)12 KafkaSPLStreamsUtils (com.ibm.streamsx.kafka.test.utils.KafkaSPLStreamsUtils)12 BigInteger (java.math.BigInteger)7