use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_projectionFunctionProvided_thenAppliedToReadRecords.
@Test
public void when_projectionFunctionProvided_thenAppliedToReadRecords() throws Exception {
int messageCount = 20;
JetInstance[] instances = new JetInstance[2];
Arrays.setAll(instances, i -> createJetMember());
Pipeline p = Pipeline.create();
p.drawFrom(KafkaSources.<Integer, String, String>kafka(properties, rec -> rec.value() + "-x", topic1Name)).drainTo(Sinks.list("sink"));
Job job = instances[0].newJob(p);
sleepAtLeastSeconds(3);
for (int i = 0; i < messageCount; i++) {
produce(topic1Name, i, Integer.toString(i));
}
IList<String> list = instances[0].getList("sink");
assertTrueEventually(() -> {
assertEquals(messageCount, list.size());
for (int i = 0; i < messageCount; i++) {
String value = Integer.toString(i) + "-x";
assertTrue("missing entry: " + value, list.contains(value));
}
}, 5);
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class Processors_globalAggregationIntegrationTest method runTest.
private void runTest(List<Long> sourceItems, Long expectedOutput) throws Exception {
JetInstance instance = createJetMember();
AggregateOperation1<Long, ?, Long> summingOp = summingLong((Long l) -> l);
DAG dag = new DAG();
Vertex source = dag.newVertex("source", () -> new ListSource(sourceItems)).localParallelism(1);
Vertex sink = dag.newVertex("sink", writeListP("sink"));
if (singleStageProcessor) {
Vertex aggregate = dag.newVertex("aggregate", Processors.aggregateP(summingOp)).localParallelism(1);
dag.edge(between(source, aggregate).distributed().allToOne()).edge(between(aggregate, sink).isolated());
} else {
Vertex accumulate = dag.newVertex("accumulate", Processors.accumulateP(summingOp));
Vertex combine = dag.newVertex("combine", combineP(summingOp)).localParallelism(1);
dag.edge(between(source, accumulate)).edge(between(accumulate, combine).distributed().allToOne()).edge(between(combine, sink).isolated());
}
instance.newJob(dag).join();
IList<Long> sinkList = instance.getList("sink");
assertEquals(singletonList(expectedOutput), new ArrayList<>(sinkList));
// wait a little more and make sure, that there are no more frames
Thread.sleep(1000);
assertEquals(singletonList(expectedOutput), new ArrayList<>(sinkList));
assertEquals(expectedOutput, sinkList.get(0));
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.
the class S8 method s6.
static void s6() {
// tag::s6[]
JetInstance jet = Jet.newJetInstance();
Jet.newJetInstance();
int upperBound = 10;
DAG dag = new DAG();
// rest of the code same as above
// end::s6[]
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.
the class HelloWorld method main.
public static void main(String[] args) {
// Create the specification of the computation pipeline. Note
// it's a pure POJO: no instance of Jet needed to create it.
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<String>list("text")).flatMap(word -> traverseArray(word.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
// Start Jet, populate the input list
JetInstance jet = Jet.newJetInstance();
try {
List<String> text = jet.getList("text");
text.add("hello world hello hello world");
text.add("world world hello world");
// Perform the computation
jet.newJob(p).join();
// Check the results
Map<String, Long> counts = jet.getMap("counts");
System.out.println("Count of hello: " + counts.get("hello"));
System.out.println("Count of world: " + counts.get("world"));
} finally {
Jet.shutdownAll();
}
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.
the class ImdgConnectors method s14.
static void s14() {
JetInstance jet = Jet.newJetInstance();
// tag::s14[]
IList<Integer> inputList = jet.getList("inputList");
for (int i = 0; i < 10; i++) {
inputList.add(i);
}
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<Integer>list("inputList")).map(i -> "item" + i).drainTo(Sinks.list("resultList"));
jet.newJob(p).join();
IList<String> resultList = jet.getList("resultList");
System.out.println("Results: " + new ArrayList<>(resultList));
// end::s14[]
}
Aggregations