use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.
the class BeaconTest method testBeaconTuples.
@Test
public void testBeaconTuples() throws Exception {
Topology topology = new Topology("testFixedCount");
final int count = new Random().nextInt(1000) + 37;
TStream<BeaconTuple> beacon = BeaconStreams.beacon(topology, count);
TStream<JSONObject> json = JSONStreams.toJSON(beacon);
TStream<String> strings = JSONStreams.serialize(json);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(strings, count);
@SuppressWarnings("serial") Condition<String> contents = tester.stringTupleTester(strings, new Predicate<String>() {
private transient BeaconTuple lastTuple;
@Override
public boolean test(String tuple) {
JSONObject json;
try {
json = (JSONObject) JSON.parse(tuple);
} catch (NullPointerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
BeaconTuple bt = new BeaconTuple((Long) json.get("sequence"), (Long) json.get("time"));
boolean ok;
if (lastTuple == null) {
ok = bt.getSequence() == 0;
} else {
ok = lastTuple.compareTo(bt) < 0 && lastTuple.getTime() <= bt.getTime() && lastTuple.getSequence() + 1 == bt.getSequence();
}
ok = ok && bt.getTime() != 0;
ok = ok && bt.getKey() == bt.getSequence();
lastTuple = bt;
return ok;
}
});
complete(tester, expectedCount, 20, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(contents.toString(), contents.valid());
}
use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.
the class SubscribeBeacon method main.
/**
* Submit this application which subscribes to a topic.
* @param args Command line arguments, accepts a single optional topic name.
* @throws Exception Error running the application
*/
public static void main(String[] args) throws Exception {
String topic = "/beacon";
String type = "DISTRIBUTED";
if (args.length >= 1)
topic = "/" + args[0];
if (args.length == 2)
type = args[1];
Topology topology = new Topology("SubscribeBeacon");
TStream<BeaconTuple> beacon = topology.subscribe(topic, BeaconTuple.class);
beacon.print();
StreamsContextFactory.getStreamsContext(type).submit(topology);
}
use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.
the class ParallelTest method testParallelNonPartitioned.
@Test
public void testParallelNonPartitioned() throws Exception {
checkUdpSupported();
Topology topology = newTopology("testParallel");
final int count = new Random().nextInt(1000) + 37;
TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
TStream<BeaconTuple> pb = fb.parallel(5);
TStream<Integer> is = pb.transform(randomHashProducer());
TStream<Integer> joined = is.endParallel();
TStream<String> numRegions = joined.transform(uniqueIdentifierMap(count));
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(numRegions, 1);
Condition<List<String>> regionCount = tester.stringContents(numRegions, "5");
complete(tester, allConditions(regionCount, expectedCount), 10, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(regionCount.valid());
}
use of com.ibm.streamsx.topology.tuple.BeaconTuple in project streamsx.topology by IBMStreams.
the class ParallelTest method testParallelWidthSupplier.
@Test
public void testParallelWidthSupplier() throws Exception {
checkUdpSupported();
Topology topology = newTopology("testParallelWidthValue");
final int count = new Random().nextInt(1000) + 37;
String submissionWidthName = "width";
final Integer submissionWidth = 5;
TStream<BeaconTuple> fb = BeaconStreams.beacon(topology, count);
TStream<BeaconTuple> pb = fb.parallel(() -> submissionWidth);
TStream<Integer> is = pb.transform(randomHashProducer());
TStream<Integer> joined = is.endParallel();
TStream<String> numRegions = joined.transform(uniqueIdentifierMap(count));
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(numRegions, 1);
Condition<List<String>> regionCount = tester.stringContents(numRegions, submissionWidth.toString());
complete(tester, allConditions(regionCount, expectedCount), 10, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(regionCount.valid());
}
Aggregations