This is an automated email from the ASF dual-hosted git repository. sai_boorlagadda pushed a commit to branch startlocator_command_tests in repository https://gitbox.apache.org/repos/asf/geode.git
commit e084d4ee9e97fd035baa3ed82c11560592291fc8 Author: Sai Boorlagadda <[email protected]> AuthorDate: Mon Oct 8 13:08:48 2018 -0700 added startServer command unit tests --- .../cli/commands/StartServerCommandDUnitTest.java | 32 +---- .../StartLocatorCommandWorkingDirectoryTest.java | 3 - .../StartServerCommandWorkingDirectoryTest.java | 146 +++++++++++++++++++++ .../internal/cli/commands/StartMemberUtils.java | 2 +- .../internal/cli/commands/StartServerCommand.java | 38 +++++- 5 files changed, 185 insertions(+), 36 deletions(-) diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartServerCommandDUnitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartServerCommandDUnitTest.java index 2d884c1..eb75315 100644 --- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartServerCommandDUnitTest.java +++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/StartServerCommandDUnitTest.java @@ -41,7 +41,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.nio.file.Paths; -import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -67,6 +66,7 @@ import org.apache.geode.test.dunit.rules.ClusterStartupRule; import org.apache.geode.test.dunit.rules.MemberVM; import org.apache.geode.test.dunit.rules.SharedErrorCollector; import org.apache.geode.test.junit.rules.GfshCommandRule; +import org.apache.geode.test.junit.rules.RequiresGeodeHome; public class StartServerCommandDUnitTest { @@ -78,6 +78,9 @@ public class StartServerCommandDUnitTest { private int serverPort; @ClassRule + public static RequiresGeodeHome requiresGeodeHome = new RequiresGeodeHome(); + + @ClassRule public static ClusterStartupRule cluster = new ClusterStartupRule(); @ClassRule @@ -240,33 +243,6 @@ public class StartServerCommandDUnitTest { } @Test - public void testWithMissingStartDirectoryThatCanBeCreated() { - // path to a missing dir that can be created - String readWritePathname = "readWriteDir"; - File readWriteDir = new File(readWritePathname); - String missingDirPath = - Paths.get(readWritePathname, "missing", "dir", "to", "start", "in").toString(); - - String expectedMessage = "Server in .*" + missingDirPath.replace("\\", "\\\\"); - - String command = new CommandStringBuilder(START_SERVER) - .addOption(START_SERVER__NAME, memberName) - .addOption(START_SERVER__LOCATORS, locatorConnectionString) - .addOption(START_SERVER__SERVER_PORT, String.valueOf(serverPort)) - .addOption(START_SERVER__DIR, missingDirPath) - .getCommandString(); - - try { - CommandResult result = gfsh.executeCommand(command); - - assertThat(result.getStatus()).isEqualTo(Result.Status.OK); - assertThat(result.getMessageFromContent()).containsPattern(expectedMessage); - } finally { - FileUtils.deleteQuietly(readWriteDir); - } - } - - @Test public void testWithConflictingPIDFile() throws Exception { String fileName = ProcessType.SERVER.getPidFileName(); diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandWorkingDirectoryTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandWorkingDirectoryTest.java index bb4c751..5e0b75f 100644 --- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandWorkingDirectoryTest.java +++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommandWorkingDirectoryTest.java @@ -24,9 +24,6 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import java.io.File; -import java.io.IOException; - -import javax.management.MalformedObjectNameException; import org.junit.Before; import org.junit.Test; diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandWorkingDirectoryTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandWorkingDirectoryTest.java new file mode 100644 index 0000000..e756865 --- /dev/null +++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/StartServerCommandWorkingDirectoryTest.java @@ -0,0 +1,146 @@ +/* + * 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 org.apache.geode.management.internal.cli.commands; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import java.io.File; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; + +public class StartServerCommandWorkingDirectoryTest { + + private String memberName; + private String workingDirectory; + private StartServerCommand startServerCommand; + private ArgumentCaptor<String> workingDirectoryCaptor; + + @Before + public void setUp() throws Exception { + memberName = "server1"; + startServerCommand = spy(new StartServerCommand()); + + doReturn(null).when(startServerCommand) + .doStartServer(anyString(), anyBoolean(), isNull(), isNull(), isNull(), anyFloat(), + anyFloat(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyFloat(), + anyFloat(), anyBoolean(), isNull(), isNull(), isNull(), anyBoolean(), isNull(), + isNull(), isNull(), anyInt(), anyBoolean(), isNull(), anyInt(), isNull(), anyInt(), + anyInt(), isNull(), anyInt(), anyInt(), isNull(), isNull(), anyInt(), isNull(), + isNull(), anyInt(), isNull(), isNull(), anyBoolean(), isNull(), isNull(), anyInt(), + anyInt(), isNull(), isNull(), anyBoolean(), anyBoolean(), isNull(), isNull(), isNull(), + isNull(), anyBoolean()); + + workingDirectoryCaptor = ArgumentCaptor.forClass(String.class); + } + + @Test + public void startLocatorWithRelativeWorkingDirectory() throws Exception { + workingDirectory = "server1Directory"; + + startServerCommand + .startServer(memberName, false, null, null, null, 0.0f, 0.0f, workingDirectory, false, + false, false, 0.0f, 0.0f, false, null, null, null, false, null, null, null, 0, false, + null, 0, null, 0, 0, null, 0, 0, null, null, 0, null, null, 0, null, null, false, null, + null, 0, 0, null, null, false, false, null, null, null, null, false); + + verifyDoStartServerInvoked(); + + assertThat(workingDirectoryCaptor.getValue()) + .isEqualTo(new File(workingDirectory).getAbsolutePath()); + } + + @Test + public void startServerWithNullWorkingDirectory() throws Exception { + workingDirectory = null; + + startServerCommand + .startServer(memberName, false, null, null, null, 0.0f, 0.0f, workingDirectory, false, + false, false, 0.0f, 0.0f, false, null, null, null, false, null, null, null, 0, false, + null, 0, null, 0, 0, null, 0, 0, null, null, 0, null, null, 0, null, null, false, null, + null, 0, 0, null, null, false, false, null, null, null, null, false); + + verifyDoStartServerInvoked(); + + assertThat(workingDirectoryCaptor.getValue()).isEqualTo(new File(memberName).getAbsolutePath()); + } + + @Test + public void startServerWithEmptyWorkingDirectory() throws Exception { + workingDirectory = ""; + + startServerCommand + .startServer(memberName, false, null, null, null, 0.0f, 0.0f, workingDirectory, false, + false, false, 0.0f, 0.0f, false, null, null, null, false, null, null, null, 0, false, + null, 0, null, 0, 0, null, 0, 0, null, null, 0, null, null, 0, null, null, false, null, + null, 0, 0, null, null, false, false, null, null, null, null, false); + + verifyDoStartServerInvoked(); + + assertThat(workingDirectoryCaptor.getValue()).isEqualTo(new File(memberName).getAbsolutePath()); + } + + @Test + public void startServerWithDotWorkingDirectory() throws Exception { + workingDirectory = "."; + + startServerCommand + .startServer(memberName, false, null, null, null, 0.0f, 0.0f, workingDirectory, false, + false, false, 0.0f, 0.0f, false, null, null, null, false, null, null, null, 0, false, + null, 0, null, 0, 0, null, 0, 0, null, null, 0, null, null, 0, null, null, false, null, + null, 0, 0, null, null, false, false, null, null, null, null, false); + + verifyDoStartServerInvoked(); + + assertThat(workingDirectoryCaptor.getValue()) + .isEqualTo(StartMemberUtils.resolveWorkingDir(new File("."), new File(memberName))); + } + + @Test + public void startServerWithAbsoluteWorkingDirectory() throws Exception { + workingDirectory = new File(System.getProperty("user.dir")).getAbsolutePath(); + + startServerCommand + .startServer(memberName, false, null, null, null, 0.0f, 0.0f, workingDirectory, false, + false, false, 0.0f, 0.0f, false, null, null, null, false, null, null, null, 0, false, + null, 0, null, 0, 0, null, 0, 0, null, null, 0, null, null, 0, null, null, false, null, + null, 0, 0, null, null, false, false, null, null, null, null, false); + + verifyDoStartServerInvoked(); + + assertThat(workingDirectoryCaptor.getValue()).isEqualTo(workingDirectory); + } + + private void verifyDoStartServerInvoked() throws Exception { + verify(startServerCommand) + .doStartServer(anyString(), anyBoolean(), isNull(), isNull(), isNull(), anyFloat(), + anyFloat(), workingDirectoryCaptor.capture(), anyBoolean(), anyBoolean(), anyBoolean(), + anyFloat(), anyFloat(), anyBoolean(), isNull(), isNull(), isNull(), anyBoolean(), + isNull(), isNull(), isNull(), anyInt(), anyBoolean(), isNull(), anyInt(), isNull(), + anyInt(), anyInt(), isNull(), anyInt(), anyInt(), isNull(), isNull(), anyInt(), + isNull(), isNull(), anyInt(), isNull(), isNull(), anyBoolean(), isNull(), isNull(), + anyInt(), anyInt(), isNull(), isNull(), anyBoolean(), anyBoolean(), isNull(), isNull(), + isNull(), isNull(), anyBoolean()); + } +} diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java index 7116ed8..d425187 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java @@ -71,7 +71,7 @@ public class StartMemberUtils { } static String resolveWorkingDir(File userSpecifiedDir, File memberNameDir) { - //TODO: see if file has some APIs to do equals + // TODO: see if file has some APIs to do equals File workingDir = (userSpecifiedDir == null || userSpecifiedDir.equals(new File(""))) ? memberNameDir : userSpecifiedDir; diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java index 5ac18fc..e5c5e4f 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java @@ -16,6 +16,7 @@ package org.apache.geode.management.internal.cli.commands; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -201,6 +202,37 @@ public class StartServerCommand extends InternalGfshCommand { workingDirectory = StartMemberUtils.resolveWorkingDir( workingDirectory == null ? null : new File(workingDirectory), new File(memberName)); + return doStartServer(memberName, assignBuckets, bindAddress, cacheXmlPathname, classpath, + criticalHeapPercentage, criticalOffHeapPercentage, workingDirectory, disableDefaultServer, + disableExitWhenOutOfMemory, enableTimeStatistics, evictionHeapPercentage, + evictionOffHeapPercentage, force, group, hostNameForClients, jmxManagerHostnameForClients, + includeSystemClasspath, initialHeap, jvmArgsOpts, locators, locatorWaitTime, lockMemory, + logLevel, maxConnections, maxHeap, maxMessageCount, maxThreads, mcastBindAddress, mcastPort, + memcachedPort, memcachedProtocol, memcachedBindAddress, redisPort, redisBindAddress, + redisPassword, messageTimeToLive, offHeapMemorySize, gemfirePropertiesFile, rebalance, + gemfireSecurityPropertiesFile, serverBindAddress, serverPort, socketBufferSize, + springXmlLocation, statisticsArchivePathname, requestSharedConfiguration, startRestApi, + httpServicePort, httpServiceBindAddress, userName, passwordToUse, redirectOutput); + } + + Result doStartServer(String memberName, Boolean assignBuckets, String bindAddress, + String cacheXmlPathname, String classpath, Float criticalHeapPercentage, + Float criticalOffHeapPercentage, String workingDirectory, Boolean disableDefaultServer, + Boolean disableExitWhenOutOfMemory, Boolean enableTimeStatistics, + Float evictionHeapPercentage, Float evictionOffHeapPercentage, Boolean force, String group, + String hostNameForClients, String jmxManagerHostnameForClients, + Boolean includeSystemClasspath, String initialHeap, String[] jvmArgsOpts, String locators, + Integer locatorWaitTime, Boolean lockMemory, String logLevel, Integer maxConnections, + String maxHeap, Integer maxMessageCount, Integer maxThreads, String mcastBindAddress, + Integer mcastPort, Integer memcachedPort, String memcachedProtocol, + String memcachedBindAddress, Integer redisPort, String redisBindAddress, String redisPassword, + Integer messageTimeToLive, String offHeapMemorySize, File gemfirePropertiesFile, + Boolean rebalance, File gemfireSecurityPropertiesFile, String serverBindAddress, + Integer serverPort, Integer socketBufferSize, String springXmlLocation, + String statisticsArchivePathname, Boolean requestSharedConfiguration, Boolean startRestApi, + String httpServicePort, String httpServiceBindAddress, String userName, String passwordToUse, + Boolean redirectOutput) + throws MalformedObjectNameException, IOException, InterruptedException { cacheXmlPathname = CliUtil.resolvePathname(cacheXmlPathname); if (StringUtils.isNotBlank(cacheXmlPathname)) { @@ -378,10 +410,8 @@ public class StartServerCommand extends InternalGfshCommand { } while (!(registeredServerSignalListener && serverSignalListener.isSignaled()) && serverState.isStartingOrNotResponding()); } finally { - stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS); // stop - // will - // close - // ErrorStream + stderrReader.stopAsync(StartMemberUtils.PROCESS_STREAM_READER_ASYNC_STOP_TIMEOUT_MILLIS); + // stop will close ErrorStream getGfsh().getSignalHandler().unregisterListener(serverSignalListener); }
