Search in sources :

Example 51 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline in project hazelcast by hazelcast.

the class WriteKafkaPTest method when_recordLingerEnabled_then_sentOnCompletion.

@Test
public void when_recordLingerEnabled_then_sentOnCompletion() {
    // When
    // 1 hour
    properties.setProperty("linger.ms", "3600000");
    // Given
    Pipeline p = Pipeline.create();
    p.readFrom(Sources.<Entry<String, String>>batchFromProcessor("source", ProcessorMetaSupplier.of(ProcessorWithEntryAndLatch::new))).writeTo(KafkaSinks.kafka(properties, topic));
    Job job = instance().getJet().newJob(p);
    // the event should not appear in the topic due to linger.ms
    try (KafkaConsumer<Integer, String> consumer = kafkaTestSupport.createConsumer(topic)) {
        assertTrueAllTheTime(() -> assertEquals(0, consumer.poll(Duration.ofMillis(100)).count()), 2);
    }
    // Then
    ProcessorWithEntryAndLatch.isDone = true;
    job.join();
    logger.info("Job finished");
    kafkaTestSupport.assertTopicContentsEventually(topic, singletonMap(0, "v"), false);
}
Also used : Entry(java.util.Map.Entry) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline 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 53 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline 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 54 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline 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 55 with Pipeline

use of com.hazelcast.jet.pipeline.Pipeline in project hazelcast by hazelcast.

the class FileNotFoundReadHadoopPTest method shouldNotFailForNonExistingPath.

@Test
public void shouldNotFailForNonExistingPath() throws IOException {
    paths.add(new org.apache.hadoop.fs.Path(directory + File.separator + "not-exists"));
    Pipeline p = Pipeline.create();
    p.readFrom(HadoopSources.inputFormat(configuration(true), (k, v) -> v.toString())).setLocalParallelism(1).writeTo(Sinks.logger());
    // Should just pass, no need to check results as there are none
    instance().getJet().newJob(p).join();
}
Also used : TextInputFormat(org.apache.hadoop.mapred.TextInputFormat) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) JetException(com.hazelcast.jet.JetException) HashSet(java.util.HashSet) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) HadoopSources(com.hazelcast.jet.hadoop.HadoopSources) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) IOUtil(com.hazelcast.internal.nio.IOUtil) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Files(java.nio.file.Files) Collection(java.util.Collection) Sinks(com.hazelcast.jet.pipeline.Sinks) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) JobConf(org.apache.hadoop.mapred.JobConf) Job(org.apache.hadoop.mapreduce.Job) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)379 Test (org.junit.Test)300 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)142 QuickTest (com.hazelcast.test.annotation.QuickTest)142 Job (com.hazelcast.jet.Job)125 Sinks (com.hazelcast.jet.pipeline.Sinks)107 Category (org.junit.experimental.categories.Category)100 HazelcastInstance (com.hazelcast.core.HazelcastInstance)94 JobConfig (com.hazelcast.jet.config.JobConfig)86 Assert.assertEquals (org.junit.Assert.assertEquals)73 List (java.util.List)72 NightlyTest (com.hazelcast.test.annotation.NightlyTest)65 Before (org.junit.Before)64 Entry (java.util.Map.Entry)61 TestSources (com.hazelcast.jet.pipeline.test.TestSources)58 Assert.assertTrue (org.junit.Assert.assertTrue)50 Sources (com.hazelcast.jet.pipeline.Sources)49 IOException (java.io.IOException)48 BeforeClass (org.junit.BeforeClass)48 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)42