http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractServerLauncherRemoteIntegrationTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractServerLauncherRemoteIntegrationTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractServerLauncherRemoteIntegrationTestCase.java new file mode 100644 index 0000000..ec7a23b --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/AbstractServerLauncherRemoteIntegrationTestCase.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.distributed; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +import org.junit.After; +import org.junit.Before; + +import com.gemstone.gemfire.internal.process.ProcessStreamReader; + +public abstract class AbstractServerLauncherRemoteIntegrationTestCase extends AbstractServerLauncherIntegrationTestCase { + + protected volatile Process process; + protected volatile ProcessStreamReader processOutReader; + protected volatile ProcessStreamReader processErrReader; + + @Before + public final void setUpAbstractServerLauncherRemoteIntegrationTestCase() throws Exception { + } + + @After + public final void tearDownAbstractServerLauncherRemoteIntegrationTestCase() throws Exception { + if (this.process != null) { + this.process.destroy(); + this.process = null; + } + if (this.processOutReader != null && this.processOutReader.isRunning()) { + this.processOutReader.stop(); + } + if (this.processErrReader != null && this.processErrReader.isRunning()) { + this.processErrReader.stop(); + } + } + + /** + * Override as needed. + */ + protected List<String> getJvmArguments() { + final List<String> jvmArguments = new ArrayList<String>(); + jvmArguments.add("-Dgemfire.log-level=config"); + return jvmArguments; + } + + /** + * Remove final if a test needs to override. + */ + protected final AbstractLauncher.Status getExpectedStopStatusForNotRunning() { + return AbstractLauncher.Status.NOT_RESPONDING; + } + + protected void waitForServerToStart() throws Exception { + assertEventuallyTrue("waiting for local Server to start: " + launcher.status(), new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + try { + assertNotNull(process); + try { + final int value = process.exitValue(); + fail("Process has died with exit value " + value + " while waiting for it to start."); + } catch (IllegalThreadStateException e) { + // expected + } + final ServerLauncher.ServerState serverState = launcher.status(); + assertNotNull(serverState); + logger.info("serverState: "+serverState); + return AbstractLauncher.Status.ONLINE.equals(serverState.getStatus()); + } + catch (RuntimeException e) { + logger.error(e, e); + return false; + } + } + }, TIMEOUT_MILLISECONDS, INTERVAL_MILLISECONDS); + } + +}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedTestSuite.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedTestSuite.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedTestSuite.java deleted file mode 100755 index 58b8d2a..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedTestSuite.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gemstone.gemfire.distributed; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - DistributedMemberDUnitTest.class, - DistributedSystemDUnitTest.class, - LocatorDUnitTest.class, - RoleDUnitTest.class, - SystemAdminDUnitTest.class -}) -/** - * Suite of tests for distributed membership dunit tests. - * - */ -public class DistributedTestSuite { -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java index a5b07ee..1e5c8b0 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java @@ -16,6 +16,10 @@ */ package com.gemstone.gemfire.distributed; +import static com.gemstone.gemfire.test.dunit.Assert.*; +import static com.gemstone.gemfire.test.dunit.Host.*; +import static com.gemstone.gemfire.internal.AvailablePortHelper.*; + import java.io.File; import java.util.Collection; import java.util.HashSet; @@ -23,6 +27,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; +import org.junit.Test; + import com.gemstone.gemfire.distributed.AbstractLauncher.Status; import com.gemstone.gemfire.distributed.LocatorLauncher.Builder; import com.gemstone.gemfire.distributed.LocatorLauncher.LocatorState; @@ -30,20 +36,18 @@ import com.gemstone.gemfire.distributed.internal.DistributionManager; import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; import com.gemstone.gemfire.distributed.internal.InternalLocator; import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember; -import com.gemstone.gemfire.internal.AvailablePortHelper; import com.gemstone.gemfire.internal.SocketCreator; import com.gemstone.gemfire.internal.util.StopWatch; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; -import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.SerializableCallable; import com.gemstone.gemfire.test.dunit.SerializableRunnable; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; /** - * Extracted from LocatorLauncherLocalJUnitTest. + * Extracted from LocatorLauncherLocalIntegrationTest. * * @since 8.0 */ -public class HostedLocatorsDUnitTest extends DistributedTestCase { +public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase { protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes @@ -59,23 +63,20 @@ public class HostedLocatorsDUnitTest extends DistributedTestCase { public final void preTearDown() throws Exception { disconnectAllFromDS(); } - - public HostedLocatorsDUnitTest(String name) { - super(name); - } + @Test public void testGetAllHostedLocators() throws Exception { final InternalDistributedSystem system = getSystem(); final String dunitLocator = system.getConfig().getLocators(); assertNotNull(dunitLocator); assertFalse(dunitLocator.isEmpty()); - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(4); + final int[] ports = getRandomAvailableTCPPorts(4); final String uniqueName = getUniqueName(); for (int i = 0 ; i < 4; i++) { final int whichvm = i; - Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() { + getHost(0).getVM(whichvm).invoke(new SerializableCallable() { @Override public Object call() throws Exception { try { @@ -131,7 +132,7 @@ public class HostedLocatorsDUnitTest extends DistributedTestCase { // validate fix for #46324 for (int whichvm = 0 ; whichvm < 4; whichvm++) { - Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() { + getHost(0).getVM(whichvm).invoke(new SerializableRunnable() { @Override public void run() { final DistributionManager dm = (DistributionManager)InternalDistributedSystem.getAnyInstance().getDistributionManager(); @@ -148,7 +149,7 @@ public class HostedLocatorsDUnitTest extends DistributedTestCase { // validation with locators for (int whichvm = 0 ; whichvm < 4; whichvm++) { - Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() { + getHost(0).getVM(whichvm).invoke(new SerializableRunnable() { @Override public void run() { final DistributionManager dm = (DistributionManager)InternalDistributedSystem.getAnyInstance().getDistributionManager(); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanIntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanIntegrationTest.java new file mode 100755 index 0000000..1a2e2d7 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanIntegrationTest.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.distributed; + +import static org.junit.Assert.*; + +import java.lang.management.ManagementFactory; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.Callable; +import javax.management.MBeanServer; +import javax.management.MBeanServerInvocationHandler; +import javax.management.ObjectName; +import javax.management.Query; +import javax.management.QueryExp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; +import com.gemstone.gemfire.internal.process.ProcessUtils; +import com.gemstone.gemfire.management.MemberMXBean; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; + +/** + * Tests querying of MemberMXBean which is used by MBeanProcessController to + * control GemFire ControllableProcesses. + * + * @since 8.0 + */ +@Category(IntegrationTest.class) +public class LauncherMemberMXBeanIntegrationTest extends AbstractLauncherIntegrationTestCase { + + @Before + public final void setUpLauncherMemberMXBeanIntegrationTest() throws Exception { + } + + @After + public final void tearDownLauncherMemberMXBeanIntegrationTest() throws Exception { + InternalDistributedSystem ids = InternalDistributedSystem.getConnectedInstance(); + if (ids != null) { + ids.disconnect(); + } + } + + @Test + public void testQueryForMemberMXBean() throws Exception { + final Properties props = new Properties(); + props.setProperty("mcast-port", "0"); + props.setProperty("locators", ""); + props.setProperty("name", getUniqueName()); + new CacheFactory(props).create(); + + final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); + final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*"); + + waitForMemberMXBean(mbeanServer, pattern); + + final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, null); + assertFalse(mbeanNames.isEmpty()); + assertEquals("mbeanNames=" + mbeanNames, 1, mbeanNames.size()); + + final ObjectName objectName = mbeanNames.iterator().next(); + final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, + MemberMXBean.class, false); + + assertNotNull(mbean); + assertEquals(ProcessUtils.identifyPid(), mbean.getProcessId()); + assertEquals(getUniqueName(), mbean.getName()); + assertEquals(getUniqueName(), mbean.getMember()); + } + + @Test + public void testQueryForMemberMXBeanWithProcessId() throws Exception { + final Properties props = new Properties(); + props.setProperty("mcast-port", "0"); + props.setProperty("locators", ""); + props.setProperty("name", getUniqueName()); + new CacheFactory(props).create(); + + final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); + final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*"); + final QueryExp constraint = Query.eq(Query.attr("ProcessId"),Query.value(ProcessUtils.identifyPid())); + + waitForMemberMXBean(mbeanServer, pattern); + + final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, constraint); + assertFalse(mbeanNames.isEmpty()); + assertEquals(1, mbeanNames.size()); + + final ObjectName objectName = mbeanNames.iterator().next(); + final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, MemberMXBean.class, false); + + assertNotNull(mbean); + assertEquals(ProcessUtils.identifyPid(), mbean.getProcessId()); + assertEquals(getUniqueName(), mbean.getName()); + assertEquals(getUniqueName(), mbean.getMember()); + } + + @Test + public void testQueryForMemberMXBeanWithMemberName() throws Exception { + final Properties props = new Properties(); + props.setProperty("mcast-port", "0"); + props.setProperty("locators", ""); + props.setProperty("name", getUniqueName()); + new CacheFactory(props).create(); + + final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); + final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*"); + final QueryExp constraint = Query.eq(Query.attr("Name"), Query.value(getUniqueName())); + + waitForMemberMXBean(mbeanServer, pattern); + + final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, constraint); + assertFalse(mbeanNames.isEmpty()); + assertEquals(1, mbeanNames.size()); + + final ObjectName objectName = mbeanNames.iterator().next(); + final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, MemberMXBean.class, false); + + assertNotNull(mbean); + assertEquals(getUniqueName(), mbean.getMember()); + } + + private void waitForMemberMXBean(final MBeanServer mbeanServer, final ObjectName pattern) throws Exception { + assertEventuallyTrue("waiting for MemberMXBean to be registered", new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, null); + return !mbeanNames.isEmpty(); + } + }, WAIT_FOR_MBEAN_TIMEOUT, INTERVAL); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanJUnitTest.java deleted file mode 100755 index 30e21e1..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherMemberMXBeanJUnitTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gemstone.gemfire.distributed; - -import static org.junit.Assert.*; - -import java.lang.management.ManagementFactory; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.Callable; - -import javax.management.MBeanServer; -import javax.management.MBeanServerInvocationHandler; -import javax.management.ObjectName; -import javax.management.Query; -import javax.management.QueryExp; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; -import com.gemstone.gemfire.internal.process.ProcessUtils; -import com.gemstone.gemfire.management.MemberMXBean; -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; - -/** - * Tests querying of MemberMXBean which is used by MBeanProcessController to - * control GemFire ControllableProcesses. - * - * @since 8.0 - */ -@Category(IntegrationTest.class) -public class LauncherMemberMXBeanJUnitTest extends AbstractLauncherJUnitTestCase { - - @Before - public final void setUpLauncherMemberMXBeanTest() throws Exception { - } - - @After - public final void tearDownLauncherMemberMXBeanTest() throws Exception { - InternalDistributedSystem ids = InternalDistributedSystem.getConnectedInstance(); - if (ids != null) { - ids.disconnect(); - } - } - - @Test - public void testQueryForMemberMXBean() throws Exception { - final Properties props = new Properties(); - props.setProperty("mcast-port", "0"); - props.setProperty("locators", ""); - props.setProperty("name", getUniqueName()); - new CacheFactory(props).create(); - - final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); - final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*"); - - waitForMemberMXBean(mbeanServer, pattern); - - final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, null); - assertFalse(mbeanNames.isEmpty()); - assertEquals("mbeanNames=" + mbeanNames, 1, mbeanNames.size()); - - final ObjectName objectName = mbeanNames.iterator().next(); - final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, - MemberMXBean.class, false); - - assertNotNull(mbean); - assertEquals(ProcessUtils.identifyPid(), mbean.getProcessId()); - assertEquals(getUniqueName(), mbean.getName()); - assertEquals(getUniqueName(), mbean.getMember()); - } - - @Test - public void testQueryForMemberMXBeanWithProcessId() throws Exception { - final Properties props = new Properties(); - props.setProperty("mcast-port", "0"); - props.setProperty("locators", ""); - props.setProperty("name", getUniqueName()); - new CacheFactory(props).create(); - - final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); - final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*"); - final QueryExp constraint = Query.eq(Query.attr("ProcessId"),Query.value(ProcessUtils.identifyPid())); - - waitForMemberMXBean(mbeanServer, pattern); - - final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, constraint); - assertFalse(mbeanNames.isEmpty()); - assertEquals(1, mbeanNames.size()); - - final ObjectName objectName = mbeanNames.iterator().next(); - final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, MemberMXBean.class, false); - - assertNotNull(mbean); - assertEquals(ProcessUtils.identifyPid(), mbean.getProcessId()); - assertEquals(getUniqueName(), mbean.getName()); - assertEquals(getUniqueName(), mbean.getMember()); - } - - @Test - public void testQueryForMemberMXBeanWithMemberName() throws Exception { - final Properties props = new Properties(); - props.setProperty("mcast-port", "0"); - props.setProperty("locators", ""); - props.setProperty("name", getUniqueName()); - new CacheFactory(props).create(); - - final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); - final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*"); - final QueryExp constraint = Query.eq(Query.attr("Name"), Query.value(getUniqueName())); - - waitForMemberMXBean(mbeanServer, pattern); - - final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, constraint); - assertFalse(mbeanNames.isEmpty()); - assertEquals(1, mbeanNames.size()); - - final ObjectName objectName = mbeanNames.iterator().next(); - final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, MemberMXBean.class, false); - - assertNotNull(mbean); - assertEquals(getUniqueName(), mbean.getMember()); - } - - private void waitForMemberMXBean(final MBeanServer mbeanServer, final ObjectName pattern) throws Exception { - assertEventuallyTrue("waiting for MemberMXBean to be registered", new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, null); - return !mbeanNames.isEmpty(); - } - }, WAIT_FOR_MBEAN_TIMEOUT, INTERVAL); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherTestSuite.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherTestSuite.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherTestSuite.java deleted file mode 100644 index b5e787a..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LauncherTestSuite.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gemstone.gemfire.distributed; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AbstractLauncherJUnitTest.class, - AbstractLauncherServiceStatusJUnitTest.class, - - LauncherMemberMXBeanJUnitTest.class, - - LocatorLauncherJUnitTest.class, - LocatorLauncherLocalJUnitTest.class, - LocatorLauncherLocalFileJUnitTest.class, - LocatorLauncherRemoteJUnitTest.class, - LocatorLauncherRemoteFileJUnitTest.class, - - ServerLauncherJUnitTest.class, - ServerLauncherLocalJUnitTest.class, - ServerLauncherLocalFileJUnitTest.class, - ServerLauncherRemoteJUnitTest.class, - ServerLauncherRemoteFileJUnitTest.class, - ServerLauncherWithProviderJUnitTest.class, -}) -/** - * Suite of tests for the Launcher classes. - * - */ -public class LauncherTestSuite { -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java index 3c80d9a..7ee4694 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java @@ -16,8 +16,9 @@ */ package com.gemstone.gemfire.distributed; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*; +import static com.gemstone.gemfire.internal.AvailablePort.*; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; @@ -26,48 +27,46 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; -import java.util.Vector; import org.junit.After; -import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; import com.gemstone.gemfire.SystemConnectException; import com.gemstone.gemfire.cache.client.internal.locator.ClientConnectionRequest; import com.gemstone.gemfire.cache.client.internal.locator.ClientConnectionResponse; import com.gemstone.gemfire.cache.client.internal.locator.QueueConnectionRequest; import com.gemstone.gemfire.cache.client.internal.locator.QueueConnectionResponse; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; import com.gemstone.gemfire.distributed.internal.InternalLocator; import com.gemstone.gemfire.distributed.internal.ServerLocation; import com.gemstone.gemfire.distributed.internal.membership.gms.messenger.JGroupsMessenger; import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient; -import com.gemstone.gemfire.internal.AvailablePort; import com.gemstone.gemfire.internal.OSProcess; import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID; import com.gemstone.gemfire.management.internal.JmxManagerAdvisor.JmxManagerProfile; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.junit.categories.IntegrationTest; @Category(IntegrationTest.class) public class LocatorJUnitTest { - /** - * - */ private static final int REQUEST_TIMEOUT = 5 * 1000; + private Locator locator; private int port; private File tmpFile; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before public void setUp() throws IOException { tmpFile = File.createTempFile("locator", ".log"); - port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + port = getRandomAvailablePort(SOCKET); File locatorFile = new File("locator"+port+".dat"); if (locatorFile.exists()) { locatorFile.delete(); @@ -79,19 +78,22 @@ public class LocatorJUnitTest { if(locator != null) { locator.stop(); } - Assert.assertEquals(false, Locator.hasLocator()); + assertEquals(false, Locator.hasLocator()); } + /** + * TRAC #45804: if jmx-manager-start is true in a locator then gfsh connect will fail + */ @Test - public void testBug45804() throws Exception { + public void testGfshConnectShouldSucceedIfJmxManagerStartIsTrueInLocator() throws Exception { Properties dsprops = new Properties(); - int jmxPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + int jmxPort = getRandomAvailablePort(SOCKET); dsprops.setProperty("mcast-port", "0"); dsprops.setProperty("locators", "localhost[" + port + "]"); dsprops.setProperty("jmx-manager-port", ""+jmxPort); dsprops.setProperty("jmx-manager-start", "true"); dsprops.setProperty("jmx-manager-http-port", "0"); - dsprops.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); + dsprops.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); System.setProperty("gemfire.disableManagement", "false"); // not needed try { locator = Locator.startLocatorAndDS(port, new File("testJmxManager.log"), dsprops); @@ -106,11 +108,11 @@ public class LocatorJUnitTest { @Test public void testBasicInfo() throws Exception { locator = Locator.startLocator(port, tmpFile); - Assert.assertTrue(locator.isPeerLocator()); - Assert.assertFalse(locator.isServerLocator()); + assertTrue(locator.isPeerLocator()); + assertFalse(locator.isServerLocator()); String[] info = InternalLocator.getLocatorInfo(InetAddress.getLocalHost(), port); - Assert.assertNotNull(info); - Assert.assertTrue(info.length > 1); + assertNotNull(info); + assertTrue(info.length > 1); } @Test @@ -119,7 +121,7 @@ public class LocatorJUnitTest { dsprops.setProperty("mcast-port", "0"); dsprops.setProperty("locators", "localhost[" + port + "]"); dsprops.setProperty("jmx-manager-start", "false"); - dsprops.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); + dsprops.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = true; int threadCount = Thread.activeCount(); @@ -127,7 +129,7 @@ public class LocatorJUnitTest { locator = Locator.startLocatorAndDS(port, new File(""), dsprops); locator.stop(); fail("expected an exception"); - } catch (SystemConnectException e) { + } catch (SystemConnectException expected) { for (int i=0; i<10; i++) { if (threadCount < Thread.activeCount()) { @@ -146,10 +148,10 @@ public class LocatorJUnitTest { public void testServerOnly() throws Exception { Properties props = new Properties(); props.setProperty("mcast-port", "0"); - props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); + props.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); locator = Locator.startLocatorAndDS(port, tmpFile, null, props, false, true, null); - Assert.assertFalse(locator.isPeerLocator()); - Assert.assertTrue(locator.isServerLocator()); + assertFalse(locator.isPeerLocator()); + assertTrue(locator.isServerLocator()); Thread.sleep(1000); doServerLocation(); } @@ -158,12 +160,11 @@ public class LocatorJUnitTest { public void testBothPeerAndServer() throws Exception { Properties props = new Properties(); props.setProperty("mcast-port", "0"); -// props.setProperty(DistributionConfig.LOG_LEVEL_NAME , getGemFireLogLevel()); - props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); + props.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false"); locator = Locator.startLocatorAndDS(port, tmpFile, null, props); - Assert.assertTrue(locator.isPeerLocator()); - Assert.assertTrue(locator.isServerLocator()); + assertTrue(locator.isPeerLocator()); + assertTrue(locator.isServerLocator()); Thread.sleep(1000); doServerLocation(); locator.stop(); @@ -172,9 +173,11 @@ public class LocatorJUnitTest { /** * Make sure two ServerLocation objects on different hosts but with the same port * are not equal + * <p/> + * TRAC #42040: LoadBalancing directs all traffic to a single cache server if all servers are started on the same port */ @Test - public void testBug42040() { + public void testServerLocationOnDifferentHostsShouldNotTestEqual() { ServerLocation sl1 = new ServerLocation("host1", 777); ServerLocation sl2 = new ServerLocation("host2", 777); if (sl1.equals(sl2)) { @@ -186,14 +189,14 @@ public class LocatorJUnitTest { { ClientConnectionRequest request = new ClientConnectionRequest(Collections.EMPTY_SET, "group1"); ClientConnectionResponse response = (ClientConnectionResponse) TcpClient.requestToServer(InetAddress.getLocalHost(), port, request, REQUEST_TIMEOUT); - Assert.assertEquals(null, response.getServer()); + assertEquals(null, response.getServer()); } { QueueConnectionRequest request = new QueueConnectionRequest(ClientProxyMembershipID.getNewProxyMembership(InternalDistributedSystem.getAnyInstance()), 3, Collections.EMPTY_SET, "group1",true); QueueConnectionResponse response = (QueueConnectionResponse) TcpClient.requestToServer(InetAddress.getLocalHost(), port, request, REQUEST_TIMEOUT); - Assert.assertEquals(new ArrayList(), response.getServers()); - Assert.assertFalse(response.isDurableQueueFound()); + assertEquals(new ArrayList(), response.getServers()); + assertFalse(response.isDurableQueueFound()); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java deleted file mode 100755 index 3b56554..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationJUnitTest.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gemstone.gemfire.distributed; - -import static com.googlecode.catchexception.apis.BDDCatchException.caughtException; -import static com.googlecode.catchexception.apis.BDDCatchException.when; -import static org.assertj.core.api.BDDAssertions.*; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.net.InetAddress; -import java.util.Properties; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.RestoreSystemProperties; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; -import org.junit.rules.TestName; - -import com.gemstone.gemfire.distributed.LocatorLauncher.Builder; -import com.gemstone.gemfire.distributed.LocatorLauncher.Command; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; -import com.gemstone.gemfire.internal.i18n.LocalizedStrings; -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; - -/** - * Integration tests for LocatorLauncher. These tests require file system I/O. - */ -@Category(IntegrationTest.class) -public class LocatorLauncherIntegrationJUnitTest { - - @Rule - public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); - - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Rule - public final TestName testName = new TestName(); - - @Test - public void testBuilderParseArgumentsWithValuesSeparatedWithCommas() throws Exception { - // given: a new builder and working directory - String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath(); - Builder builder = new Builder(); - - // when: parsing many arguments - builder.parseArguments( - "start", - "memberOne", - "--bind-address", InetAddress.getLocalHost().getHostAddress(), - "--dir", expectedWorkingDirectory, - "--hostname-for-clients", "Tucows", - "--pid", "1234", - "--port", "11235", - "--redirect-output", - "--force", - "--debug"); - - // then: the getters should return properly parsed values - assertThat(builder.getCommand()).isEqualTo(Command.START); - assertThat(builder.getBindAddress()).isEqualTo(InetAddress.getLocalHost()); - assertThat(builder.getWorkingDirectory()).isEqualTo(expectedWorkingDirectory); - assertThat(builder.getHostnameForClients()).isEqualTo("Tucows"); - assertThat(builder.getPid().intValue()).isEqualTo(1234); - assertThat(builder.getPort().intValue()).isEqualTo(11235); - assertThat(builder.getRedirectOutput()).isTrue(); - assertThat(builder.getForce()).isTrue(); - assertThat(builder.getDebug()).isTrue(); - } - - @Test - public void testBuilderParseArgumentsWithValuesSeparatedWithEquals() throws Exception { - // given: a new builder and a directory - String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath(); - Builder builder = new Builder(); - - // when: parsing arguments with values separated by equals - builder.parseArguments( - "start", - "--dir=" + expectedWorkingDirectory, - "--port=" + "12345", - "memberOne"); - - // then: the getters should return properly parsed values - assertThat(builder.getCommand()).isEqualTo(Command.START); - assertThat(builder.getDebug()).isFalse(); - assertThat(builder.getForce()).isFalse(); - assertThat(builder.getHelp()).isFalse(); - assertThat(builder.getBindAddress()).isNull(); - assertThat(builder.getHostnameForClients()).isNull(); - assertThat(builder.getMemberName()).isEqualTo("memberOne"); - assertThat(builder.getPid()).isNull(); - assertThat(builder.getWorkingDirectory()).isEqualTo(expectedWorkingDirectory); - assertThat(builder.getPort().intValue()).isEqualTo(12345); - } - - @Test - public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception { - // given: gemfire.properties with a name - Properties gemfireProperties = new Properties(); - gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "locator123"); - useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", gemfireProperties); - - // when: starting with null MemberName - LocatorLauncher launcher = new Builder() - .setCommand(Command.START) - .setMemberName(null) - .build(); - - // then: name in gemfire.properties file should be used for MemberName - assertThat(launcher).isNotNull(); - assertThat(launcher.getCommand()).isEqualTo(Command.START); - assertThat(launcher.getMemberName()).isNull(); - } - - @Test - public void testBuildWithNoMemberNameOnStart() throws Exception { - // given: gemfire.properties with no name - useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", new Properties()); - - // when: no MemberName is specified - when(new Builder() - .setCommand(Command.START)) - .build(); - - // then: throw IllegalStateException - then(caughtException()) - .isExactlyInstanceOf(IllegalStateException.class) - .hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Locator")); - } - - @Test - public void testBuilderSetAndGetWorkingDirectory() throws Exception { - // given: a new builder and a directory - String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath(); - Builder builder = new Builder(); - - // when: not setting WorkingDirectory - // then: getWorkingDirectory returns default - assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); - - // when: setting WorkingDirectory to null - assertThat(builder.setWorkingDirectory(null)).isSameAs(builder); - // then: getWorkingDirectory returns default - assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); - - // when: setting WorkingDirectory to empty string - assertThat(builder.setWorkingDirectory("")).isSameAs(builder); - // then: getWorkingDirectory returns default - assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); - - // when: setting WorkingDirectory to white space - assertThat(builder.setWorkingDirectory(" ")).isSameAs(builder); - // then: getWorkingDirectory returns default - assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); - - // when: setting WorkingDirectory to a directory - assertThat(builder.setWorkingDirectory(rootFolder)).isSameAs(builder); - // then: getWorkingDirectory returns that directory - assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder); - - // when: setting WorkingDirectory to null (again) - assertThat(builder.setWorkingDirectory(null)).isSameAs(builder); - // then: getWorkingDirectory returns default - assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); - } - - @Test - public void testBuilderSetWorkingDirectoryToFile() throws IOException { - // given: a file instead of a directory - File tmpFile = this.temporaryFolder.newFile(); - - // when: setting WorkingDirectory to that file - when(new Builder()) - .setWorkingDirectory(tmpFile.getCanonicalPath()); - - // then: throw IllegalArgumentException - then(caughtException()) - .isExactlyInstanceOf(IllegalArgumentException.class) - .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")) - .hasCause(new FileNotFoundException(tmpFile.getCanonicalPath())); - } - - @Test - public void testBuildSetWorkingDirectoryToNonCurrentDirectoryOnStart() throws Exception { - // given: using LocatorLauncher in-process - - // when: setting WorkingDirectory to non-current directory - when(new Builder() - .setCommand(Command.START) - .setMemberName("memberOne") - .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath())) - .build(); - - // then: throw IllegalStateException - then(caughtException()) - .isExactlyInstanceOf(IllegalStateException.class) - .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE.toLocalizedString("Locator")); - } - - @Test - public void testBuilderSetWorkingDirectoryToNonExistingDirectory() { - // when: setting WorkingDirectory to non-existing directory - when(new Builder()) - .setWorkingDirectory("/path/to/non_existing/directory"); - - // then: throw IllegalArgumentException - then(caughtException()) - .isExactlyInstanceOf(IllegalArgumentException.class) - .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")) - .hasCause(new FileNotFoundException("/path/to/non_existing/directory")); - } - - /** - * Creates a gemfire properties file in temporaryFolder: - * <ol> - * <li>creates <code>fileName</code> in <code>temporaryFolder</code></li> - * <li>sets "gemfirePropertyFile" system property</li> - * <li>writes <code>gemfireProperties</code> to the file</li> - * </ol> - */ - private void useGemFirePropertiesFileInTemporaryFolder(final String fileName, final Properties gemfireProperties) throws Exception { - File propertiesFile = new File(this.temporaryFolder.getRoot().getCanonicalPath(), fileName); - System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath()); - - gemfireProperties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName()); - assertThat(propertiesFile.isFile()).isTrue(); - assertThat(propertiesFile.exists()).isTrue(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationTest.java new file mode 100755 index 0000000..5f442a2 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherIntegrationTest.java @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.distributed; + +import static com.googlecode.catchexception.apis.BDDCatchException.*; +import static org.assertj.core.api.BDDAssertions.*; +import static org.assertj.core.api.BDDAssertions.then; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.net.InetAddress; +import java.util.Properties; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; +import org.junit.rules.TestName; + +import com.gemstone.gemfire.distributed.LocatorLauncher.Builder; +import com.gemstone.gemfire.distributed.LocatorLauncher.Command; +import com.gemstone.gemfire.distributed.internal.DistributionConfig; +import com.gemstone.gemfire.internal.i18n.LocalizedStrings; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; + +/** + * Integration tests for LocatorLauncher. These tests require file system I/O. + */ +@Category(IntegrationTest.class) +public class LocatorLauncherIntegrationTest { + + @Rule + public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); + + @Rule + public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public final TestName testName = new TestName(); + + @Test + public void testBuilderParseArgumentsWithValuesSeparatedWithCommas() throws Exception { + // given: a new builder and working directory + String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath(); + Builder builder = new Builder(); + + // when: parsing many arguments + builder.parseArguments( + "start", + "memberOne", + "--bind-address", InetAddress.getLocalHost().getHostAddress(), + "--dir", expectedWorkingDirectory, + "--hostname-for-clients", "Tucows", + "--pid", "1234", + "--port", "11235", + "--redirect-output", + "--force", + "--debug"); + + // then: the getters should return properly parsed values + assertThat(builder.getCommand()).isEqualTo(Command.START); + assertThat(builder.getBindAddress()).isEqualTo(InetAddress.getLocalHost()); + assertThat(builder.getWorkingDirectory()).isEqualTo(expectedWorkingDirectory); + assertThat(builder.getHostnameForClients()).isEqualTo("Tucows"); + assertThat(builder.getPid().intValue()).isEqualTo(1234); + assertThat(builder.getPort().intValue()).isEqualTo(11235); + assertThat(builder.getRedirectOutput()).isTrue(); + assertThat(builder.getForce()).isTrue(); + assertThat(builder.getDebug()).isTrue(); + } + + @Test + public void testBuilderParseArgumentsWithValuesSeparatedWithEquals() throws Exception { + // given: a new builder and a directory + String expectedWorkingDirectory = this.temporaryFolder.getRoot().getCanonicalPath(); + Builder builder = new Builder(); + + // when: parsing arguments with values separated by equals + builder.parseArguments( + "start", + "--dir=" + expectedWorkingDirectory, + "--port=" + "12345", + "memberOne"); + + // then: the getters should return properly parsed values + assertThat(builder.getCommand()).isEqualTo(Command.START); + assertThat(builder.getDebug()).isFalse(); + assertThat(builder.getForce()).isFalse(); + assertThat(builder.getHelp()).isFalse(); + assertThat(builder.getBindAddress()).isNull(); + assertThat(builder.getHostnameForClients()).isNull(); + assertThat(builder.getMemberName()).isEqualTo("memberOne"); + assertThat(builder.getPid()).isNull(); + assertThat(builder.getWorkingDirectory()).isEqualTo(expectedWorkingDirectory); + assertThat(builder.getPort().intValue()).isEqualTo(12345); + } + + @Test + public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception { + // given: gemfire.properties with a name + Properties gemfireProperties = new Properties(); + gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "locator123"); + useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", gemfireProperties); + + // when: starting with null MemberName + LocatorLauncher launcher = new Builder() + .setCommand(Command.START) + .setMemberName(null) + .build(); + + // then: name in gemfire.properties file should be used for MemberName + assertThat(launcher).isNotNull(); + assertThat(launcher.getCommand()).isEqualTo(Command.START); + assertThat(launcher.getMemberName()).isNull(); + } + + @Test + public void testBuildWithNoMemberNameOnStart() throws Exception { + // given: gemfire.properties with no name + useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", new Properties()); + + // when: no MemberName is specified + when(new Builder() + .setCommand(Command.START)) + .build(); + + // then: throw IllegalStateException + then(caughtException()) + .isExactlyInstanceOf(IllegalStateException.class) + .hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Locator")); + } + + @Test + public void testBuilderSetAndGetWorkingDirectory() throws Exception { + // given: a new builder and a directory + String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath(); + Builder builder = new Builder(); + + // when: not setting WorkingDirectory + // then: getWorkingDirectory returns default + assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); + + // when: setting WorkingDirectory to null + assertThat(builder.setWorkingDirectory(null)).isSameAs(builder); + // then: getWorkingDirectory returns default + assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); + + // when: setting WorkingDirectory to empty string + assertThat(builder.setWorkingDirectory("")).isSameAs(builder); + // then: getWorkingDirectory returns default + assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); + + // when: setting WorkingDirectory to white space + assertThat(builder.setWorkingDirectory(" ")).isSameAs(builder); + // then: getWorkingDirectory returns default + assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); + + // when: setting WorkingDirectory to a directory + assertThat(builder.setWorkingDirectory(rootFolder)).isSameAs(builder); + // then: getWorkingDirectory returns that directory + assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder); + + // when: setting WorkingDirectory to null (again) + assertThat(builder.setWorkingDirectory(null)).isSameAs(builder); + // then: getWorkingDirectory returns default + assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY); + } + + @Test + public void testBuilderSetWorkingDirectoryToFile() throws IOException { + // given: a file instead of a directory + File tmpFile = this.temporaryFolder.newFile(); + + // when: setting WorkingDirectory to that file + when(new Builder()) + .setWorkingDirectory(tmpFile.getCanonicalPath()); + + // then: throw IllegalArgumentException + then(caughtException()) + .isExactlyInstanceOf(IllegalArgumentException.class) + .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")) + .hasCause(new FileNotFoundException(tmpFile.getCanonicalPath())); + } + + @Test + public void testBuildSetWorkingDirectoryToNonCurrentDirectoryOnStart() throws Exception { + // given: using LocatorLauncher in-process + + // when: setting WorkingDirectory to non-current directory + when(new Builder() + .setCommand(Command.START) + .setMemberName("memberOne") + .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath())) + .build(); + + // then: throw IllegalStateException + then(caughtException()) + .isExactlyInstanceOf(IllegalStateException.class) + .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE.toLocalizedString("Locator")); + } + + @Test + public void testBuilderSetWorkingDirectoryToNonExistingDirectory() { + // when: setting WorkingDirectory to non-existing directory + when(new Builder()) + .setWorkingDirectory("/path/to/non_existing/directory"); + + // then: throw IllegalArgumentException + then(caughtException()) + .isExactlyInstanceOf(IllegalArgumentException.class) + .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")) + .hasCause(new FileNotFoundException("/path/to/non_existing/directory")); + } + + /** + * Creates a gemfire properties file in temporaryFolder: + * <ol> + * <li>creates <code>fileName</code> in <code>temporaryFolder</code></li> + * <li>sets "gemfirePropertyFile" system property</li> + * <li>writes <code>gemfireProperties</code> to the file</li> + * </ol> + */ + private void useGemFirePropertiesFileInTemporaryFolder(final String fileName, final Properties gemfireProperties) throws Exception { + File propertiesFile = new File(this.temporaryFolder.getRoot().getCanonicalPath(), fileName); + System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath()); + + gemfireProperties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName()); + assertThat(propertiesFile.isFile()).isTrue(); + assertThat(propertiesFile.exists()).isTrue(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java deleted file mode 100644 index a8ddd6a..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherJUnitTest.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gemstone.gemfire.distributed; - -import static org.junit.Assert.*; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import com.gemstone.gemfire.distributed.LocatorLauncher.Builder; -import com.gemstone.gemfire.distributed.LocatorLauncher.Command; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; -import com.gemstone.gemfire.internal.i18n.LocalizedStrings; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import joptsimple.OptionException; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.RestoreSystemProperties; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; - -/** - * The LocatorLauncherJUnitTest class is a test suite of test cases for testing the contract and functionality of - * launching a GemFire Locator. - * - * @see com.gemstone.gemfire.distributed.LocatorLauncher - * @see com.gemstone.gemfire.distributed.LocatorLauncher.Builder - * @see com.gemstone.gemfire.distributed.LocatorLauncher.Command - * @see org.junit.Assert - * @see org.junit.Test - * @since 7.0 - */ -@Category(UnitTest.class) -public class LocatorLauncherJUnitTest { - - @Rule - public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); - - @Rule - public final TestName testName = new TestName(); - - @Test(expected = IllegalArgumentException.class) - public void testBuilderParseArgumentsWithNonNumericPort() { - try { - new Builder().parseArguments("start", "locator1", "--port", "oneTwoThree"); - } - catch (IllegalArgumentException expected) { - assertTrue(expected.getCause() instanceof OptionException); - assertTrue(expected.getMessage(), expected.getMessage().contains( - LocalizedStrings.Launcher_Builder_PARSE_COMMAND_LINE_ARGUMENT_ERROR_MESSAGE.toLocalizedString( - "Locator", expected.getCause().getMessage()))); - throw expected; - } - } - - @Test - public void testForceDefaultsToFalse() { - assertFalse(new Builder().getForce()); - } - - @Test - public void testForceSetToTrue() { - Builder builder = new Builder(); - - builder.parseArguments("start", "--force"); - - assertTrue(Boolean.TRUE.equals(builder.getForce())); - } - - @Test - public void testSetAndGetCommand() { - final Builder builder = new Builder(); - - assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand()); - assertSame(builder, builder.setCommand(Command.START)); - assertEquals(Command.START, builder.getCommand()); - assertSame(builder, builder.setCommand(Command.STATUS)); - assertEquals(Command.STATUS, builder.getCommand()); - assertSame(builder, builder.setCommand(Command.STOP)); - assertEquals(Command.STOP, builder.getCommand()); - assertSame(builder, builder.setCommand(null)); - assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand()); - } - - @Test - public void testSetAndGetBindAddress() throws UnknownHostException { - final Builder builder = new Builder(); - - assertNull(builder.getBindAddress()); - assertSame(builder, builder.setBindAddress(null)); - assertNull(builder.getBindAddress()); - assertSame(builder, builder.setBindAddress("")); - assertNull(builder.getBindAddress()); - assertSame(builder, builder.setBindAddress(" ")); - assertNull(builder.getBindAddress()); - assertSame(builder, builder.setBindAddress(InetAddress.getLocalHost().getCanonicalHostName())); - assertEquals(InetAddress.getLocalHost(), builder.getBindAddress()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetBindAddressToUnknownHost() { - try { - new Builder().setBindAddress("badhostname.badcompany.bad"); - } - catch (IllegalArgumentException expected) { - final String expectedMessage1 = LocalizedStrings.Launcher_Builder_UNKNOWN_HOST_ERROR_MESSAGE.toLocalizedString("Locator"); - final String expectedMessage2 = "badhostname.badcompany.bad is not an address for this machine."; - assertTrue(expected.getMessage().equals(expectedMessage1) || expected.getMessage().equals(expectedMessage2)); - if (expected.getMessage().equals(expectedMessage1)) { - assertTrue(expected.getCause() instanceof UnknownHostException); - } - throw expected; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testSetBindAddressToNonLocalHost() { - try { - new Builder().setBindAddress("yahoo.com"); - } - catch (IllegalArgumentException expected) { - final String expectedMessage = "yahoo.com is not an address for this machine."; - assertEquals(expectedMessage, expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetBindAddressToLocalHost() throws Exception { - String host = InetAddress.getLocalHost().getHostName(); - new Builder().setBindAddress(host); - } - - @Test - public void testSetAndGetHostnameForClients() { - final Builder builder = new Builder(); - - assertNull(builder.getHostnameForClients()); - assertSame(builder, builder.setHostnameForClients("Pegasus")); - assertEquals("Pegasus", builder.getHostnameForClients()); - assertSame(builder, builder.setHostnameForClients(null)); - assertNull(builder.getHostnameForClients()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetHostnameForClientsWithBlankString() { - try { - new Builder().setHostnameForClients(" "); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.LocatorLauncher_Builder_INVALID_HOSTNAME_FOR_CLIENTS_ERROR_MESSAGE - .toLocalizedString(), expected.getMessage()); - throw expected; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testSetHostnameForClientsWithEmptyString() { - try { - new Builder().setHostnameForClients(""); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.LocatorLauncher_Builder_INVALID_HOSTNAME_FOR_CLIENTS_ERROR_MESSAGE - .toLocalizedString(), expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAndGetMemberName() { - Builder builder = new Builder(); - - assertNull(builder.getMemberName()); - assertSame(builder, builder.setMemberName("locatorOne")); - assertEquals("locatorOne", builder.getMemberName()); - assertSame(builder, builder.setMemberName(null)); - assertNull(builder.getMemberName()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetMemberNameWithBlankString() { - try { - new Builder().setMemberName(" "); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_ERROR_MESSAGE.toLocalizedString("Locator"), - expected.getMessage()); - throw expected; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testSetMemberNameWithEmptyString() { - try { - new Builder().setMemberName(""); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_ERROR_MESSAGE.toLocalizedString("Locator"), - expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAndGetPid() { - Builder builder = new Builder(); - - assertNull(builder.getPid()); - assertSame(builder, builder.setPid(0)); - assertEquals(0, builder.getPid().intValue()); - assertSame(builder, builder.setPid(1)); - assertEquals(1, builder.getPid().intValue()); - assertSame(builder, builder.setPid(1024)); - assertEquals(1024, builder.getPid().intValue()); - assertSame(builder, builder.setPid(12345)); - assertEquals(12345, builder.getPid().intValue()); - assertSame(builder, builder.setPid(null)); - assertNull(builder.getPid()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetPidToInvalidValue() { - try { - new Builder().setPid(-1); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.Launcher_Builder_PID_ERROR_MESSAGE.toLocalizedString(), expected.getMessage()); - throw expected; - } - } - - @SuppressWarnings("deprecation") - @Test - public void testSetAndGetPort() { - Builder builder = new Builder(); - - assertEquals(LocatorLauncher.DEFAULT_LOCATOR_PORT, builder.getPort()); - assertSame(builder, builder.setPort(65535)); - assertEquals(65535, builder.getPort().intValue()); - assertSame(builder, builder.setPort(1024)); - assertEquals(1024, builder.getPort().intValue()); - assertSame(builder, builder.setPort(80)); - assertEquals(80, builder.getPort().intValue()); - assertSame(builder, builder.setPort(1)); - assertEquals(1, builder.getPort().intValue()); - assertSame(builder, builder.setPort(0)); - assertEquals(0, builder.getPort().intValue()); - assertSame(builder, builder.setPort(null)); - assertEquals(LocatorLauncher.DEFAULT_LOCATOR_PORT, builder.getPort()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetPortToOverflow() { - try { - new Builder().setPort(65536); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.Launcher_Builder_INVALID_PORT_ERROR_MESSAGE.toLocalizedString("Locator"), - expected.getMessage()); - throw expected; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testSetPortToUnderflow() { - try { - new Builder().setPort(-1); - } - catch (IllegalArgumentException expected) { - assertEquals(LocalizedStrings.Launcher_Builder_INVALID_PORT_ERROR_MESSAGE.toLocalizedString("Locator"), - expected.getMessage()); - throw expected; - } - } - - @Test - public void testBuild() throws Exception { - Builder builder = new Builder(); - - LocatorLauncher launcher = builder.setCommand(Command.START) - .setDebug(true) - .setHostnameForClients("beanstock.vmware.com") - .setMemberName("Beanstock") - .setPort(8192) - .build(); - - assertNotNull(launcher); - assertEquals(builder.getCommand(), launcher.getCommand()); - assertTrue(launcher.isDebugging()); - assertEquals(builder.getHostnameForClients(), launcher.getHostnameForClients()); - assertEquals(builder.getMemberName(), launcher.getMemberName()); - assertEquals(builder.getPort(), launcher.getPort()); - assertEquals(builder.getWorkingDirectory(), launcher.getWorkingDirectory()); - assertFalse(launcher.isHelping()); - assertFalse(launcher.isRunning()); - } - - @Test - public void testBuildWithMemberNameSetInApiPropertiesOnStart() { - LocatorLauncher launcher = new Builder() - .setCommand(LocatorLauncher.Command.START) - .setMemberName(null) - .set(DistributionConfig.NAME_NAME, "locatorABC") - .build(); - - assertNotNull(launcher); - assertEquals(LocatorLauncher.Command.START, launcher.getCommand()); - assertNull(launcher.getMemberName()); - assertEquals("locatorABC", launcher.getProperties().getProperty(DistributionConfig.NAME_NAME)); - } - - @Test - public void testBuildWithMemberNameSetInSystemPropertiesOnStart() { - System.setProperty(DistributionConfig.GEMFIRE_PREFIX + DistributionConfig.NAME_NAME, "locatorXYZ"); - - LocatorLauncher launcher = new Builder() - .setCommand(LocatorLauncher.Command.START) - .setMemberName(null) - .build(); - - assertNotNull(launcher); - assertEquals(LocatorLauncher.Command.START, launcher.getCommand()); - assertNull(launcher.getMemberName()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java new file mode 100755 index 0000000..c695b07 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileIntegrationTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.distributed; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.internal.process.ProcessControllerFactory; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; + +/** + * Subclass of LocatorLauncherLocalDUnitTest which forces the code to not find + * the Attach API which is in the JDK tools.jar. As a result LocatorLauncher + * ends up using the FileProcessController implementation. + * + * @since 8.0 + */ +@Category(IntegrationTest.class) +public class LocatorLauncherLocalFileIntegrationTest extends LocatorLauncherLocalIntegrationTest { + + @Before + public final void setUpLocatorLauncherLocalFileIntegrationTest() throws Exception { + System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true"); + } + + @After + public final void tearDownLocatorLauncherLocalFileIntegrationTest() throws Exception { + } + + @Override + @Test + public void testIsAttachAPIFound() throws Exception { + final ProcessControllerFactory factory = new ProcessControllerFactory(); + assertFalse(factory.isAttachAPIFound()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileJUnitTest.java deleted file mode 100755 index 7dc5452..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherLocalFileJUnitTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gemstone.gemfire.distributed; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.gemstone.gemfire.internal.process.ProcessControllerFactory; - -/** - * Subclass of LocatorLauncherLocalDUnitTest which forces the code to not find - * the Attach API which is in the JDK tools.jar. As a result LocatorLauncher - * ends up using the FileProcessController implementation. - * - * @since 8.0 - */ -public class LocatorLauncherLocalFileJUnitTest extends LocatorLauncherLocalJUnitTest { - - @Before - public final void setUpLocatorLauncherLocalFileTest() throws Exception { - System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true"); - } - - @After - public final void tearDownLocatorLauncherLocalFileTest() throws Exception { - } - - @Override - @Test - public void testIsAttachAPIFound() throws Exception { - final ProcessControllerFactory factory = new ProcessControllerFactory(); - assertFalse(factory.isAttachAPIFound()); - } -}