Search in sources :

Example 1 with Capture

use of com.oracle.bedrock.util.Capture in project oracle-bedrock by coherence-community.

the class LocalPlatformJavaApplicationTest method shouldEnableRemoteDebugAndConnectBackToDebugger.

/**
 * Start the {@link JavaApplication} with remote debugging enabled and mode set to
 * {@link RemoteDebugging.Behavior#ATTACH_TO_DEBUGGER}
 * and assert the process connects back to the debugger
 */
@Ignore("This test can cause JVMs to crash on various platforms.  Disabled for now until there is a fix.")
@Test
public void shouldEnableRemoteDebugAndConnectBackToDebugger() throws Exception {
    // make sure we can run the JDB debugger otherwise we cannot run this test
    Assume.assumeThat(hasJDB(), is(true));
    Capture<Integer> debuggerPort = new Capture<>(getPlatform().getAvailablePorts());
    CapturingApplicationConsole jdbConsole = new CapturingApplicationConsole();
    try (Application jdb = getPlatform().launch(Application.class, Executable.named("jdb"), Argument.of("-connect"), Argument.of("com.sun.jdi.SocketListen:localAddress=" + getPlatform().getAddress().getHostAddress() + ",port=" + debuggerPort.get()), Console.of(jdbConsole))) {
        Eventually.assertThat("JDB did not start properly", invoking(jdbConsole).getCapturedOutputLines(), hasItem(startsWith("Listening at address:")));
        CapturingApplicationConsole console = new CapturingApplicationConsole();
        try (JavaApplication app = getPlatform().launch(JavaApplication.class, ClassName.of(SleepingApplication.class), DisplayName.of("TestApp"), // sleeping for 60 seconds to allow connection
        Argument.of("60"), RemoteDebugging.enabled().attach().at(new RemoteDebugging.TransportAddress(debuggerPort)), Console.of(console))) {
            Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("Now sleeping")));
            // assert that the application connects back to the debugger
            // (this can take sometime as JDB initializes itself)
            Eventually.assertThat("Application did not connect back to JDB", invoking(jdbConsole).getCapturedOutputLines(), hasItem(containsString("VM Started:")), delayedBy(10, TimeUnit.SECONDS));
        }
    }
}
Also used : SleepingApplication(classloader.applications.SleepingApplication) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) EventingApplication(classloader.applications.EventingApplication) SleepingApplication(classloader.applications.SleepingApplication) ParentApplication(classloader.applications.ParentApplication) Application(com.oracle.bedrock.runtime.Application) Capture(com.oracle.bedrock.util.Capture) Ignore(org.junit.Ignore) SocketBasedRemoteChannelTest(com.oracle.bedrock.runtime.concurrent.socket.SocketBasedRemoteChannelTest) Test(org.junit.Test)

Example 2 with Capture

use of com.oracle.bedrock.util.Capture in project oracle-bedrock by coherence-community.

the class AbstractCoherenceClusterBuilderTest method shouldFailOverNamedCache.

/**
 * Ensure that a {@link NamedCache} produced by a {@link CoherenceCluster} {@link CoherenceClusterMember}
 * is failed over to another {@link CoherenceClusterMember} when the original {@link CoherenceClusterMember}
 * is closed.
 */
@Test
public void shouldFailOverNamedCache() {
    Capture<Integer> wkaPort = new Capture<>(LocalPlatform.get().getAvailablePorts());
    final int CLUSTER_SIZE = 3;
    String localHost = System.getProperty("tangosol.coherence.localhost", "127.0.0.1");
    AvailablePortIterator availablePorts = LocalPlatform.get().getAvailablePorts();
    ClusterPort clusterPort = ClusterPort.of(new Capture<>(availablePorts));
    CoherenceClusterBuilder builder = new CoherenceClusterBuilder();
    builder.include(CLUSTER_SIZE, CoherenceClusterMember.class, WellKnownAddress.of(localHost, wkaPort), clusterPort, LocalHost.of(localHost, wkaPort), ClusterName.of("FailOver"), DisplayName.of("DCS"));
    try (CoherenceCluster cluster = builder.build(getPlatform(), Console.system())) {
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        // acquire a NamedCache from a specific cluster member
        CoherenceClusterMember member = cluster.get("DCS-1");
        NamedCache cache = member.getCache("dist-example");
        // use the cache to put some data
        cache.put("message", "hello");
        assertThat(cluster.get("DCS-2").getCache("dist-example").get("message"), is("hello"));
        // close the cluster member
        member.close();
        // ensure that it's not in the cluster
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE - 1));
        // attempt to use the cache
        assertThat(invoking(cache).get("message"), is("hello"));
    }
}
Also used : AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Capture(com.oracle.bedrock.util.Capture) NamedCache(com.tangosol.net.NamedCache) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 3 with Capture

use of com.oracle.bedrock.util.Capture in project oracle-bedrock by coherence-community.

the class AbstractCoherenceClusterBuilderTest method shouldBuilderWKABasedStorageCluster.

/**
 * Ensure that we can build a cluster using WKA.
 */
@Test
public void shouldBuilderWKABasedStorageCluster() {
    Capture<Integer> wkaPort = new Capture<>(LocalPlatform.get().getAvailablePorts());
    ClusterPort clusterPort = ClusterPort.of(new Capture<>(LocalPlatform.get().getAvailablePorts()));
    String localHost = System.getProperty("tangosol.coherence.localhost", "127.0.0.1");
    String clusterName = "WKA" + getClass().getSimpleName();
    int desiredClusterSize = 4;
    CoherenceClusterBuilder clusterBuilder = new CoherenceClusterBuilder();
    clusterBuilder.include(desiredClusterSize, CoherenceClusterMember.class, DisplayName.of("storage"), LocalStorage.enabled(), WellKnownAddress.of(localHost, wkaPort), ClusterName.of(clusterName), LocalHost.of(localHost, wkaPort), clusterPort);
    try (CoherenceCluster cluster = clusterBuilder.build(Console.system())) {
        assertThat(invoking(cluster).getClusterSize(), is(desiredClusterSize));
    }
}
Also used : ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Capture(com.oracle.bedrock.util.Capture) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 4 with Capture

use of com.oracle.bedrock.util.Capture in project oracle-bedrock by coherence-community.

the class AbstractCoherenceClusterBuilderTest method shouldRemoveCoherenceClusterMemberFromCoherenceCluster.

/**
 * Ensure that the explicitly closing a CoherenceCacheServer removes it from
 * the CoherenceCluster in which is it defined.
 */
@Test
public void shouldRemoveCoherenceClusterMemberFromCoherenceCluster() {
    final int CLUSTER_SIZE = 3;
    Capture<Integer> wkaPort = new Capture<>(LocalPlatform.get().getAvailablePorts());
    String localHost = System.getProperty("tangosol.coherence.localhost", "127.0.0.1");
    ClusterPort clusterPort = ClusterPort.of(new Capture<>(LocalPlatform.get().getAvailablePorts()));
    CoherenceClusterBuilder builder = new CoherenceClusterBuilder();
    builder.include(CLUSTER_SIZE, CoherenceClusterMember.class, WellKnownAddress.of(localHost, wkaPort), clusterPort, LocalHost.of(localHost, wkaPort), ClusterName.of("Access"), DisplayName.of("DCS"));
    try (CoherenceCluster cluster = builder.build(getPlatform(), Console.system())) {
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        // acquire a cluster member
        CoherenceClusterMember member = cluster.get("DCS-1");
        // close it
        member.close();
        // ensure that it's not in the cluster
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE - 1));
    }
}
Also used : ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Capture(com.oracle.bedrock.util.Capture) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 5 with Capture

use of com.oracle.bedrock.util.Capture in project oracle-bedrock by coherence-community.

the class AbstractCoherenceClusterBuilderTest method shouldPerformRollingRestartOfCluster.

/**
 * Ensure we perform a rolling restart of a {@link CoherenceCluster}
 */
@Test
public void shouldPerformRollingRestartOfCluster() {
    final int CLUSTER_SIZE = 4;
    AvailablePortIterator availablePorts = LocalPlatform.get().getAvailablePorts();
    ClusterPort clusterPort = ClusterPort.of(new Capture<>(availablePorts));
    String clusterName = "Rolling" + getClass().getSimpleName();
    Platform platform = getPlatform();
    CoherenceClusterBuilder builder = new CoherenceClusterBuilder();
    builder.include(CLUSTER_SIZE, CoherenceClusterMember.class, DisplayName.of("DCS"), clusterPort, ClusterName.of(clusterName), LocalHost.only(), Console.system());
    try (CoherenceCluster cluster = builder.build(getPlatform())) {
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        StabilityPredicate<CoherenceCluster> predicate = StabilityPredicate.of(CoherenceCluster.Predicates.autoStartServicesSafe());
        cluster.filter(member -> member.isServiceRunning("ProxyService")).relaunch();
        cluster.unordered().limit(2).relaunch(predicate);
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        cluster.unordered().limit(2).relaunch(predicate);
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        cluster.unordered().limit(2).relaunch(predicate);
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        // introduce a new system property for the relaunched members
        cluster.relaunch(predicate, SystemProperty.of("cloned", "yes"));
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
        // ensure all the members have the new system property
        for (CoherenceClusterMember member : cluster) {
            assertThat(member.getSystemProperty("cloned"), is("yes"));
        }
    }
}
Also used : WellKnownAddress(com.oracle.bedrock.runtime.coherence.options.WellKnownAddress) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Decoration(com.oracle.bedrock.options.Decoration) ClusterName(com.oracle.bedrock.runtime.coherence.options.ClusterName) MachineName(com.oracle.bedrock.runtime.coherence.options.MachineName) StabilityPredicate(com.oracle.bedrock.runtime.options.StabilityPredicate) ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) CacheConfig(com.oracle.bedrock.runtime.coherence.options.CacheConfig) Capture(com.oracle.bedrock.util.Capture) HashSet(java.util.HashSet) LocalHost(com.oracle.bedrock.runtime.coherence.options.LocalHost) Console(com.oracle.bedrock.runtime.options.Console) AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) OptionsByType(com.oracle.bedrock.OptionsByType) NamedCache(com.tangosol.net.NamedCache) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Trilean(com.oracle.bedrock.util.Trilean) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LocalStorage(com.oracle.bedrock.runtime.coherence.options.LocalStorage) Test(org.junit.Test) SystemProperty(com.oracle.bedrock.runtime.java.options.SystemProperty) DeferredHelper.invoking(com.oracle.bedrock.deferred.DeferredHelper.invoking) Eventually.assertThat(com.oracle.bedrock.testsupport.deferred.Eventually.assertThat) Platform(com.oracle.bedrock.runtime.Platform) ApplicationListener(com.oracle.bedrock.runtime.ApplicationListener) DisplayName(com.oracle.bedrock.runtime.options.DisplayName) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Assert(org.junit.Assert) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Platform(com.oracle.bedrock.runtime.Platform) AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Aggregations

Capture (com.oracle.bedrock.util.Capture)9 Test (org.junit.Test)8 ClusterPort (com.oracle.bedrock.runtime.coherence.options.ClusterPort)5 AvailablePortIterator (com.oracle.bedrock.runtime.network.AvailablePortIterator)5 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)5 NamedCache (com.tangosol.net.NamedCache)3 Application (com.oracle.bedrock.runtime.Application)2 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)2 ClassPath (com.oracle.bedrock.runtime.java.ClassPath)2 JavaAgent (com.oracle.bedrock.runtime.java.options.JavaAgent)2 File (java.io.File)2 Ignore (org.junit.Ignore)2 EventingApplication (classloader.applications.EventingApplication)1 ParentApplication (classloader.applications.ParentApplication)1 SleepingApplication (classloader.applications.SleepingApplication)1 OptionsByType (com.oracle.bedrock.OptionsByType)1 DeferredHelper.invoking (com.oracle.bedrock.deferred.DeferredHelper.invoking)1 Decoration (com.oracle.bedrock.options.Decoration)1