Search in sources :

Example 21 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class LocalCoherenceClusterBuilderIT method shouldEstablishStorageAndProxyClusterWithCodeCoverage.

/**
 * Ensure we can build and close a {@link CoherenceCluster}
 * of storage enabled members with a proxy server when using code-coverage tools.
 */
@Test
public void shouldEstablishStorageAndProxyClusterWithCodeCoverage() throws Exception {
    // determine the classpath of the JaCoCo runtime agent jar (should be something like jacocoagent-x.y.z.jar)
    ClassPath jacocoPath = ClassPath.ofClass(RT.class);
    // define a temp file name pattern for JaCoCo code coverage reports
    String jacocoDestinationFileName = "jacoco-${bedrock.runtime.id}.exec";
    File destinationFile = new File(System.getProperty("java.io.tmpdir"), jacocoDestinationFileName);
    // define the JavaAgent for JaCoCo
    JavaAgent javaAgent = JavaAgent.using(jacocoPath.toString(), "destfile=" + destinationFile + ",output=file,sessionid=${bedrock.runtime.id},dumponexit=true");
    AvailablePortIterator availablePorts = LocalPlatform.get().getAvailablePorts();
    Capture<Integer> clusterPort = new Capture<>(availablePorts);
    CoherenceClusterBuilder builder = new CoherenceClusterBuilder();
    builder.include(2, CoherenceClusterMember.class, DisplayName.of("storage"), ClusterPort.of(clusterPort), LocalStorage.enabled(), CacheConfig.of("test-cache-config.xml"), LocalHost.only(), ClusterName.of("Storage-Proxy"), javaAgent, RuntimeExit.withExitCode(0));
    builder.include(1, CoherenceClusterMember.class, DisplayName.of("extend"), ClusterPort.of(clusterPort), LocalStorage.disabled(), CacheConfig.of("test-extend-proxy-config.xml"), LocalHost.only(), ClusterName.of("Storage-Proxy"), javaAgent, RuntimeExit.withExitCode(0));
    try (CoherenceCluster cluster = builder.build(Console.system())) {
        // ensure the cluster size is as expected
        assertThat(invoking(cluster).getClusterSize(), is(3));
        CoherenceClusterMember extendMember = cluster.get("extend-1");
        assertThat(invoking(extendMember).isServiceRunning("ExtendTcpProxyService"), is(true));
        for (CoherenceClusterMember storageMember : cluster.getAll("storage")) {
            assertThat(invoking(storageMember).isServiceRunning("ExtendTcpProxyService"), is(false));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assertions.fail();
    }
}
Also used : JavaAgent(com.oracle.bedrock.runtime.java.options.JavaAgent) ClassPath(com.oracle.bedrock.runtime.java.ClassPath) AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) File(java.io.File) Capture(com.oracle.bedrock.util.Capture) Test(org.junit.jupiter.api.Test)

Example 22 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class Maven method onLaunching.

@Override
public void onLaunching(Platform platform, MetaClass metaClass, OptionsByType optionsByType) {
    // resolve the class path based on the required maven artifacts
    try {
        perform((system, session, repositories, scope) -> {
            // we only filter based on the scope
            DependencyFilter filter = DependencyFilterUtils.classpathFilter(scope);
            // collect class paths for each resolved artifact
            LinkedHashSet<ClassPath> artifactPaths = new LinkedHashSet<>();
            for (Artifact artifact : artifacts.values()) {
                CollectRequest collectRequest = new CollectRequest();
                collectRequest.setRoot(new Dependency(artifact, scope));
                collectRequest.setRepositories(repositories);
                DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter);
                List<ArtifactResult> artifactResults = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
                for (ArtifactResult artifactResult : artifactResults) {
                    artifactPaths.add(ClassPath.ofFile(artifactResult.getArtifact().getFile()));
                }
            }
            // define the ClassPath based on the artifact paths
            ClassPath classPath = new ClassPath(artifactPaths);
            // add the additional ClassPaths (when defined)
            classPath = additionalClassPath == null ? classPath : new ClassPath(classPath, additionalClassPath);
            optionsByType.add(classPath);
        }, optionsByType);
    } catch (RepositoryException e) {
        throw new RuntimeException("Failed to resolve artifact", e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClassPath(com.oracle.bedrock.runtime.java.ClassPath) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) RepositoryException(org.eclipse.aether.RepositoryException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 23 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class JacocoProfile method onLaunching.

@Override
public void onLaunching(Platform platform, MetaClass metaClass, OptionsByType optionsByType) {
    if (enabled && metaClass != null && JavaApplication.class.isAssignableFrom(metaClass.getImplementationClass(platform, optionsByType))) {
        try {
            // determine the classpath of the JaCoCo runtime agent jar (should be something like jacocoagent-x.y.z.jar)
            ClassPath jacocoPath = ClassPath.ofClass(RT.class);
            // define a JavaAgent for JaCoCo
            JavaAgent javaAgent = JavaAgent.using(jacocoPath.toString(), parameters);
            optionsByType.add(javaAgent);
        } catch (Exception e) {
        // ignored
        }
    }
}
Also used : JavaAgent(com.oracle.bedrock.runtime.java.options.JavaAgent) ClassPath(com.oracle.bedrock.runtime.java.ClassPath) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) IOException(java.io.IOException)

Example 24 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class MavenTest method shouldResolveSingleArtifactWithTransitiveDependency.

/**
 * Ensure that {@link Maven} can resolve a single artifact (with a transitive dependency).
 */
@Test
public void shouldResolveSingleArtifactWithTransitiveDependency() {
    LocalPlatform platform = LocalPlatform.get();
    MetaClass metaClass = new JavaApplication.MetaClass();
    OptionsByType optionsByType = OptionsByType.empty();
    optionsByType.add(Maven.artifact("junit:junit:jar:4.12"));
    Maven maven = optionsByType.get(Maven.class);
    maven.onLaunching(platform, metaClass, optionsByType);
    ClassPath classPath = optionsByType.getOrDefault(ClassPath.class, null);
    assertThat(classPath, is(not(nullValue())));
    assertThat(classPath.size(), is(2));
    assertThat(classPath.toString(), containsString("junit-4.12.jar"));
    assertThat(classPath.toString(), containsString("hamcrest-core-1.3.jar"));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) MetaClass(com.oracle.bedrock.runtime.MetaClass) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 25 with ClassPath

use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.

the class TestClassesClassPathClassesTest method shouldLoadRunWithAnnotatedTestClass.

@Test
public void shouldLoadRunWithAnnotatedTestClass() throws Exception {
    File folder = createClassesFolder(RunWithAnnotatedTest.class);
    ClassPath classPath = ClassPath.ofFile(folder);
    TestClasses.ClassPathClasses testClasses = new TestClasses.ClassPathClasses(classPath);
    Set<Class<?>> classes = testClasses.resolveTestClasses();
    assertThat(classes, is(notNullValue()));
    assertThat(classes, containsInAnyOrder(RunWithAnnotatedTest.class));
}
Also used : TestClasses(com.oracle.bedrock.testsupport.junit.options.TestClasses) RunWithAnnotatedTest(com.oracle.bedrock.testsupport.junit.RunWithAnnotatedTest) ClassPath(com.oracle.bedrock.runtime.java.ClassPath) File(java.io.File) RunWithAnnotatedTest(com.oracle.bedrock.testsupport.junit.RunWithAnnotatedTest) AbstractJUnit4Test(com.oracle.bedrock.testsupport.junit.AbstractJUnit4Test) JUnit4Test(com.oracle.bedrock.testsupport.junit.JUnit4Test) JUnit3Test(com.oracle.bedrock.testsupport.junit.JUnit3Test) Test(org.junit.Test)

Aggregations

ClassPath (com.oracle.bedrock.runtime.java.ClassPath)29 Test (org.junit.Test)21 File (java.io.File)12 TestClasses (com.oracle.bedrock.testsupport.junit.options.TestClasses)10 AbstractJUnit4Test (com.oracle.bedrock.testsupport.junit.AbstractJUnit4Test)9 JUnit3Test (com.oracle.bedrock.testsupport.junit.JUnit3Test)9 JUnit4Test (com.oracle.bedrock.testsupport.junit.JUnit4Test)9 RunWithAnnotatedTest (com.oracle.bedrock.testsupport.junit.RunWithAnnotatedTest)9 OptionsByType (com.oracle.bedrock.OptionsByType)4 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 MetaClass (com.oracle.bedrock.runtime.MetaClass)4 JavaAgent (com.oracle.bedrock.runtime.java.options.JavaAgent)3 DummyClass (classloader.child.DummyClass)2 AvailablePortIterator (com.oracle.bedrock.runtime.network.AvailablePortIterator)2 JUnit3Suite (com.oracle.bedrock.testsupport.junit.JUnit3Suite)2 Capture (com.oracle.bedrock.util.Capture)2 LinkedHashSet (java.util.LinkedHashSet)2 DummyParentLoadedClass (classloader.parent.DummyParentLoadedClass)1 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)1 ContainerClassLoader (com.oracle.bedrock.runtime.java.container.ContainerClassLoader)1