Search in sources :

Example 41 with JobConfig

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

the class AbstractDeploymentTest method testDeployment_whenZipAddedAsResource_thenClassesFromAllJarsAvailableOnClassLoader.

@Test
public void testDeployment_whenZipAddedAsResource_thenClassesFromAllJarsAvailableOnClassLoader() throws Throwable {
    DAG dag = new DAG();
    List<String> onClasspath = new ArrayList<>();
    onClasspath.add("com.sample.pojo.person.Person$Appereance");
    onClasspath.add("com.sample.pojo.car.Car");
    List<String> notOnClasspath = new ArrayList<>();
    notOnClasspath.add("com.sample.pojo.address.Address");
    dag.newVertex("load class", () -> new LoadClassesIsolated(onClasspath, notOnClasspath, true));
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJarsInZip(this.getClass().getResource("/zip-resources/person-car-jar.zip"));
    executeAndPeel(getJet().newJob(dag, jobConfig));
}
Also used : ArrayList(java.util.ArrayList) DAG(com.hazelcast.jet.core.DAG) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with JobConfig

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

the class AbstractDeploymentTest method testDeployment_whenJarAddedAsResource_thenClassesAvailableOnClassLoader.

@Test
public void testDeployment_whenJarAddedAsResource_thenClassesAvailableOnClassLoader() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("load class", () -> new LoadClassesIsolated(true));
    JobConfig jobConfig = new JobConfig();
    jobConfig.addJar(this.getClass().getResource("/deployment/sample-pojo-1.0-person.jar"));
    executeAndPeel(getJet().newJob(dag, jobConfig));
}
Also used : DAG(com.hazelcast.jet.core.DAG) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with JobConfig

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

the class AbstractDeploymentTest method testDeployment_whenAttachNestedDirectory_thenFilesAvailableOnMembers.

@Test
public void testDeployment_whenAttachNestedDirectory_thenFilesAvailableOnMembers() throws Throwable {
    Pipeline pipeline = Pipeline.create();
    String dirName = "nested";
    String dirToAttach = Paths.get(this.getClass().getResource("/" + dirName).toURI()).toString();
    pipeline.readFrom(TestSources.items(1)).flatMapUsingService(ServiceFactories.sharedService(context -> context.attachedDirectory(dirName)), (file, integer) -> Traversers.traverseStream(Files.list(file.toPath()).map(Path::toString))).apply(assertCollected(c -> {
        c.forEach(s -> {
            File dir = new File(s);
            assertTrue(dir.exists());
            try {
                List<Path> subFiles = Files.list(dir.toPath()).collect(toList());
                assertEquals("each dir should contain 1 file", 1, subFiles.size());
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });
        assertEquals("list size must be 3", 3, c.size());
    })).writeTo(Sinks.logger());
    JobConfig jobConfig = new JobConfig();
    jobConfig.attachDirectory(dirToAttach);
    executeAndPeel(getJet().newJob(pipeline, jobConfig));
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Enumeration(java.util.Enumeration) QuickTest(com.hazelcast.test.annotation.QuickTest) URL(java.net.URL) LoadResourceMetaSupplier(com.hazelcast.jet.impl.deployment.LoadResource.LoadResourceMetaSupplier) ArrayList(java.util.ArrayList) JetService(com.hazelcast.jet.JetService) URLClassLoader(java.net.URLClassLoader) TestUtil.executeAndPeel(com.hazelcast.jet.core.TestUtil.executeAndPeel) Collections.singleton(java.util.Collections.singleton) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) DAG(com.hazelcast.jet.core.DAG) ServiceFactories(com.hazelcast.jet.pipeline.ServiceFactories) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) Job(com.hazelcast.jet.Job) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Files(java.nio.file.Files) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Collections.enumeration(java.util.Collections.enumeration) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Traversers(com.hazelcast.jet.Traversers) Category(org.junit.experimental.categories.Category) File(java.io.File) JobClassLoaderFactory(com.hazelcast.jet.config.JobClassLoaderFactory) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collections.emptyEnumeration(java.util.Collections.emptyEnumeration) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) Assertions.assertCollected(com.hazelcast.jet.pipeline.test.Assertions.assertCollected) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Assert.assertEquals(org.junit.Assert.assertEquals) Path(java.nio.file.Path) IOException(java.io.IOException) File(java.io.File) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with JobConfig

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

the class AbstractDeploymentTest method testDeployment_whenAddClass_thenNestedClassesAreAddedAsWell.

@Test
public void testDeployment_whenAddClass_thenNestedClassesAreAddedAsWell() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("executes lambda from a nested class", NestedClassIsLoaded::new);
    JobConfig jobConfig = new JobConfig();
    URL classUrl = new File(CLASS_DIRECTORY).toURI().toURL();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { classUrl }, null);
    Class<?> worker = urlClassLoader.loadClass("com.sample.lambda.Worker");
    jobConfig.addClass(worker);
    executeAndPeel(getJet().newJob(dag, jobConfig));
}
Also used : URLClassLoader(java.net.URLClassLoader) DAG(com.hazelcast.jet.core.DAG) File(java.io.File) JobConfig(com.hazelcast.jet.config.JobConfig) URL(java.net.URL) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with JobConfig

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

the class AbstractDeploymentTest method testDeployment_whenAttachDirectoryWithoutId_thenFilesAvailableOnMembers.

@Test
public void testDeployment_whenAttachDirectoryWithoutId_thenFilesAvailableOnMembers() throws Throwable {
    String dirName = "deployment";
    String dirToAttach = Paths.get(this.getClass().getResource("/" + dirName).toURI()).toString();
    Pipeline pipeline = attachDirectoryPipeline(dirName);
    JobConfig jobConfig = new JobConfig();
    jobConfig.attachDirectory(dirToAttach);
    executeAndPeel(getJet().newJob(pipeline, jobConfig));
}
Also used : JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) 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