Search in sources :

Example 1 with JavaAgent

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

the class LocalCoherenceClusterBuilderTest 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();
        Assert.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.Test)

Example 2 with JavaAgent

use of com.oracle.bedrock.runtime.java.options.JavaAgent 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 3 with JavaAgent

use of com.oracle.bedrock.runtime.java.options.JavaAgent 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)

Aggregations

ClassPath (com.oracle.bedrock.runtime.java.ClassPath)3 JavaAgent (com.oracle.bedrock.runtime.java.options.JavaAgent)3 AvailablePortIterator (com.oracle.bedrock.runtime.network.AvailablePortIterator)2 Capture (com.oracle.bedrock.util.Capture)2 File (java.io.File)2 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1