You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2018/04/19 16:37:35 UTC

[geode] branch develop updated: GEODE-5095: Fix output for create gateway-receiver (port number) (#1816)

This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new e358ce0  GEODE-5095: Fix output for create gateway-receiver (port number) (#1816)
e358ce0 is described below

commit e358ce09564df22b65a46be0dc50b6c38cfd2d51
Author: Sai Boorlagadda <sa...@gmail.com>
AuthorDate: Thu Apr 19 09:37:30 2018 -0700

    GEODE-5095: Fix output for create gateway-receiver (port number) (#1816)
---
 .../functions/GatewayReceiverCreateFunction.java   | 32 +++++-----
 .../GatewayReceiverCreateFunctionTest.java         | 73 ++++++++++++++++++++++
 2 files changed, 91 insertions(+), 14 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java
index 905b200..286b5a5 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunction.java
@@ -80,22 +80,11 @@ public class GatewayReceiverCreateFunction implements InternalFunction {
       GatewayReceiver createdGatewayReceiver =
           createGatewayReceiver(cache, gatewayReceiverCreateArgs);
 
-      Map<String, String> attributes = new HashMap<>();
-      if (gatewayReceiverCreateArgs.getStartPort() != null) {
-        attributes.put("start-port", gatewayReceiverCreateArgs.getStartPort().toString());
-      }
-      if (gatewayReceiverCreateArgs.getEndPort() != null) {
-        attributes.put("end-port", gatewayReceiverCreateArgs.getEndPort().toString());
-      }
-      if (gatewayReceiverCreateArgs.getBindAddress() != null) {
-        attributes.put("bind-address", gatewayReceiverCreateArgs.getBindAddress());
-      }
-      XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.GATEWAY_RECEIVER)
-          .withAttributes(attributes).build();
+      XmlEntity xmlEntity = getXmlEntity(gatewayReceiverCreateArgs);
       resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity,
           CliStrings.format(
               CliStrings.CREATE_GATEWAYRECEIVER__MSG__GATEWAYRECEIVER_CREATED_ON_0_ONPORT_1,
-              memberNameOrId, createdGatewayReceiver.getPort())));
+              memberNameOrId, Integer.toString(createdGatewayReceiver.getPort()))));
     } catch (IllegalStateException e) {
       // no need to log the stack trace
       resultSender.lastResult(new CliFunctionResult(memberNameOrId, e, e.getMessage()));
@@ -106,6 +95,21 @@ public class GatewayReceiverCreateFunction implements InternalFunction {
 
   }
 
+  XmlEntity getXmlEntity(GatewayReceiverFunctionArgs gatewayReceiverCreateArgs) {
+    Map<String, String> attributes = new HashMap<>();
+    if (gatewayReceiverCreateArgs.getStartPort() != null) {
+      attributes.put("start-port", gatewayReceiverCreateArgs.getStartPort().toString());
+    }
+    if (gatewayReceiverCreateArgs.getEndPort() != null) {
+      attributes.put("end-port", gatewayReceiverCreateArgs.getEndPort().toString());
+    }
+    if (gatewayReceiverCreateArgs.getBindAddress() != null) {
+      attributes.put("bind-address", gatewayReceiverCreateArgs.getBindAddress());
+    }
+    return XmlEntity.builder().withType(CacheXml.GATEWAY_RECEIVER).withAttributes(attributes)
+        .build();
+  }
+
   /** GatewayReceiver creation happens here. */
   GatewayReceiver createGatewayReceiver(Cache cache,
       GatewayReceiverFunctionArgs gatewayReceiverCreateArgs)
@@ -168,7 +172,7 @@ public class GatewayReceiverCreateFunction implements InternalFunction {
     return ClassPathLoader.getLatest().forName(className).newInstance();
   }
 
-  private boolean gatewayReceiverExists(Cache cache) {
+  boolean gatewayReceiverExists(Cache cache) {
     return cache.getGatewayReceivers() != null && !cache.getGatewayReceivers().isEmpty();
   }
 
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunctionTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunctionTest.java
new file mode 100644
index 0000000..28e17be
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GatewayReceiverCreateFunctionTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.functions;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.ArgumentCaptor;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.cache.wan.GatewayReceiver;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class GatewayReceiverCreateFunctionTest {
+
+  private GatewayReceiverCreateFunction function = mock(GatewayReceiverCreateFunction.class);
+
+  private FunctionContext context = mock(FunctionContext.class);
+  private Cache cache = mock(Cache.class);
+  private GatewayReceiverFunctionArgs args = mock(GatewayReceiverFunctionArgs.class);
+  private GatewayReceiver receiver = mock(GatewayReceiver.class);
+  private ResultSender resultSender = mock(ResultSender.class);
+
+  @Before
+  public void setup()
+      throws IllegalAccessException, ClassNotFoundException, InstantiationException {
+    doReturn(cache).when(context).getCache();
+    doReturn(args).when(context).getArguments();
+    doReturn("server-1").when(context).getMemberName();
+    doReturn(resultSender).when(context).getResultSender();
+
+    doCallRealMethod().when(function).execute(context);
+    doReturn(false).when(function).gatewayReceiverExists(any());
+    doReturn(receiver).when(function).createGatewayReceiver(cache, args);
+    doReturn(null).when(function).getXmlEntity(args);
+
+    doReturn(5555).when(receiver).getPort();
+  }
+
+  @Test
+  public void testFunctionSuccessResult() {
+    function.execute(context);
+    ArgumentCaptor<Object> resultObject = ArgumentCaptor.forClass(Object.class);
+    verify(resultSender, times(1)).lastResult(resultObject.capture());
+
+    CliFunctionResult result = (CliFunctionResult) resultObject.getValue();
+
+    assertThat(result.getStatus()).contains("5555");
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
sai_boorlagadda@apache.org.