|
| 1 | +/* |
| 2 | + * File: AbstractClusterBuilderTest.java |
| 3 | + * |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 5 | + * |
| 6 | + * The contents of this file are subject to the terms and conditions of |
| 7 | + * the Common Development and Distribution License 1.0 (the "License"). |
| 8 | + * |
| 9 | + * You may not use this file except in compliance with the License. |
| 10 | + * |
| 11 | + * You can obtain a copy of the License by consulting the LICENSE.txt file |
| 12 | + * distributed with this file, or by consulting https://oss.oracle.com/licenses/CDDL |
| 13 | + * |
| 14 | + * See the License for the specific language governing permissions |
| 15 | + * and limitations under the License. |
| 16 | + * |
| 17 | + * When distributing the software, include this License Header Notice in each |
| 18 | + * file and include the License file LICENSE.txt. |
| 19 | + * |
| 20 | + * MODIFICATIONS: |
| 21 | + * If applicable, add the following below the License Header, with the fields |
| 22 | + * enclosed by brackets [] replaced by your own identifying information: |
| 23 | + * "Portions Copyright [year] [name of copyright owner]" |
| 24 | + */ |
| 25 | + |
| 26 | +package com.oracle.tools.runtime.coherence; |
| 27 | + |
| 28 | +import com.oracle.tools.junit.AbstractTest; |
| 29 | + |
| 30 | +import com.oracle.tools.runtime.PropertiesBuilder; |
| 31 | + |
| 32 | +import com.oracle.tools.runtime.coherence.ClusterMemberSchema.JMXManagementMode; |
| 33 | + |
| 34 | +import com.oracle.tools.runtime.console.SystemApplicationConsole; |
| 35 | + |
| 36 | +import com.oracle.tools.runtime.java.ContainerBasedJavaApplicationBuilder; |
| 37 | +import com.oracle.tools.runtime.java.JavaApplicationBuilder; |
| 38 | +import com.oracle.tools.runtime.java.SimpleJavaApplication; |
| 39 | +import com.oracle.tools.runtime.java.SimpleJavaApplicationSchema; |
| 40 | +import com.oracle.tools.runtime.java.container.Container; |
| 41 | + |
| 42 | +import com.oracle.tools.runtime.network.AvailablePortIterator; |
| 43 | + |
| 44 | +import junit.framework.Assert; |
| 45 | + |
| 46 | +import org.hamcrest.Matchers; |
| 47 | + |
| 48 | +import org.junit.Test; |
| 49 | + |
| 50 | +import static com.oracle.tools.deferred.DeferredAssert.assertThat; |
| 51 | + |
| 52 | +import static com.oracle.tools.deferred.DeferredHelper.eventually; |
| 53 | +import static com.oracle.tools.deferred.DeferredHelper.invoking; |
| 54 | + |
| 55 | +import static org.hamcrest.CoreMatchers.is; |
| 56 | + |
| 57 | +import java.util.HashSet; |
| 58 | + |
| 59 | +import javax.management.ObjectName; |
| 60 | + |
| 61 | +/** |
| 62 | + * Functional Tests for the {@link com.oracle.tools.runtime.coherence.ClusterBuilder} class. |
| 63 | + * <p> |
| 64 | + * Copyright (c) 2013. All Rights Reserved. Oracle Corporation.<br> |
| 65 | + * Oracle is a registered trademark of Oracle Corporation and/or its affiliates. |
| 66 | + * |
| 67 | + * @author Brian Oliver |
| 68 | + */ |
| 69 | +public abstract class AbstractClusterBuilderTest extends AbstractTest |
| 70 | +{ |
| 71 | + /** |
| 72 | + * Creates a new {@link com.oracle.tools.runtime.java.JavaApplicationBuilder} |
| 73 | + * to use for a tests in this class and/or sub-classes. |
| 74 | + * |
| 75 | + * @return the {@link com.oracle.tools.runtime.java.JavaApplicationBuilder} |
| 76 | + */ |
| 77 | + public abstract JavaApplicationBuilder<ClusterMember, ClusterMemberSchema> newJavaApplicationBuilder(); |
| 78 | + |
| 79 | + |
| 80 | + /** |
| 81 | + * Ensure we can build and destroy a {@link com.oracle.tools.runtime.coherence.Cluster} |
| 82 | + * of storage enabled members. |
| 83 | + * |
| 84 | + * @throws Exception |
| 85 | + */ |
| 86 | + @Test |
| 87 | + public void shouldBuildStorageEnabledCluster() throws Exception |
| 88 | + { |
| 89 | + final int CLUSTER_SIZE = 3; |
| 90 | + |
| 91 | + AvailablePortIterator portIterator = Container.getAvailablePorts(); |
| 92 | + |
| 93 | + ClusterMemberSchema schema = |
| 94 | + new ClusterMemberSchema().setEnvironmentVariables(PropertiesBuilder.fromCurrentEnvironmentVariables()) |
| 95 | + .setSingleServerMode().setClusterPort(portIterator.next()).setJMXPort(portIterator) |
| 96 | + .setJMXManagementMode(JMXManagementMode.LOCAL_ONLY); |
| 97 | + |
| 98 | + Cluster cluster = null; |
| 99 | + |
| 100 | + try |
| 101 | + { |
| 102 | + ClusterBuilder builder = new ClusterBuilder(); |
| 103 | + |
| 104 | + builder.addBuilder(newJavaApplicationBuilder(), schema, "DCCF", CLUSTER_SIZE); |
| 105 | + |
| 106 | + cluster = builder.realize(new SystemApplicationConsole()); |
| 107 | + |
| 108 | + assertThat(eventually(invoking(cluster).getClusterSize()), is(CLUSTER_SIZE)); |
| 109 | + } |
| 110 | + catch (Exception e) |
| 111 | + { |
| 112 | + e.printStackTrace(); |
| 113 | + Assert.fail(); |
| 114 | + } |
| 115 | + finally |
| 116 | + { |
| 117 | + if (cluster != null) |
| 118 | + { |
| 119 | + cluster.destroy(); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + /** |
| 126 | + * Ensure we can build and destroy a {@link com.oracle.tools.runtime.coherence.Cluster} |
| 127 | + * of storage enabled members with a proxy server. |
| 128 | + * |
| 129 | + * @throws Exception |
| 130 | + */ |
| 131 | + @Test |
| 132 | + public void shouldBuildStorageAndProxyCluster() throws Exception |
| 133 | + { |
| 134 | + AvailablePortIterator jmxPorts = Container.getAvailablePorts(); |
| 135 | + |
| 136 | + int clusterPort = jmxPorts.next(); |
| 137 | + |
| 138 | + ClusterMemberSchema storageSchema = |
| 139 | + new ClusterMemberSchema().setClusterPort(clusterPort).setStorageEnabled(true) |
| 140 | + .setCacheConfigURI("test-cache-config.xml").setJMXSupport(true).setRemoteJMXManagement(true) |
| 141 | + .setJMXManagementMode(ClusterMemberSchema.JMXManagementMode.LOCAL_ONLY).setJMXPort(jmxPorts) |
| 142 | + .setSingleServerMode(); |
| 143 | + |
| 144 | + ClusterMemberSchema extendSchema = |
| 145 | + new ClusterMemberSchema().setStorageEnabled(false).setClusterPort(clusterPort) |
| 146 | + .setCacheConfigURI("test-extend-proxy-config.xml").setJMXSupport(true).setRemoteJMXManagement(true) |
| 147 | + .setSystemProperty("coherence.extend.port", |
| 148 | + jmxPorts).setJMXManagementMode(ClusterMemberSchema.JMXManagementMode.LOCAL_ONLY) |
| 149 | + .setJMXPort(jmxPorts).setSingleServerMode(); |
| 150 | + |
| 151 | + SystemApplicationConsole console = new SystemApplicationConsole(); |
| 152 | + |
| 153 | + Cluster cluster = null; |
| 154 | + |
| 155 | + try |
| 156 | + { |
| 157 | + ClusterBuilder builder = new ClusterBuilder(); |
| 158 | + |
| 159 | + builder.addBuilder(newJavaApplicationBuilder(), storageSchema, "storage", 2); |
| 160 | + builder.addBuilder(newJavaApplicationBuilder(), extendSchema, "extend", 1); |
| 161 | + |
| 162 | + cluster = builder.realize(new SystemApplicationConsole()); |
| 163 | + |
| 164 | + // ensure the cluster size is as expected |
| 165 | + assertThat(eventually(invoking(cluster).getClusterSize()), is(3)); |
| 166 | + |
| 167 | + // ensure the member id's are different |
| 168 | + HashSet<Integer> memberIds = new HashSet<Integer>(); |
| 169 | + |
| 170 | + for (ClusterMember member : cluster) |
| 171 | + { |
| 172 | + memberIds.add(member.getLocalMemberId()); |
| 173 | + } |
| 174 | + |
| 175 | + Assert.assertEquals(3, memberIds.size()); |
| 176 | + |
| 177 | + // ensure the there's only one extend service instance |
| 178 | + ObjectName objectName = |
| 179 | + new ObjectName("Coherence:type=ConnectionManager,name=ExtendTcpProxyService,nodeId=*"); |
| 180 | + |
| 181 | + ClusterMember extendMember = cluster.getApplication("extend-1"); |
| 182 | + |
| 183 | + assertThat(eventually(invoking(extendMember).queryMBeans(objectName, null).size()), Matchers.is(1)); |
| 184 | + |
| 185 | + for (ClusterMember storageMember : cluster.getApplications("storage")) |
| 186 | + { |
| 187 | + assertThat(eventually(invoking(storageMember).queryMBeans(objectName, null).size()), Matchers.is(0)); |
| 188 | + } |
| 189 | + } |
| 190 | + catch (Exception e) |
| 191 | + { |
| 192 | + e.printStackTrace(); |
| 193 | + Assert.fail(); |
| 194 | + } |
| 195 | + finally |
| 196 | + { |
| 197 | + if (cluster != null) |
| 198 | + { |
| 199 | + cluster.destroy(); |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | +} |
0 commit comments