Search in sources :

Example 46 with Topology

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

the class ConsistentRegionTest method testConsistentOperatorDriven.

@Test
public void testConsistentOperatorDriven() throws Exception {
    Topology topology = new Topology("testConsistentOperatorDriven");
    final int N = 2000;
    StreamSchema schema = Type.Factory.getStreamSchema("tuple<uint64 id>");
    Map<String, Object> params = new HashMap<>();
    params.put("iterations", N);
    params.put("period", 0.01);
    params.put("triggerCount", SPL.createValue(37, Type.MetaType.UINT32));
    SPLStream b = SPL.invokeSource(topology, "spl.utility::Beacon", params, schema);
    ConsistentRegionConfig config = ConsistentRegionConfig.operatorDriven();
    assertSame(b, b.setConsistent(config));
    // Create a mini-flow
    b = b.filter(t -> true);
    Condition<Void> resets = topology.getTester().resetConsistentRegions(5);
    assertNotNull(resets);
    Condition<Long> exact = topology.getTester().tupleCount(b, N);
    complete(topology.getTester(), exact, 80, TimeUnit.SECONDS);
}
Also used : ConsistentRegionConfig.periodic(com.ibm.streamsx.topology.consistent.ConsistentRegionConfig.periodic) Assert.assertNotNull(org.junit.Assert.assertNotNull) ConsistentRegionConfig(com.ibm.streamsx.topology.consistent.ConsistentRegionConfig) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) HashMap(java.util.HashMap) Test(org.junit.Test) StreamSchema(com.ibm.streams.operator.StreamSchema) Assert.assertSame(org.junit.Assert.assertSame) TimeUnit(java.util.concurrent.TimeUnit) Topology(com.ibm.streamsx.topology.Topology) Map(java.util.Map) SPL(com.ibm.streamsx.topology.spl.SPL) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Before(org.junit.Before) Type(com.ibm.streams.operator.Type) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) StreamSchema(com.ibm.streams.operator.StreamSchema) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) ConsistentRegionConfig(com.ibm.streamsx.topology.consistent.ConsistentRegionConfig) Test(org.junit.Test)

Example 47 with Topology

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

the class ConsistentRegionTest method testConsistentPeriodic.

@Test
public void testConsistentPeriodic() throws Exception {
    Topology topology = new Topology("testConsistentPeriodic");
    final int N = 2000;
    StreamSchema schema = Type.Factory.getStreamSchema("tuple<uint64 id>");
    Map<String, Object> params = new HashMap<>();
    params.put("iterations", N);
    params.put("period", 0.01);
    SPLStream b = SPL.invokeSource(topology, "spl.utility::Beacon", params, schema);
    ConsistentRegionConfig config = periodic(2);
    assertSame(b, b.setConsistent(config));
    // Create a mini-flow
    b = b.filter(t -> true);
    Condition<Long> exact = topology.getTester().tupleCount(b, N);
    Condition<Void> resets = topology.getTester().resetConsistentRegions(null);
    assertNotNull(resets);
    complete(topology.getTester(), exact, 80, TimeUnit.SECONDS);
}
Also used : ConsistentRegionConfig.periodic(com.ibm.streamsx.topology.consistent.ConsistentRegionConfig.periodic) Assert.assertNotNull(org.junit.Assert.assertNotNull) ConsistentRegionConfig(com.ibm.streamsx.topology.consistent.ConsistentRegionConfig) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) HashMap(java.util.HashMap) Test(org.junit.Test) StreamSchema(com.ibm.streams.operator.StreamSchema) Assert.assertSame(org.junit.Assert.assertSame) TimeUnit(java.util.concurrent.TimeUnit) Topology(com.ibm.streamsx.topology.Topology) Map(java.util.Map) SPL(com.ibm.streamsx.topology.spl.SPL) Condition(com.ibm.streamsx.topology.tester.Condition) Assume.assumeTrue(org.junit.Assume.assumeTrue) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Before(org.junit.Before) Type(com.ibm.streams.operator.Type) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) StreamSchema(com.ibm.streams.operator.StreamSchema) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) ConsistentRegionConfig(com.ibm.streamsx.topology.consistent.ConsistentRegionConfig) Test(org.junit.Test)

Example 48 with Topology

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

the class JobConfigSubmissionTest method testItDirect.

private void testItDirect(String topologyName, JobConfig config, String... expected) throws Exception {
    // Uses a Java primitive operator directly.
    assumeTrue(hasStreamsInstall());
    // JobConfig only apply to DISTRIBUTED submit
    assumeTrue(isDistributedOrService());
    config.addToConfig(getConfig());
    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 : 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 49 with Topology

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

the class PublishSubscribeSPLTest method testSPLPublishAllowFilterWithSubscribe.

/**
 * Test that with publish allow filter set to false
 * a subscriber without a filter gets the full set of data.
 */
@Test
public void testSPLPublishAllowFilterWithSubscribe() throws Exception {
    final Topology t = new Topology();
    SPLStream source = SPLStreamsTest.testTupleStream(t);
    final String topic = uniqueTopic("SPLPublishAllowFilterWithSubscribe");
    source = addStartupDelay(source);
    source.publish(topic, true);
    SPLStream sub = SPLStreams.subscribe(t, topic, source.getSchema());
    TStream<String> subscribe = sub.transform(new GetTupleId());
    completeAndValidate(subscribe, 20, "SPL:0", "SPL:1", "SPL:2", "SPL:3");
}
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) SPLStreamsTest(com.ibm.streamsx.topology.test.spl.SPLStreamsTest)

Example 50 with Topology

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

the class PublishSubscribeSPLTest method _testSPLPublishFilteredSubscribe.

private void _testSPLPublishFilteredSubscribe(String topic, boolean allowFilters, boolean useParams) throws Exception {
    final Topology t = new Topology();
    topic = uniqueTopic(topic);
    SPL.addToolkit(t, new File(getTestRoot(), "spl/testtk"));
    SPLStream source = SPLStreamsTest.testTupleStream(t);
    source = addStartupDelay(source);
    Supplier<String> pubParam = useParams ? t.createSubmissionParameter("PFSPL", String.class) : null;
    if (useParams)
        source.publish(pubParam, allowFilters);
    else
        source.publish(topic, allowFilters);
    // Filter on the vi attribute, passing the value 321.
    Map<String, Object> params = new HashMap<>();
    params.put("topic", topic);
    params.put("value", 43675232L);
    SPLStream sub = SPL.invokeSource(t, "testspl::Int64SubscribeFilter", params, source.getSchema());
    TStream<String> subscribe = sub.transform(new GetTupleId());
    if (useParams) {
        JobConfig jco = new JobConfig();
        jco.addSubmissionParameter("PFSPL", topic);
        jco.addToConfig(getConfig());
    }
    completeAndValidate(subscribe, 20, "SPL:1");
}
Also used : HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) File(java.io.File) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)372 TestTopology (com.ibm.streamsx.topology.test.TestTopology)315 Test (org.junit.Test)301 List (java.util.List)116 Tester (com.ibm.streamsx.topology.tester.Tester)115 ArrayList (java.util.ArrayList)70 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)68 HashMap (java.util.HashMap)49 TStream (com.ibm.streamsx.topology.TStream)42 Condition (com.ibm.streamsx.topology.tester.Condition)28 File (java.io.File)27 TimeUnit (java.util.concurrent.TimeUnit)27 StreamSchema (com.ibm.streams.operator.StreamSchema)26 Random (java.util.Random)26 JSONObject (com.ibm.json.java.JSONObject)23 HashSet (java.util.HashSet)23 RString (com.ibm.streams.operator.types.RString)21 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)21 Message (com.ibm.streamsx.topology.tuple.Message)20 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)20