Search in sources :

Example 41 with DAG

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

the class StreamKafkaP_StandaloneKafkaTest method when_cancelledAfterBrokerDown_then_cancelsPromptly.

@Test
public void when_cancelledAfterBrokerDown_then_cancelsPromptly() throws IOException {
    KafkaTestSupport kafkaTestSupport = new KafkaTestSupport();
    kafkaTestSupport.createKafkaCluster();
    kafkaTestSupport.createTopic("topic", 1);
    DAG dag = new DAG();
    dag.newVertex("src", KafkaProcessors.streamKafkaP(getProperties(kafkaTestSupport.getBrokerConnectionString()), FunctionEx.identity(), EventTimePolicy.noEventTime(), "topic")).localParallelism(1);
    Job job = createHazelcastInstance().getJet().newJob(dag);
    assertJobStatusEventually(job, RUNNING);
    sleepSeconds(1);
    kafkaTestSupport.shutdownKafkaCluster();
    sleepSeconds(3);
    long start = System.nanoTime();
    job.cancel();
    try {
        job.join();
    } catch (CancellationException ignored) {
    }
    // There was an issue claimed that when the broker was down, job did not cancel.
    // Let's assert the cancellation didn't take too long.
    long durationSeconds = NANOSECONDS.toSeconds(System.nanoTime() - start);
    assertTrue("durationSeconds=" + durationSeconds, durationSeconds < 10);
    logger.info("Job cancelled in " + durationSeconds + " seconds");
}
Also used : CancellationException(java.util.concurrent.CancellationException) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with DAG

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

the class ShowStatementTest method createJobInJava.

private void createJobInJava(String jobName) {
    DAG dag = new DAG();
    dag.newVertex("v", () -> new TestProcessors.MockP().streaming());
    instance().getJet().newJob(dag, new JobConfig().setName(jobName));
}
Also used : DAG(com.hazelcast.jet.core.DAG) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 43 with DAG

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

the class TestAbstractSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table_, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    TestTable table = (TestTable) table_;
    List<Object[]> rows = table.rows;
    boolean streaming = table.streaming;
    FunctionEx<Context, TestDataGenerator> createContextFn = ctx -> {
        ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
        EventTimePolicy<JetSqlRow> eventTimePolicy = eventTimePolicyProvider == null ? EventTimePolicy.noEventTime() : eventTimePolicyProvider.apply(evalContext);
        return new TestDataGenerator(rows, predicate, projection, evalContext, eventTimePolicy, streaming);
    };
    ProcessorMetaSupplier pms = createProcessorSupplier(createContextFn);
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Context(com.hazelcast.jet.core.Processor.Context) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) String.join(java.lang.String.join) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTimeMapper(com.hazelcast.jet.core.EventTimeMapper) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) Traversers(com.hazelcast.jet.Traversers) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Collectors.joining(java.util.stream.Collectors.joining) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataTypeUtils.resolveTypeForTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeUtils.resolveTypeForTypeFamily) Context(com.hazelcast.jet.core.Processor.Context) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 44 with DAG

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

the class TestAllTypesSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    if (eventTimePolicyProvider != null) {
        throw QueryException.error("Ordering function are not supported for " + TYPE_NAME + " mappings");
    }
    BatchSource<JetSqlRow> source = SourceBuilder.batch("batch", ExpressionEvalContext::from).<JetSqlRow>fillBufferFn((ctx, buf) -> {
        JetSqlRow row = ExpressionUtil.evaluate(predicate, projection, VALUES, ctx);
        if (row != null) {
            buf.add(row);
        }
        buf.close();
    }).build();
    ProcessorMetaSupplier pms = ((BatchSourceTransform<JetSqlRow>) source).metaSupplier;
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) LocalDateTime(java.time.LocalDateTime) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BigDecimal(java.math.BigDecimal) TEST_SS(com.hazelcast.jet.sql.SqlTestSupport.TEST_SS) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) LocalTime(java.time.LocalTime) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ImmutableMap(com.google.common.collect.ImmutableMap) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 45 with DAG

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

the class WriteFilePTest method test_rollByDate.

@Test
public void test_rollByDate() {
    int numItems = 10;
    DAG dag = new DAG();
    Vertex src = dag.newVertex("src", () -> new SlowSourceP(semaphore, numItems)).localParallelism(1);
    @SuppressWarnings("Convert2MethodRef") Vertex sink = dag.newVertex("sink", WriteFileP.metaSupplier(directory.toString(), Objects::toString, "utf-8", "SSS", DISABLE_ROLLING, true, (LongSupplier & Serializable) () -> clock.get()));
    dag.edge(between(src, sink));
    Job job = instance().getJet().newJob(dag);
    for (int i = 0; i < numItems; i++) {
        // When
        semaphore.release();
        String stringValue = i + System.lineSeparator();
        // Then
        Path file = directory.resolve(String.format("%03d-0", i));
        assertTrueEventually(() -> assertTrue("file not found: " + file, Files.exists(file)), 5);
        assertTrueEventually(() -> assertEquals(stringValue, new String(Files.readAllBytes(file), StandardCharsets.UTF_8)), 5);
        clock.incrementAndGet();
    }
    job.join();
}
Also used : Path(java.nio.file.Path) Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DAG (com.hazelcast.jet.core.DAG)211 Test (org.junit.Test)159 Vertex (com.hazelcast.jet.core.Vertex)127 QuickTest (com.hazelcast.test.annotation.QuickTest)100 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)91 Job (com.hazelcast.jet.Job)64 Entry (java.util.Map.Entry)51 List (java.util.List)38 Assert.assertEquals (org.junit.Assert.assertEquals)37 Map (java.util.Map)36 JobConfig (com.hazelcast.jet.config.JobConfig)35 Assert.assertTrue (org.junit.Assert.assertTrue)31 Edge (com.hazelcast.jet.core.Edge)29 IntStream (java.util.stream.IntStream)29 Category (org.junit.experimental.categories.Category)28 Collectors.toList (java.util.stream.Collectors.toList)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 FunctionEx (com.hazelcast.function.FunctionEx)23 ArrayList (java.util.ArrayList)22 Nonnull (javax.annotation.Nonnull)21