Search in sources :

Example 6 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast-jet by hazelcast.

the class WriteLoggerPTest method test.

@Test
public void test() {
    // Given
    Processor p = supplierFrom(writeLoggerP()).get();
    TestInbox inbox = new TestInbox();
    Outbox outbox = mock(Outbox.class);
    ILogger logger = mock(ILogger.class);
    p.init(outbox, new TestProcessorContext().setLogger(logger));
    // When
    inbox.add(1);
    p.process(0, inbox);
    Watermark wm = new Watermark(2);
    p.tryProcessWatermark(wm);
    // Then
    verifyZeroInteractions(outbox);
    verify(logger).info("1");
    verify(logger).fine(wm.toString());
    verifyZeroInteractions(logger);
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) Outbox(com.hazelcast.jet.core.Outbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ILogger(com.hazelcast.logging.ILogger) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Example 7 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast-jet by hazelcast.

the class WriteSocketTest method unitTest.

@Test
public void unitTest() throws Exception {
    AtomicInteger counter = new AtomicInteger();
    ServerSocket serverSocket = new ServerSocket(0);
    new Thread(() -> uncheckRun(() -> {
        Socket socket = serverSocket.accept();
        serverSocket.close();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
            while (reader.readLine() != null) {
                counter.incrementAndGet();
            }
        }
    })).start();
    TestInbox inbox = new TestInbox();
    range(0, ITEM_COUNT).forEach(inbox::add);
    Processor p = supplierFrom(writeSocketP("localhost", serverSocket.getLocalPort(), Object::toString, UTF_8)).get();
    p.init(mock(Outbox.class), new TestProcessorContext());
    p.process(0, inbox);
    p.complete();
    assertTrueEventually(() -> assertTrue(counter.get() >= ITEM_COUNT));
    // wait a little to check, if the counter doesn't get too far
    Thread.sleep(500);
    assertEquals(ITEM_COUNT, counter.get());
}
Also used : Processor(com.hazelcast.jet.core.Processor) InputStreamReader(java.io.InputStreamReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestInbox(com.hazelcast.jet.core.test.TestInbox) BufferedReader(java.io.BufferedReader) Outbox(com.hazelcast.jet.core.Outbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 8 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.

the class JoinByEquiJoinProcessorSupplier method get.

@Nonnull
@Override
public Collection<? extends Processor> get(int count) {
    List<Processor> processors = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        PartitionIdSet partitions = this.partitions == null ? null : new PartitionIdSet(partitionCount, this.partitions);
        QueryPath[] rightPaths = rightRowProjectorSupplier.paths();
        KvRowProjector rightProjector = rightRowProjectorSupplier.get(evalContext, extractors);
        Processor processor = new TransformP<JetSqlRow, JetSqlRow>(joinFn(joinInfo, map, partitions, rightPaths, rightProjector, evalContext)) {

            @Override
            public boolean isCooperative() {
                return false;
            }
        };
        processors.add(processor);
    }
    return processors;
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) KvRowProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector) Processor(com.hazelcast.jet.core.Processor) TransformP(com.hazelcast.jet.impl.processor.TransformP) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 9 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.

the class JoinScanProcessorSupplier method get.

@Nonnull
@Override
public Collection<? extends Processor> get(int count) {
    List<Processor> processors = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        Processor processor = new TransformBatchedP<JetSqlRow, JetSqlRow>(joinFn(joinInfo, map, rightRowProjectorSupplier, evalContext)) {

            @Override
            public boolean isCooperative() {
                return false;
            }
        };
        processors.add(processor);
    }
    return processors;
}
Also used : Processor(com.hazelcast.jet.core.Processor) TransformBatchedP(com.hazelcast.jet.impl.processor.TransformBatchedP) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 10 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast by hazelcast.

the class RowProjectorProcessorSupplier method get.

@Nonnull
@Override
public Collection<? extends Processor> get(int count) {
    List<Processor> processors = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        KvRowProjector projector = projectorSupplier.get(evalContext, extractors);
        Processor processor = new StreamKafkaP<>(properties, singletonList(topic), record -> projector.project(record.key(), record.value()), eventTimePolicy);
        processors.add(processor);
    }
    return processors;
}
Also used : KvRowProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector) Processor(com.hazelcast.jet.core.Processor) StreamKafkaP(com.hazelcast.jet.kafka.impl.StreamKafkaP) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Aggregations

Processor (com.hazelcast.jet.core.Processor)49 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)22 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)17 QuickTest (com.hazelcast.test.annotation.QuickTest)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)14 List (java.util.List)13 Nonnull (javax.annotation.Nonnull)13 TestInbox (com.hazelcast.jet.core.test.TestInbox)11 Watermark (com.hazelcast.jet.core.Watermark)10 Collection (java.util.Collection)9 Collections.singletonList (java.util.Collections.singletonList)9 Entry (java.util.Map.Entry)9 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)8 FunctionEx (com.hazelcast.function.FunctionEx)7 Job (com.hazelcast.jet.Job)7 JobConfig (com.hazelcast.jet.config.JobConfig)7 DAG (com.hazelcast.jet.core.DAG)7 Arrays (java.util.Arrays)6