Skip to content

Commit

Permalink
GEODE-6765: Gfsh list* commands do not return error when no results f…
Browse files Browse the repository at this point in the history
…ound (apache#3634)

- This also includes not returning an error when no members are found to
  execute against.

Authored-by: Jens Deppe <[email protected]>
  • Loading branch information
jdeppe-pivotal authored May 30, 2019
1 parent 1680b2b commit 47e44ff
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public static void beforeClass() {

@Test
public void list() {
gfsh.executeAndAssertThat("list async-event-queue").statusIsSuccess()
.containsOutput(CliStrings.LIST_ASYNC_EVENT_QUEUES__NO_QUEUES_FOUND_MESSAGE);

gfsh.executeAndAssertThat("create async-event-queue --id=queue1 --group=group1 --listener="
+ MyAsyncEventListener.class.getName()).statusIsSuccess();

Expand All @@ -78,5 +75,14 @@ public void list() {
.tableHasRowWithValues("Member", "ID", "server-1", "queue")
.tableHasRowWithValues("Member", "ID", "server-2", "queue");

gfsh.executeAndAssertThat("destroy async-event-queue --id=queue").statusIsSuccess();
gfsh.executeAndAssertThat("destroy async-event-queue --id=queue1").statusIsSuccess();
gfsh.executeAndAssertThat("destroy async-event-queue --id=queue2").statusIsSuccess();
}

@Test
public void ensureNoResultIsSuccess() {
gfsh.executeAndAssertThat("list async-event-queue").statusIsSuccess()
.containsOutput(CliStrings.LIST_ASYNC_EVENT_QUEUES__NO_QUEUES_FOUND_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public void listRegionsInGroup2() throws Exception {
REGION2, REGION3, SUBREGION1A);
}

@Test
public void listNoMembersIsSuccess() {
CommandStringBuilder csb = new CommandStringBuilder(LIST_REGION);
csb.addOption(GROUP, "unknown");
gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
}

private static void createLocalRegion(final String regionName) {
final Cache cache = CacheFactory.getAnyInstance();
// Create the data region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public static void runLessCommandAsExternalViewer(Result commandResult) {
null, workingDir);
p.waitFor();
} catch (IOException | InterruptedException e) {
Gfsh.printlnErr(e.getMessage());
Gfsh.println(e.getMessage());
} finally {
if (file != null)
file.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ListAsyncEventQueuesCommand extends GfshCommand {
public ResultModel listAsyncEventQueues() {
Set<DistributedMember> targetMembers = getAllNormalMembers();
if (targetMembers.isEmpty()) {
return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
return ResultModel.createInfo(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

// Each (successful) member returns a list of AsyncEventQueueDetails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ResultModel listClient() throws Exception {
ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();

if (cacheServers.length == 0) {
return ResultModel.createError(
return ResultModel.createInfo(
CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public ResultModel listClient() throws Exception {
}

if (clientServerMap.size() == 0) {
return ResultModel.createError(
return ResultModel.createInfo(
CliStrings.format(CliStrings.LIST_COULD_NOT_RETRIEVE_CLIENT_LIST));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ResultModel listDeployed(@CliOption(key = {CliStrings.GROUP, CliStrings.G

Set<DistributedMember> targetMembers = findMembers(group, null);
if (targetMembers.isEmpty()) {
return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
return ResultModel.createInfo(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

ResultModel result = new ResultModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResultModel listDurableClientCQs(
Set<DistributedMember> targetMembers = findMembers(group, memberNameOrId);

if (targetMembers.isEmpty()) {
return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
return ResultModel.createInfo(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

final ResultCollector<?, ?> rc =
Expand All @@ -72,7 +72,7 @@ public ResultModel listDurableClientCQs(
table.accumulate("Status", oneResult.getStatus());
table.accumulate("CQ Name", oneResult.getStatusMessage());

if (!oneResult.isSuccessful()) {
if (!(oneResult.isSuccessful() || oneResult.isIgnorableFailure())) {
result.setStatus(Result.Status.ERROR);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ResultModel listFunction(
Set<DistributedMember> targetMembers = findMembers(groups, members);

if (targetMembers.isEmpty()) {
return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
return ResultModel.createInfo(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

List<CliFunctionResult> results = executeAndGetFunctionResult(this.listFunctionFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ResultModel listGateway(
Set<DistributedMember> dsMembers = findMembers(onGroup, onMember);

if (dsMembers.isEmpty()) {
return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
return ResultModel.createInfo(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<>();
Expand Down Expand Up @@ -104,7 +104,7 @@ public ResultModel listGateway(
}
}
if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
return ResultModel.createError(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
return ResultModel.createInfo(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
}

accumulateListGatewayResult(result, gatewaySenderBeans, gatewayReceiverBeans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ResultModel listRegion(
Set<DistributedMember> targetMembers = findMembers(group, memberNameOrId);

if (targetMembers.isEmpty()) {
return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
return ResultModel.createInfo(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

TabularResultModel resultData = result.addTable("regionInfo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ private List<CliFunctionResult> createFunctionResult(String memberNameOrId,
try {
CacheClientNotifier ccn = CacheClientNotifier.getInstance();
if (ccn == null) {
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.IGNORABLE,
CliStrings.NO_CLIENT_FOUND));
return results;
}

CacheClientProxy ccp = ccn.getClientProxy(durableClientId);
if (ccp == null) {
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.IGNORABLE,
CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId)));
return results;
}

CqService cqService = ccp.getCache().getCqService();
if (cqService == null || !cqService.isRunning()) {
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.IGNORABLE,
CliStrings.LIST_DURABLE_CQS__NO__CQS__REGISTERED));
return results;
}

List<String> durableCqNames = cqService.getAllDurableClientCqs(ccp.getProxyID());
if (durableCqNames == null || durableCqNames.isEmpty()) {
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR,
results.add(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.IGNORABLE,
CliStrings
.format(CliStrings.LIST_DURABLE_CQS__NO__CQS__FOR__CLIENT, durableClientId)));
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ public static void println() {
gfshout.println();
}

public static <T> void println(T toPrint) {
public static void println(Object toPrint) {
gfshout.println(toPrint);
}

public static <T> void print(T toPrint) {
public static void print(Object toPrint) {
gfshout.print(toPrint);
}

public static <T> void printlnErr(T toPrint) {
public static void printlnErr(Object toPrint) {
gfsherr.println(toPrint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void noMembersFound() {
doReturn(Collections.emptySet()).when(command).getAllNormalMembers();

// Command should succeed with one row of data
gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
.containsOutput(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public void testListDurableClientCqsForOneGroup() {
csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, CLIENT_NAME);
commandString = csb.toString();

gfsh.executeAndAssertThat(commandString).statusIsError()
gfsh.executeAndAssertThat(commandString).statusIsSuccess()
.hasTableSection()
.hasColumn("Status").containsExactly("IGNORED", "IGNORED")
.hasColumn("CQ Name")
.containsExactlyInAnyOrder(
CliStrings.format(CliStrings.LIST_DURABLE_CQS__NO__CQS__FOR__CLIENT, CLIENT_NAME),
Expand All @@ -135,10 +136,10 @@ public void testListDurableClientCqsWhenNoneExist() {
csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, CLIENT_NAME);
String commandString = csb.toString();

gfsh.executeAndAssertThat(commandString).statusIsError()
gfsh.executeAndAssertThat(commandString).statusIsSuccess()
.hasTableSection()
.hasColumn("CQ Name")
.containsExactlyInAnyOrder(
.hasColumn("Status").containsExactlyInAnyOrder("IGNORED", "IGNORED")
.hasColumn("CQ Name").containsExactlyInAnyOrder(
CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, CLIENT_NAME),
CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, CLIENT_NAME));
}
Expand All @@ -151,8 +152,9 @@ public void testListDurableClientCqsWithMixedResults() {
csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, CLIENT_NAME);
String commandString = csb.toString();

gfsh.executeAndAssertThat(commandString).statusIsError()
gfsh.executeAndAssertThat(commandString).statusIsSuccess()
.hasTableSection()
.hasColumn("Status").containsExactlyInAnyOrder("IGNORED", "OK", "OK", "OK")
.hasColumn("CQ Name")
.containsExactlyInAnyOrder("cq1", "cq2", "cq3", "No client found with client-id : dc1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Properties;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -43,11 +43,11 @@

@Category({GfshTest.class})
public class ListClientCommandDUnitTest {
@ClassRule
public static ClusterStartupRule cluster = new ClusterStartupRule(6);
@Rule
public ClusterStartupRule cluster = new ClusterStartupRule(6);

@ClassRule
public static GfshCommandRule gfsh = new GfshCommandRule();
@Rule
public GfshCommandRule gfsh = new GfshCommandRule();

private static final String REGION_NAME = "stocks";

Expand All @@ -57,22 +57,36 @@ public class ListClientCommandDUnitTest {

private static ClientVM client1, client2;

@BeforeClass
public static void setup() throws Exception {
@Before
public void setup() throws Exception {
locator = cluster.startLocatorVM(locatorID);
int locatorPort = locator.getPort();

gfsh.connectAndVerify(locator);
}

private void startServers(MemberVM locator) {
server1 = cluster.startServerVM(server1ID,
r -> r.withRegion(RegionShortcut.REPLICATE, REGION_NAME)
.withConnectionToLocator(locatorPort));
.withConnectionToLocator(locator.getPort()));
server2 = cluster.startServerVM(server2ID,
r -> r.withRegion(RegionShortcut.REPLICATE, REGION_NAME)
.withConnectionToLocator(locatorPort));
.withConnectionToLocator(locator.getPort()));
}

gfsh.connectAndVerify(locator);
@Test
public void noResultIsSuccess() {
startServers(locator);
gfsh.executeAndAssertThat("list clients").statusIsSuccess();
}

@Test
public void noMembersIsSuccess() {
gfsh.executeAndAssertThat("list clients").statusIsSuccess();
}

@Test
public void testTwoClientsConnectToOneServer() throws Exception {
startServers(locator);
int server1port = server1.getPort();
Properties client1props = new Properties();
client1props.setProperty("name", "client-1");
Expand Down Expand Up @@ -123,6 +137,7 @@ public void testTwoClientsConnectToOneServer() throws Exception {

@Test
public void oneClientConnectToTwoServers() throws Exception {
startServers(locator);
int server1port = server1.getPort();
int server2port = server2.getPort();
Properties client1props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public InfoResultModelAssert hasInfoSection(String sectionName) {
// convenience method to get the first table section. if more than one table section
// use the sectionName to get it
public TabularResultModelAssert hasTableSection() {
return new TabularResultModelAssert(getResultModel().getTableSections().get(0));
List<TabularResultModel> table = getResultModel().getTableSections();
assertThat(table.size()).isGreaterThan(0);
return new TabularResultModelAssert(table.get(0));
}

public TabularResultModelAssert hasTableSection(String sectionName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testCreateDestroySerialGatewaySenderWithDefault() throws Exception {

locatorSite1.waitUntilGatewaySendersAreReadyOnExactlyThisManyServers(0);

gfsh.executeAndAssertThat("list gateways").statusIsError()
gfsh.executeAndAssertThat("list gateways").statusIsSuccess()
.containsOutput("GatewaySenders or GatewayReceivers are not available in cluster");
}

Expand All @@ -100,7 +100,7 @@ public void testCreateDestroyParallellGatewaySenderWithDefault() throws Exceptio

locatorSite1.waitUntilGatewaySendersAreReadyOnExactlyThisManyServers(0);

gfsh.executeAndAssertThat("list gateways").statusIsError()
gfsh.executeAndAssertThat("list gateways").statusIsSuccess()
.containsOutput("GatewaySenders or GatewayReceivers are not available in cluster");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testListGatewayWithNoSenderReceiver() {
locatorSite1.invoke(() -> validateMemberMXBeanProxy(getMember(server3.getVM())));

String command = CliStrings.LIST_GATEWAY;
gfsh.executeAndAssertThat(command).statusIsError();
gfsh.executeAndAssertThat(command).statusIsSuccess();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void before() throws Exception {
@Test
public void testListClient() throws Exception {
gfshRule.executeAndAssertThat("list clients")
.statusIsError()
.statusIsSuccess()
.hasInfoSection().hasOutput()
.isEqualTo("No clients were retrieved for cache-servers.");
}
Expand Down

0 comments on commit 47e44ff

Please sign in to comment.