Search in sources :

Example 56 with JobConfig

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

the class SourcesTest method remoteMapWithUnknownValueClass_whenQueryingIsNotNecessary.

@Test
public void remoteMapWithUnknownValueClass_whenQueryingIsNotNecessary() throws Exception {
    // Given
    URL jarResource = Thread.currentThread().getContextClassLoader().getResource("deployment/sample-pojo-1.0-car.jar");
    assertNotNull("jar not found", jarResource);
    ClassLoader cl = new URLClassLoader(new URL[] { jarResource });
    Class<?> personClz = cl.loadClass("com.sample.pojo.car.Car");
    Object person = personClz.getConstructor(String.class, String.class).newInstance("make", "model");
    IMap<String, Object> map = remoteHz.getMap(srcName);
    // the class of the value is unknown to the remote IMDG member, it will be only known to Jet
    map.put("key", person);
    // When
    BatchSource<Entry<String, Object>> source = Sources.remoteMap(srcName, clientConfig);
    // Then
    p.readFrom(source).map(en -> en.getValue().toString()).writeTo(sink);
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJar(jarResource);
    hz().getJet().newJob(p, jobConfig).join();
    List<Object> expected = singletonList(person.toString());
    List<Object> actual = new ArrayList<>(sinkList);
    assertEquals(expected, actual);
}
Also used : Socket(java.net.Socket) BeforeClass(org.junit.BeforeClass) Util.uncheckRun(com.hazelcast.jet.impl.util.Util.uncheckRun) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) URL(java.net.URL) HazelcastInstanceFactory(com.hazelcast.instance.impl.HazelcastInstanceFactory) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) TruePredicate.truePredicate(com.hazelcast.query.impl.predicates.TruePredicate.truePredicate) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ServerSocket(java.net.ServerSocket) URLClassLoader(java.net.URLClassLoader) Util.entry(com.hazelcast.jet.Util.entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) Projections(com.hazelcast.projection.Projections) JobStatus(com.hazelcast.jet.core.JobStatus) Job(com.hazelcast.jet.Job) PrintWriter(java.io.PrintWriter) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AfterClass(org.junit.AfterClass) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test) Projections.singleAttribute(com.hazelcast.projection.Projections.singleAttribute) Category(org.junit.experimental.categories.Category) File(java.io.File) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) ICache(com.hazelcast.cache.ICache) Entry(java.util.Map.Entry) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) ArrayList(java.util.ArrayList) URL(java.net.URL) JobConfig(com.hazelcast.jet.config.JobConfig) Entry(java.util.Map.Entry) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with JobConfig

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

the class SourcesTest method remoteCacheWithUnknownValueClass.

@Test
public void remoteCacheWithUnknownValueClass() throws Exception {
    // Given
    URL jarResource = Thread.currentThread().getContextClassLoader().getResource("deployment/sample-pojo-1.0-car.jar");
    assertNotNull("jar not found", jarResource);
    ClassLoader cl = new URLClassLoader(new URL[] { jarResource });
    Class<?> personClz = cl.loadClass("com.sample.pojo.car.Car");
    Object person = personClz.getConstructor(String.class, String.class).newInstance("make", "model");
    ICache<String, Object> cache = remoteHz.getCacheManager().getCache(srcName);
    // the class of the value is unknown to the remote IMDG member, it will be only known to Jet
    cache.put("key", person);
    // When
    BatchSource<Entry<String, Object>> source = Sources.remoteCache(srcName, clientConfig);
    // Then
    p.readFrom(source).map(en -> en.getValue().toString()).writeTo(sink);
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJar(jarResource);
    hz().getJet().newJob(p, jobConfig).join();
    List<Object> expected = singletonList(person.toString());
    List<Object> actual = new ArrayList<>(sinkList);
    assertEquals(expected, actual);
}
Also used : Socket(java.net.Socket) BeforeClass(org.junit.BeforeClass) Util.uncheckRun(com.hazelcast.jet.impl.util.Util.uncheckRun) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) URL(java.net.URL) HazelcastInstanceFactory(com.hazelcast.instance.impl.HazelcastInstanceFactory) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) TruePredicate.truePredicate(com.hazelcast.query.impl.predicates.TruePredicate.truePredicate) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ServerSocket(java.net.ServerSocket) URLClassLoader(java.net.URLClassLoader) Util.entry(com.hazelcast.jet.Util.entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) Projections(com.hazelcast.projection.Projections) JobStatus(com.hazelcast.jet.core.JobStatus) Job(com.hazelcast.jet.Job) PrintWriter(java.io.PrintWriter) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AfterClass(org.junit.AfterClass) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test) Projections.singleAttribute(com.hazelcast.projection.Projections.singleAttribute) Category(org.junit.experimental.categories.Category) File(java.io.File) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) ICache(com.hazelcast.cache.ICache) Entry(java.util.Map.Entry) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) ArrayList(java.util.ArrayList) URL(java.net.URL) JobConfig(com.hazelcast.jet.config.JobConfig) Entry(java.util.Map.Entry) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 58 with JobConfig

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

the class Sources_withEventJournalTest method remoteCacheJournal_withUnknownValueClass.

@Test
public void remoteCacheJournal_withUnknownValueClass() throws Exception {
    // Given
    URL jarResource = Thread.currentThread().getContextClassLoader().getResource("deployment/sample-pojo-1.0-car.jar");
    assertNotNull("jar not found", jarResource);
    ClassLoader cl = new URLClassLoader(new URL[] { jarResource });
    Class<?> carClz = cl.loadClass("com.sample.pojo.car.Car");
    Object car = carClz.getConstructor(String.class, String.class).newInstance("make", "model");
    String cacheName = JOURNALED_CACHE_PREFIX + randomName();
    ICache<String, Object> cache = remoteHz.getCacheManager().getCache(cacheName);
    // the class of the value is unknown to the remote IMDG member, it will be only known to Jet
    cache.put("key", car);
    // When
    StreamSource<Entry<Object, Object>> source = Sources.remoteCacheJournal(cacheName, clientConfig, START_FROM_OLDEST);
    // Then
    p.readFrom(source).withoutTimestamps().map(en -> en.getValue().toString()).writeTo(sink);
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJar(jarResource);
    Job job = hz().getJet().newJob(p, jobConfig);
    List<Object> expected = singletonList(car.toString());
    assertTrueEventually(() -> assertEquals(expected, new ArrayList<>(sinkList)), 10);
    job.cancel();
}
Also used : BeforeClass(org.junit.BeforeClass) IntStream.range(java.util.stream.IntStream.range) URL(java.net.URL) HazelcastInstanceFactory(com.hazelcast.instance.impl.HazelcastInstanceFactory) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) URLClassLoader(java.net.URLClassLoader) EventJournalCacheEvent(com.hazelcast.cache.EventJournalCacheEvent) Util.entry(com.hazelcast.jet.Util.entry) ClientConfig(com.hazelcast.client.config.ClientConfig) Job(com.hazelcast.jet.Job) IList(com.hazelcast.collection.IList) PredicateEx(com.hazelcast.function.PredicateEx) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AfterClass(org.junit.AfterClass) Assert.assertNotNull(org.junit.Assert.assertNotNull) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Functions.entryValue(com.hazelcast.function.Functions.entryValue) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) ICache(com.hazelcast.cache.ICache) Entry(java.util.Map.Entry) Util.mapPutEvents(com.hazelcast.jet.Util.mapPutEvents) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) ArrayList(java.util.ArrayList) URL(java.net.URL) JobConfig(com.hazelcast.jet.config.JobConfig) Entry(java.util.Map.Entry) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Job(com.hazelcast.jet.Job) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 59 with JobConfig

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

the class AsyncTransformUsingServiceP_IntegrationTest method test_pipelineApi_mapNotPartitioned.

@Test
public void test_pipelineApi_mapNotPartitioned() {
    Pipeline p = Pipeline.create();
    p.readFrom(Sources.mapJournal(journaledMap, START_FROM_OLDEST, EventJournalMapEvent::getNewValue, alwaysTrue())).withoutTimestamps().mapUsingServiceAsync(serviceFactory, transformNotPartitionedFn(i -> i + "-1")).setLocalParallelism(2).writeTo(Sinks.list(sinkList));
    instance().getJet().newJob(p, jobConfig);
    assertResultEventually(i -> Stream.of(i + "-1"), NUM_ITEMS);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) DAG(com.hazelcast.jet.core.DAG) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) WatermarkPolicy(com.hazelcast.jet.core.WatermarkPolicy) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) Collectors.joining(java.util.stream.Collectors.joining) Sources(com.hazelcast.jet.pipeline.Sources) Stream(java.util.stream.Stream) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) IntStream(java.util.stream.IntStream) PredicateEx.alwaysTrue(com.hazelcast.function.PredicateEx.alwaysTrue) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Function(java.util.function.Function) DEFAULT_MAX_CONCURRENT_OPS(com.hazelcast.jet.pipeline.GeneralStage.DEFAULT_MAX_CONCURRENT_OPS) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) IList(com.hazelcast.collection.IList) Config(com.hazelcast.config.Config) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Parameter(org.junit.runners.Parameterized.Parameter) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Test(org.junit.Test) Vertex(com.hazelcast.jet.core.Vertex) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) TriFunction(com.hazelcast.jet.function.TriFunction) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Edge.between(com.hazelcast.jet.core.Edge.between) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with JobConfig

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

the class AsyncTransformUsingServiceP_IntegrationTest method stressTestInt.

private void stressTestInt(boolean restart) {
    /*
        This is a stress test of the cooperative emission using the DAG api. Only through DAG
        API we can configure edge queue sizes, which we use to cause more trouble for the
        cooperative emission.
         */
    // add more input to the source map
    int numItems = 10_000;
    journaledMap.putAll(IntStream.range(NUM_ITEMS, numItems).boxed().collect(toMap(i -> i, i -> i)));
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", throttle(streamMapP(journaledMap.getName(), alwaysTrue(), EventJournalMapEvent::getNewValue, START_FROM_OLDEST, eventTimePolicy(i -> (long) ((Integer) i), WatermarkPolicy.limitingLag(10), 10, 0, 0)), 5000));
    BiFunctionEx<ExecutorService, Integer, CompletableFuture<Traverser<String>>> flatMapAsyncFn = transformNotPartitionedFn(i -> traverseItems(i + "-1", i + "-2", i + "-3", i + "-4", i + "-5"));
    ProcessorSupplier processorSupplier = ordered ? AsyncTransformUsingServiceOrderedP.supplier(serviceFactory, DEFAULT_MAX_CONCURRENT_OPS, flatMapAsyncFn) : AsyncTransformUsingServiceUnorderedP.supplier(serviceFactory, DEFAULT_MAX_CONCURRENT_OPS, flatMapAsyncFn, identity());
    Vertex map = dag.newVertex("map", processorSupplier).localParallelism(2);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeListP(sinkList.getName()));
    // Use a shorter queue to not block the barrier from the source for too long due to
    // the backpressure from the slow mapper
    EdgeConfig edgeToMapperConfig = new EdgeConfig().setQueueSize(128);
    // Use a shorter queue on output from the mapper so that we experience backpressure
    // from the sink
    EdgeConfig edgeFromMapperConfig = new EdgeConfig().setQueueSize(10);
    dag.edge(between(source, map).setConfig(edgeToMapperConfig)).edge(between(map, sink).setConfig(edgeFromMapperConfig));
    Job job = instance().getJet().newJob(dag, jobConfig);
    for (int i = 0; restart && i < 5; i++) {
        assertJobStatusEventually(job, RUNNING);
        sleepMillis(100);
        job.restart();
    }
    assertResultEventually(i -> Stream.of(i + "-1", i + "-2", i + "-3", i + "-4", i + "-5"), numItems);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) DAG(com.hazelcast.jet.core.DAG) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) WatermarkPolicy(com.hazelcast.jet.core.WatermarkPolicy) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) Collectors.joining(java.util.stream.Collectors.joining) Sources(com.hazelcast.jet.pipeline.Sources) Stream(java.util.stream.Stream) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) IntStream(java.util.stream.IntStream) PredicateEx.alwaysTrue(com.hazelcast.function.PredicateEx.alwaysTrue) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Function(java.util.function.Function) DEFAULT_MAX_CONCURRENT_OPS(com.hazelcast.jet.pipeline.GeneralStage.DEFAULT_MAX_CONCURRENT_OPS) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) IList(com.hazelcast.collection.IList) Config(com.hazelcast.config.Config) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Parameter(org.junit.runners.Parameterized.Parameter) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Test(org.junit.Test) Vertex(com.hazelcast.jet.core.Vertex) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) TriFunction(com.hazelcast.jet.function.TriFunction) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) DAG(com.hazelcast.jet.core.DAG) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job)

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