geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kh...@apache.org
Subject [1/2] geode git commit: GEODE-2541: Fixed ClassCastException failure
Date Wed, 01 Mar 2017 21:45:48 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-2541 [created] 8e30938aa


GEODE-2541: Fixed ClassCastException failure

Fixed in HeadlessGfsh, and added new test for handling a command response
that's not a CommandResult object


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/b8953046
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/b8953046
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/b8953046

Branch: refs/heads/feature/GEODE-2541
Commit: b8953046cb0b32155ff8bce09890161a77bea473
Parents: f2262d1
Author: Ken Howe <khowe@pivotal.io>
Authored: Wed Mar 1 13:04:05 2017 -0800
Committer: Ken Howe <khowe@pivotal.io>
Committed: Wed Mar 1 13:04:05 2017 -0800

----------------------------------------------------------------------
 .../management/internal/cli/HeadlessGfsh.java   | 16 +++++
 .../cli/HeadlessGfshIntegrationTest.java        | 62 +++++++++++++++-----
 2 files changed, 64 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/b8953046/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
index 72be0c7..76e986d 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
@@ -15,6 +15,7 @@
 package org.apache.geode.management.internal.cli;
 
 import jline.console.ConsoleReader;
+import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.shell.GfshConfig;
 import org.apache.geode.management.internal.cli.shell.jline.GfshUnsupportedTerminal;
@@ -122,6 +123,13 @@ public class HeadlessGfsh implements ResultHandler {
     try {
       Object result = queue.poll(timeout, TimeUnit.SECONDS);
       queue.clear();
+      if (!(result instanceof org.apache.geode.management.internal.cli.result.CommandResult))
{
+        if (result == null) {
+          return ResultBuilder.createBadResponseErrorResult("command response was null");
+        } else {
+          return ResultBuilder.createBadResponseErrorResult(result.toString());
+        }
+      }
       return result;
     } catch (InterruptedException e) {
       e.printStackTrace();
@@ -159,6 +167,14 @@ public class HeadlessGfsh implements ResultHandler {
     return shell.errorString;
   }
 
+  /**
+   * Method for tests to access the results queue
+   *
+   */
+  LinkedBlockingQueue getQueue() {
+    return queue;
+  }
+
   public static class HeadlessGfshShell extends Gfsh {
 
     private ResultHandler handler = null;

http://git-wip-us.apache.org/repos/asf/geode/blob/b8953046/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfshIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfshIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfshIntegrationTest.java
index 2ea8d99..c183377 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfshIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfshIntegrationTest.java
@@ -14,10 +14,24 @@
  */
 package org.apache.geode.management.internal.cli;
 
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.internal.AvailablePort.SOCKET;
+import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -26,18 +40,17 @@ import org.junit.rules.TestName;
 
 import java.io.IOException;
 import java.util.Properties;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePort.SOCKET;
-import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import java.util.concurrent.LinkedBlockingQueue;
 
 /**
  * TODO : Add more tests for error-catch, different type of results etc
  */
 @Category(IntegrationTest.class)
 public class HeadlessGfshIntegrationTest {
+  private int port;
+  private DistributedSystem ds;
+  private GemFireCacheImpl cache;
+  private HeadlessGfsh gfsh;
 
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -45,11 +58,9 @@ public class HeadlessGfshIntegrationTest {
   @Rule
   public TestName testName = new TestName();
 
-  @SuppressWarnings({"deprecation"})
-  @Test
-  public void testHeadlessGfshTest()
-      throws ClassNotFoundException, IOException, InterruptedException {
-    int port = getRandomAvailablePort(SOCKET);
+  @Before
+  public void setup() throws IOException, ClassNotFoundException {
+    port = getRandomAvailablePort(SOCKET);
 
     Properties properties = new Properties();
     properties.put(NAME, this.testName.getMethodName());
@@ -59,11 +70,17 @@ public class HeadlessGfshIntegrationTest {
     properties.put(HTTP_SERVICE_PORT, "0");
     properties.put(MCAST_PORT, "0");
 
-    DistributedSystem ds = DistributedSystem.connect(properties);
-    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.create(ds);
+    ds = DistributedSystem.connect(properties);
+    cache = (GemFireCacheImpl) CacheFactory.create(ds);
 
-    HeadlessGfsh gfsh = new HeadlessGfsh("Test", 25,
+    gfsh = new HeadlessGfsh("Test", 25,
         this.temporaryFolder.newFolder("gfsh_files").getCanonicalPath());
+  }
+
+  @SuppressWarnings({"deprecation"})
+  @Test
+  public void testHeadlessGfshTest() throws InterruptedException {
+
     for (int i = 0; i < 5; i++) {
       gfsh.executeCommand("connect --jmx-manager=localhost[" + port + "]");
       Object result = gfsh.getResult();
@@ -88,4 +105,21 @@ public class HeadlessGfshIntegrationTest {
     ds.disconnect();
   }
 
+  @SuppressWarnings({"deprecation"})
+  @Test
+  public void testStringResultReturnedAsCommandResult() throws InterruptedException {
+    gfsh.clear();
+    gfsh.executeCommand("list members");
+
+    LinkedBlockingQueue headlessQueue = gfsh.getQueue();
+    headlessQueue.clear();
+    headlessQueue.put("ERROR RESULT");
+    Object result = gfsh.getResult();
+    assertNotNull(result);
+    assertTrue(((CommandResult) result).getStatus() == Result.Status.ERROR);
+    System.out.println(((CommandResult) result).toString());
+    gfsh.terminate();
+    cache.close();
+    ds.disconnect();
+  }
 }


Mime
View raw message