Search in sources :

Example 1 with AvailablePortIterator

use of com.oracle.bedrock.runtime.network.AvailablePortIterator in project oracle-bedrock by coherence-community.

the class AbstractCoherenceClusterBuilderTest method shouldBuildStorageEnabledCluster.

/**
 * Ensure we can build and destroy a {@link CoherenceCluster} containing storage-enabled
 * {@link CoherenceCacheServer}s.
 */
@Test
public void shouldBuildStorageEnabledCluster() {
    final int CLUSTER_SIZE = 3;
    AvailablePortIterator availablePorts = LocalPlatform.get().getAvailablePorts();
    ClusterPort clusterPort = ClusterPort.of(new Capture<>(availablePorts));
    CoherenceClusterBuilder builder = new CoherenceClusterBuilder();
    builder.include(CLUSTER_SIZE, CoherenceClusterMember.class, clusterPort, LocalHost.only(), ClusterName.of("Storage-Only"));
    try (CoherenceCluster cluster = builder.build(getPlatform(), Console.system())) {
        assertThat(invoking(cluster).getClusterSize(), is(CLUSTER_SIZE));
    }
}
Also used : AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) ClusterPort(com.oracle.bedrock.runtime.coherence.options.ClusterPort) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Example 2 with AvailablePortIterator

use of com.oracle.bedrock.runtime.network.AvailablePortIterator 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 AvailablePortIterator

use of com.oracle.bedrock.runtime.network.AvailablePortIterator 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)

Example 4 with AvailablePortIterator

use of com.oracle.bedrock.runtime.network.AvailablePortIterator 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 5 with AvailablePortIterator

use of com.oracle.bedrock.runtime.network.AvailablePortIterator in project oracle-bedrock by coherence-community.

the class AbstractCoherenceCacheServerTest method shouldStartJMXConnection.

/**
 * Ensure we can start and connect to the Coherence using the {@link JmxFeature}.
 *
 * @throws Exception
 */
@Test
public void shouldStartJMXConnection() throws Exception {
    AvailablePortIterator availablePorts = LocalPlatform.get().getAvailablePorts();
    Platform platform = getPlatform();
    try (CoherenceCacheServer server = platform.launch(CoherenceCacheServer.class, ClusterPort.from(availablePorts), LocalHost.only(), RoleName.of("test-role"), SiteName.of("test-site"), JmxFeature.enabled(), JMXManagementMode.LOCAL_ONLY)) {
        assertThat(invoking(server).getClusterSize(), is(1));
        assertThat(server.getRoleName(), is("test-role"));
        assertThat(server.getSiteName(), is("test-site"));
        JmxFeature jmxFeature = server.get(JmxFeature.class);
        assertThat(jmxFeature, is(notNullValue()));
        // use JMX to determine the cluster size
        int size = jmxFeature.getMBeanAttribute(new ObjectName("Coherence:type=Cluster"), "ClusterSize", Integer.class);
        assertThat(size, is(1));
    }
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Platform(com.oracle.bedrock.runtime.Platform) AvailablePortIterator(com.oracle.bedrock.runtime.network.AvailablePortIterator) JmxFeature(com.oracle.bedrock.runtime.java.features.JmxFeature) ObjectName(javax.management.ObjectName) AbstractTest(com.oracle.bedrock.testsupport.junit.AbstractTest) Test(org.junit.Test)

Aggregations

AvailablePortIterator (com.oracle.bedrock.runtime.network.AvailablePortIterator)16 Test (org.junit.Test)13 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)12 ClusterPort (com.oracle.bedrock.runtime.coherence.options.ClusterPort)10 Capture (com.oracle.bedrock.util.Capture)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)5 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 Platform (com.oracle.bedrock.runtime.Platform)4 OptionsByType (com.oracle.bedrock.OptionsByType)3 NamedCache (com.tangosol.net.NamedCache)3 ApplicationListener (com.oracle.bedrock.runtime.ApplicationListener)2 ClassPath (com.oracle.bedrock.runtime.java.ClassPath)2 JavaAgent (com.oracle.bedrock.runtime.java.options.JavaAgent)2 File (java.io.File)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 SocketEchoServer (applications.SocketEchoServer)1 DeferredHelper.invoking (com.oracle.bedrock.deferred.DeferredHelper.invoking)1 Decoration (com.oracle.bedrock.options.Decoration)1