Search in sources :

Example 11 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class Hz3SourcesTest method when_readFromInstanceDown_then_shouldThrowJetException.

@Test
public void when_readFromInstanceDown_then_shouldThrowJetException() {
    HazelcastInstance hz = createHazelcastInstance();
    Pipeline p = Pipeline.create();
    BatchSource<Map.Entry<Integer, String>> source = Hz3Sources.remoteMap("test-map", HZ3_DOWN_CLIENT_CONFIG);
    p.readFrom(source).map(Map.Entry::getValue).writeTo(Sinks.list("test-result"));
    JobConfig config = getJobConfig(source.name());
    Job job = hz.getJet().newJob(p, config);
    assertThatThrownBy(() -> job.join()).hasStackTraceContaining(JetException.class.getName()).hasStackTraceContaining("Unable to connect to any cluster");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Job(com.hazelcast.jet.Job) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 12 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class Hz3SourcesTest method readFromMapManyItems.

@Test
public void readFromMapManyItems() {
    IMap<Integer, String> map = hz3.getMap("test-map");
    Map<Integer, String> items = new HashMap<>();
    for (int i = 0; i < 10_000; i++) {
        items.put(i, "item " + i);
    }
    map.putAll(items);
    HazelcastInstance hz = createHazelcastInstance();
    Pipeline p = Pipeline.create();
    BatchSource<Map.Entry<Integer, String>> source = Hz3Sources.remoteMap("test-map", HZ3_CLIENT_CONFIG);
    p.readFrom(source).writeTo(Sinks.map("test-result"));
    JobConfig config = getJobConfig(source.name());
    Job job = hz.getJet().newJob(p, config);
    job.join();
    IMap<Integer, String> result = hz.getMap("test-result");
    assertThat(result.entrySet()).isEqualTo(items.entrySet());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 13 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class Hz3SourcesTest method readFromEmptyMap.

@Test
public void readFromEmptyMap() {
    // make sure the map exists
    hz3.getMap("test-map");
    HazelcastInstance hz = createHazelcastInstance();
    Pipeline p = Pipeline.create();
    BatchSource<Map.Entry<Integer, String>> source = Hz3Sources.remoteMap("test-map", HZ3_CLIENT_CONFIG);
    p.readFrom(source).map(Map.Entry::getValue).writeTo(Sinks.list("test-result"));
    JobConfig config = getJobConfig(source.name());
    Job job = hz.getJet().newJob(p, config);
    job.join();
    IList<String> result = hz.getList("test-result");
    assertThat(result).isEmpty();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Job(com.hazelcast.jet.Job) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 14 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class PlanExecutor method execute.

SqlResult execute(SelectPlan plan, QueryId queryId, List<Object> arguments, long timeout) {
    List<Object> args = prepareArguments(plan.getParameterMetadata(), arguments);
    JobConfig jobConfig = new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, args).setArgument(KEY_SQL_QUERY_TEXT, plan.getQuery()).setArgument(KEY_SQL_UNBOUNDED, plan.isStreaming()).setTimeoutMillis(timeout);
    QueryResultProducerImpl queryResultProducer = new QueryResultProducerImpl(!plan.isStreaming());
    AbstractJetInstance<?> jet = (AbstractJetInstance<?>) hazelcastInstance.getJet();
    long jobId = jet.newJobId();
    Object oldValue = resultRegistry.store(jobId, queryResultProducer);
    assert oldValue == null : oldValue;
    try {
        Job job = jet.newLightJob(jobId, plan.getDag(), jobConfig);
        job.getFuture().whenComplete((r, t) -> {
            // make sure the queryResultProducer is cleaned up after the job completes. This normally
            // takes effect when the job fails before the QRP is removed by the RootResultConsumerSink
            resultRegistry.remove(jobId);
            if (t != null) {
                int errorCode = findQueryExceptionCode(t);
                String errorMessage = findQueryExceptionMessage(t);
                queryResultProducer.onError(QueryException.error(errorCode, "The Jet SQL job failed: " + errorMessage, t));
            }
        });
    } catch (Throwable e) {
        resultRegistry.remove(jobId);
        throw e;
    }
    return new SqlResultImpl(queryId, queryResultProducer, plan.getRowMetadata(), plan.isStreaming());
}
Also used : AbstractJetInstance(com.hazelcast.jet.impl.AbstractJetInstance) Job(com.hazelcast.jet.Job) UpdateSqlResultImpl(com.hazelcast.sql.impl.UpdateSqlResultImpl) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 15 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class PostgresCdcIntegrationTest method cdcMapSink.

@Test
@Category(NightlyTest.class)
public void cdcMapSink() throws Exception {
    // given
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(source("customers")).withNativeTimestamps(0).writeTo(CdcSinks.map("cache", r -> r.key().toMap().get("id"), r -> r.value().toObject(Customer.class).toString()));
    // when
    HazelcastInstance hz = createHazelcastInstances(2)[0];
    JobConfig jobConfig = new JobConfig().setProcessingGuarantee(ProcessingGuarantee.AT_LEAST_ONCE);
    Job job = hz.getJet().newJob(pipeline, jobConfig);
    JetTestSupport.assertJobStatusEventually(job, JobStatus.RUNNING);
    // then
    assertEqualsEventually(() -> mapResultsToSortedList(hz.getMap("cache")), Arrays.asList("1001:Customer {id=1001, firstName=Sally, lastName=Thomas, email=sally.thomas@acme.com}", "1002:Customer {id=1002, firstName=George, lastName=Bailey, email=gbailey@foobar.com}", "1003:Customer {id=1003, firstName=Edward, lastName=Walker, email=ed@walker.com}", "1004:Customer {id=1004, firstName=Anne, lastName=Kretchmar, email=annek@noanswer.org}"));
    // when
    job.restart();
    JetTestSupport.assertJobStatusEventually(job, JobStatus.RUNNING);
    executeBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004", "INSERT INTO customers VALUES (1005, 'Jason', 'Bourne', 'jason@bourne.org')");
    // then
    assertEqualsEventually(() -> mapResultsToSortedList(hz.getMap("cache")), Arrays.asList("1001:Customer {id=1001, firstName=Sally, lastName=Thomas, email=sally.thomas@acme.com}", "1002:Customer {id=1002, firstName=George, lastName=Bailey, email=gbailey@foobar.com}", "1003:Customer {id=1003, firstName=Edward, lastName=Walker, email=ed@walker.com}", "1004:Customer {id=1004, firstName=Anne Marie, lastName=Kretchmar, email=annek@noanswer.org}", "1005:Customer {id=1005, firstName=Jason, lastName=Bourne, email=jason@bourne.org}"));
    // when
    executeBatch("DELETE FROM customers WHERE id=1005");
    // then
    assertEqualsEventually(() -> mapResultsToSortedList(hz.getMap("cache")), Arrays.asList("1001:Customer {id=1001, firstName=Sally, lastName=Thomas, email=sally.thomas@acme.com}", "1002:Customer {id=1002, firstName=George, lastName=Bailey, email=gbailey@foobar.com}", "1003:Customer {id=1003, firstName=Edward, lastName=Walker, email=ed@walker.com}", "1004:Customer {id=1004, firstName=Anne Marie, lastName=Kretchmar, email=annek@noanswer.org}"));
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) Connection(java.sql.Connection) Util.uncheckRun(com.hazelcast.jet.impl.util.Util.uncheckRun) QuickTest(com.hazelcast.test.annotation.QuickTest) Date(java.util.Date) JobProxy(com.hazelcast.jet.impl.JobProxy) StreamSource(com.hazelcast.jet.pipeline.StreamSource) CdcSinks(com.hazelcast.jet.cdc.CdcSinks) ParsingException(com.hazelcast.jet.cdc.ParsingException) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Future(java.util.concurrent.Future) Operation(com.hazelcast.jet.cdc.Operation) ResultSet(java.sql.ResultSet) Util.entry(com.hazelcast.jet.Util.entry) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assert.fail(org.junit.Assert.fail) ChangeRecord(com.hazelcast.jet.cdc.ChangeRecord) JobStatus(com.hazelcast.jet.core.JobStatus) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) RecordPart(com.hazelcast.jet.cdc.RecordPart) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) PreparedStatement(java.sql.PreparedStatement) String.format(java.lang.String.format) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) List(java.util.List) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

JobConfig (com.hazelcast.jet.config.JobConfig)254 Test (org.junit.Test)196 Job (com.hazelcast.jet.Job)160 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)111 QuickTest (com.hazelcast.test.annotation.QuickTest)109 Pipeline (com.hazelcast.jet.pipeline.Pipeline)70 HazelcastInstance (com.hazelcast.core.HazelcastInstance)64 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)46 Category (org.junit.experimental.categories.Category)45 Assert.assertEquals (org.junit.Assert.assertEquals)43 DAG (com.hazelcast.jet.core.DAG)41 JobRepository (com.hazelcast.jet.impl.JobRepository)40 List (java.util.List)36 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)35 Config (com.hazelcast.config.Config)33 Assert.assertTrue (org.junit.Assert.assertTrue)32 ArrayList (java.util.ArrayList)31 Sinks (com.hazelcast.jet.pipeline.Sinks)28 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)27 RunWith (org.junit.runner.RunWith)27