ListGatewayCommand extends GfshCommand { protected void accumulateListGatewayResult(ResultModel result, Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans, Map<String, GatewayReceiverMXBean> gatewayReceiverBeans) { if (!gatewaySenderBeans.isEmpty()) { TabularResultModel gatewaySenders = result.addTable("gatewaySenders"); gatewaySenders.setHeader(CliStrings.SECTION_GATEWAY_SENDER); for (Map.Entry<String, Map<String, GatewaySenderMXBean>> entry : gatewaySenderBeans .entrySet()) { for (Map.Entry<String, GatewaySenderMXBean> memberToBean : entry.getValue().entrySet()) { gatewaySenders.accumulate(CliStrings.RESULT_GATEWAY_SENDER_ID, entry.getKey()); gatewaySenders.accumulate(CliStrings.RESULT_HOST_MEMBER, memberToBean.getKey()); gatewaySenders.accumulate(CliStrings.RESULT_REMOTE_CLUSTER, memberToBean.getValue().getRemoteDSId() + ""); gatewaySenders.accumulate(CliStrings.RESULT_TYPE, memberToBean.getValue().isParallel() ? CliStrings.SENDER_PARALLEL : CliStrings.SENDER_SERIAL); gatewaySenders.accumulate(CliStrings.RESULT_STATUS, getStatus(memberToBean.getValue())); gatewaySenders.accumulate(CliStrings.RESULT_QUEUED_EVENTS, memberToBean.getValue().getEventQueueSize() + ""); gatewaySenders.accumulate(CliStrings.RESULT_RECEIVER, memberToBean.getValue().getGatewayReceiver()); } } } if (!gatewayReceiverBeans.isEmpty()) { TabularResultModel gatewaySenders = result.addTable("gatewayReceivers"); gatewaySenders.setHeader(CliStrings.SECTION_GATEWAY_RECEIVER); for (Map.Entry<String, GatewayReceiverMXBean> entry : gatewayReceiverBeans.entrySet()) { gatewaySenders.accumulate(CliStrings.RESULT_HOST_MEMBER, entry.getKey()); gatewaySenders.accumulate(CliStrings.RESULT_PORT, entry.getValue().getPort() + ""); gatewaySenders.accumulate(CliStrings.RESULT_SENDERS_COUNT, entry.getValue().getClientConnectionCount() + ""); if (entry.getValue() == null || entry.getValue().getConnectedGatewaySenders() == null) { gatewaySenders.accumulate(CliStrings.RESULT_SENDER_CONNECTED, ""); } else { gatewaySenders.accumulate(CliStrings.RESULT_SENDER_CONNECTED, Arrays.stream(entry.getValue().getConnectedGatewaySenders()).collect(joining(", "))); } } } }  @CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP) @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.READ) ResultModel listGateway(
      @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS},
          optionContext = ConverterHint.MEMBERIDNAME,
          help = CliStrings.LIST_GATEWAY__MEMBER__HELP) String[] onMember,
      @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
          optionContext = ConverterHint.MEMBERGROUP,
          help = CliStrings.LIST_GATEWAY__GROUP__HELP) String[] onGroup,
      @CliOption(key = {CliStrings.LIST_GATEWAY__SHOW_RECEIVERS_ONLY},
          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false",
          help = CliStrings.LIST_GATEWAY__SHOW_RECEIVERS_ONLY__HELP) boolean showReceiversOnly,
      @CliOption(key = {CliStrings.LIST_GATEWAY__SHOW_SENDERS_ONLY},
          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false",
          help = CliStrings.LIST_GATEWAY__SHOW_SENDERS_ONLY__HELP) boolean showSendersOnly);  }
@Test public void listGatewaysDisplaysGatewaySendersAndReceivers() { ResultModel crd = new ResultModel(); crd.setHeader(CliStrings.HEADER_GATEWAYS); doReturn(new String[] {"10.118.19.31(server-ny-2:33256)<v2>:1029", "10.118.19.31(server-ny-1:33206)<v1>:1028"}).when(receiverMXBean) .getConnectedGatewaySenders(); command.accumulateListGatewayResult(crd, Collections.emptyMap(), receiverBeans); new CommandResultAssert(new CommandResult(crd)) .hasTableSection("gatewayReceivers") .hasColumn("Senders Connected") .containsExactly( "10.118.19.31(server-ny-2:33256)<v2>:1029, 10.118.19.31(server-ny-1:33206)<v1>:1028"); }
@Test public void listGatewaysDisplaysGatewayReceiversWhenEmpty() { ResultModel crd = new ResultModel(); doReturn(new String[0]).when(receiverMXBean).getConnectedGatewaySenders(); command.accumulateListGatewayResult(crd, Collections.emptyMap(), receiverBeans); new CommandResultAssert(new CommandResult(crd)) .hasTableSection("gatewayReceivers") .hasColumn("Senders Connected").containsExactly(""); }
@Test public void listGatewaysDisplaysGatewayReceiversWhenNull() { ResultModel crd = new ResultModel(); doReturn(null).when(receiverMXBean).getConnectedGatewaySenders(); command.accumulateListGatewayResult(crd, Collections.emptyMap(), receiverBeans); new CommandResultAssert(new CommandResult(crd)) .hasTableSection("gatewayReceivers") .hasColumn("Senders Connected").containsExactly(""); }