geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [17/47] geode git commit: GEODE-3436: Restore refactoring of Refactoring MiscellaneousCommands
Date Thu, 31 Aug 2017 01:25:54 GMT
http://git-wip-us.apache.org/repos/asf/geode/blob/611095f0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
index f0c2c2f..674a0b6 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
@@ -14,9 +14,34 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
 
-import org.apache.geode.cache.*;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.lang.ThreadUtils;
@@ -24,27 +49,22 @@ import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.cli.Result.Status;
 import org.apache.geode.management.internal.cli.HeadlessGfsh;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.*;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.result.CompositeResultData;
 import org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.management.internal.cli.result.ResultBuilder;
+import org.apache.geode.management.internal.cli.result.ResultData;
+import org.apache.geode.management.internal.cli.result.TabularResultData;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
-import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
 
 /**
- * Dunit class for testing gemfire function commands : GC, Shutdown
+ * DUnit class for testing gemfire function commands : GC, Shutdown
  */
 @Category(DistributedTest.class)
 public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
@@ -75,20 +95,15 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     String command = "gc --group=Group1";
     CommandResult cmdResult = executeCommand(command);
     cmdResult.resetToFirstLine();
-    if (cmdResult != null) {
-      String cmdResultStr = commandResultToString(cmdResult);
-      getLogWriter()
-          .info("testGCForGroup cmdResultStr=" + cmdResultStr + "; cmdResult=" + cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
-        TabularResultData table = (TabularResultData) cmdResult.getResultData();
-        List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
-        assertEquals(true, memberNames.size() == 1);
-      } else {
-        fail("testGCForGroup failed as CommandResult should be table type");
-      }
+    String cmdResultStr = commandResultToString(cmdResult);
+    getLogWriter().info("testGCForGroup cmdResultStr=" + cmdResultStr + "; cmdResult=" +
cmdResult);
+    assertEquals(Status.OK, cmdResult.getStatus());
+    if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
+      TabularResultData table = (TabularResultData) cmdResult.getResultData();
+      List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
+      assertEquals(true, memberNames.size() == 1);
     } else {
-      fail("testGCForGroup failed as did not get CommandResult");
+      fail("testGCForGroup failed as CommandResult should be table type");
     }
   }
 
@@ -101,23 +116,19 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
   public void testGCForMemberID() {
     setUpJmxManagerOnVm0ThenConnect(null);
     final VM vm1 = Host.getHost(0).getVM(1);
-    final String vm1MemberId = vm1.invoke(() -> getMemberId());
+    final String vm1MemberId = vm1.invoke(this::getMemberId);
     String command = "gc --member=" + vm1MemberId;
     CommandResult cmdResult = executeCommand(command);
     cmdResult.resetToFirstLine();
-    if (cmdResult != null) {
-      String cmdResultStr = commandResultToString(cmdResult);
-      getLogWriter().info("testGCForMemberID cmdResultStr=" + cmdResultStr);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
-        TabularResultData table = (TabularResultData) cmdResult.getResultData();
-        List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
-        assertEquals(true, memberNames.size() == 1);
-      } else {
-        fail("testGCForGroup failed as CommandResult should be table type");
-      }
+    String cmdResultStr = commandResultToString(cmdResult);
+    getLogWriter().info("testGCForMemberID cmdResultStr=" + cmdResultStr);
+    assertEquals(Status.OK, cmdResult.getStatus());
+    if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
+      TabularResultData table = (TabularResultData) cmdResult.getResultData();
+      List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
+      assertEquals(true, memberNames.size() == 1);
     } else {
-      fail("testGCForCluster failed as did not get CommandResult");
+      fail("testGCForGroup failed as CommandResult should be table type");
     }
   }
 
@@ -128,7 +139,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
       props.setProperty(LOG_FILE, "testShowLogDefault.log");
       setUpJmxManagerOnVm0ThenConnect(props);
       final VM vm1 = Host.getHost(0).getVM(0);
-      final String vm1MemberId = vm1.invoke(() -> getMemberId());
+      final String vm1MemberId = vm1.invoke(this::getMemberId);
       String command = "show log --member=" + vm1MemberId;
       CommandResult cmdResult = executeCommand(command);
       if (cmdResult != null) {
@@ -152,7 +163,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     try {
       setUpJmxManagerOnVm0ThenConnect(props);
       final VM vm1 = Host.getHost(0).getVM(0);
-      final String vm1MemberId = vm1.invoke(() -> getMemberId());
+      final String vm1MemberId = vm1.invoke(this::getMemberId);
       String command = "show log --member=" + vm1MemberId + " --lines=50";
       CommandResult cmdResult = executeCommand(command);
       if (cmdResult != null) {
@@ -174,24 +185,20 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     String command = "gc";
     CommandResult cmdResult = executeCommand(command);
     cmdResult.resetToFirstLine();
-    if (cmdResult != null) {
-      String cmdResultStr = commandResultToString(cmdResult);
-      getLogWriter()
-          .info("testGCForEntireCluster cmdResultStr=" + cmdResultStr + "; cmdResult=" +
cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
-        TabularResultData table = (TabularResultData) cmdResult.getResultData();
-        List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
-        assertEquals(3, memberNames.size());
-      } else {
-        fail("testGCForGroup failed as CommandResult should be table type");
-      }
+    String cmdResultStr = commandResultToString(cmdResult);
+    getLogWriter()
+        .info("testGCForEntireCluster cmdResultStr=" + cmdResultStr + "; cmdResult=" + cmdResult);
+    assertEquals(Status.OK, cmdResult.getStatus());
+    if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
+      TabularResultData table = (TabularResultData) cmdResult.getResultData();
+      List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
+      assertEquals(3, memberNames.size());
     } else {
-      fail("testGCForGroup failed as did not get CommandResult");
+      fail("testGCForGroup failed as CommandResult should be table type");
     }
   }
 
-  void setupForGC() {
+  private void setupForGC() {
     disconnectAllFromDS();
 
     final VM vm1 = Host.getHost(0).getVM(1);
@@ -307,7 +314,6 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
       }
     });
 
-
     String command = "shutdown --time-out=15";
     CommandResult cmdResult = executeCommand(command);
 
@@ -326,7 +332,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     });
   }
 
-  void setupForChangeLogLelvel() {
+  private void setupForChangeLogLevel() {
     final VM vm0 = Host.getHost(0).getVM(0);
     final VM vm1 = Host.getHost(0).getVM(1);
 
@@ -346,7 +352,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     });
   }
 
-  void setupForShutDown() {
+  private void setupForShutDown() {
     final VM vm0 = Host.getHost(0).getVM(0);
     final VM vm1 = Host.getHost(0).getVM(1);
 
@@ -367,7 +373,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     });
   }
 
-  void verifyShutDown() {
+  private void verifyShutDown() {
     final VM vm0 = Host.getHost(0).getVM(0);
     final VM vm1 = Host.getHost(0).getVM(1);
 
@@ -410,7 +416,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase
{
     final VM vm0 = Host.getHost(0).getVM(0);
     final VM vm1 = Host.getHost(0).getVM(1);
 
-    setupForChangeLogLelvel();
+    setupForChangeLogLevel();
 
     String serverName1 = (String) vm0.invoke(new SerializableCallable() {
       @Override

http://git-wip-us.apache.org/repos/asf/geode/blob/611095f0/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
index 8635306..43c5e95 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
@@ -160,8 +160,8 @@ public class GfshCommandsSecurityTest {
         continue;
       }
 
-      assertThat(ResultBuilder.ERRORCODE_UNAUTHORIZED).describedAs(other.getCommand())
-          .isEqualTo(((ErrorResultData) result.getResultData()).getErrorCode());
+      assertThat(((ErrorResultData) result.getResultData()).getErrorCode())
+          .describedAs(other.getCommand()).isEqualTo(ResultBuilder.ERRORCODE_UNAUTHORIZED);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/611095f0/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java
b/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java
index e0d13b6..038e8cf 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/TestCommand.java
@@ -185,7 +185,14 @@ public class TestCommand {
     createTestCommand("import cluster-configuration --zip-file-name=value.zip", clusterManage);
 
     // DestroyFunctionCommand, ExecuteFunctionCommand, ListFunctionCommand
-    createTestCommand("destroy function --id=InterestCalculations", dataManage);
+    // TODO PSR: the `destroy function` command is interactive (in its interceptor) when
both
+    // onGroup == null && onMember == null.
+    // This causes the function to throw
+    // CODE_SHELLCLIENT_ABORT_OP = 110;
+    // instead of the expected
+    // ERRORCODE_UNAUTHORIZED = 415;
+    // TODO: Should authorization occur before the interceptor resolves?
+    // createTestCommand("destroy function --id=InterestCalculations", dataManage);
     createTestCommand("execute function --id=InterestCalculations --groups=Group1", dataWrite);
     createTestCommand("list functions", clusterRead);
 


Mime
View raw message