Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6F9EE200C55 for ; Thu, 13 Apr 2017 19:18:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6A283160BBA; Thu, 13 Apr 2017 17:18:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 89214160BA7 for ; Thu, 13 Apr 2017 19:18:23 +0200 (CEST) Received: (qmail 37925 invoked by uid 500); 13 Apr 2017 17:18:22 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 37505 invoked by uid 99); 13 Apr 2017 17:18:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Apr 2017 17:18:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 47413E2F41; Thu, 13 Apr 2017 17:18:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.apache.org Date: Thu, 13 Apr 2017 17:18:27 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [06/22] geode git commit: GEODE-2767: Added DUnitTests to validate export log options --group and --member. archived-at: Thu, 13 Apr 2017 17:18:24 -0000 GEODE-2767: Added DUnitTests to validate export log options --group and --member. * this closes #445 Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/42bc1093 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/42bc1093 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/42bc1093 Branch: refs/heads/feature/GEODE-2632 Commit: 42bc1093be2707c16838f477bcccb7933ba9bc53 Parents: 31b6507 Author: Patrick Rhomberg Authored: Mon Apr 10 14:49:33 2017 -0700 Committer: Jinmei Liao Committed: Tue Apr 11 09:44:09 2017 -0700 ---------------------------------------------------------------------- .../cli/commands/ExportLogsDUnitTest.java | 2 +- .../ExportLogsWithMemberGroupDUnitTest.java | 144 +++++++++++++++++++ 2 files changed, 145 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/42bc1093/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java index c960c8f..ef535d8 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java @@ -77,6 +77,7 @@ public class ExportLogsDUnitTest { private Map> expectedMessages; + @Before public void setup() throws Exception { Properties properties = new Properties(); @@ -127,7 +128,6 @@ public class ExportLogsDUnitTest { } @Test - @Category(FlakyTest.class) // time sensitive public void testExportWithStartAndEndDateTimeFiltering() throws Exception { ZonedDateTime cutoffTime = LocalDateTime.now().atZone(ZoneId.systemDefault()); http://git-wip-us.apache.org/repos/asf/geode/blob/42bc1093/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java new file mode 100644 index 0000000..e5cca27 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsWithMemberGroupDUnitTest.java @@ -0,0 +1,144 @@ +/* + * 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.commands; + +import static org.apache.geode.distributed.ConfigurationProperties.GROUPS; +import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS; +import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_ARCHIVE_FILE; +import static org.apache.geode.management.internal.cli.commands.ExportLogsCommand.ONLY_DATE_FORMAT; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.Sets; + +import org.apache.geode.distributed.ConfigurationProperties; +import org.apache.geode.internal.AvailablePortHelper; +import org.apache.geode.management.cli.Result; +import org.apache.geode.management.internal.cli.result.CommandResult; +import org.apache.geode.management.internal.cli.util.CommandStringBuilder; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; +import org.apache.geode.test.dunit.rules.MemberVM; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +@Category(DistributedTest.class) +public class ExportLogsWithMemberGroupDUnitTest { + @ClassRule + public static LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); + + @ClassRule + public static GfshShellConnectionRule connector = new GfshShellConnectionRule(); + + protected static int jmxPort, httpPort; + protected static Set expectedZipEntries = new HashSet<>(); + protected static MemberVM locator; + + @BeforeClass + public static void beforeClass() throws Exception { + int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + httpPort = ports[0]; + jmxPort = ports[1]; + Properties locatorProperties = new Properties(); + locatorProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost"); + locatorProperties.setProperty(HTTP_SERVICE_PORT, httpPort + ""); + locatorProperties.setProperty(JMX_MANAGER_PORT, jmxPort + ""); + + // start the locator in vm0 and then connect to it over http + locator = lsRule.startLocatorVM(0, locatorProperties); + + Properties serverProperties = new Properties(); + serverProperties.setProperty(GROUPS, "group1"); + lsRule.startServerVM(1, serverProperties, locator.getPort()); + lsRule.startServerVM(2, serverProperties, locator.getPort()); + + serverProperties.setProperty(GROUPS, "group2"); + lsRule.startServerVM(3, serverProperties, locator.getPort()); + + + expectedZipEntries = Sets.newHashSet("locator-0/locator-0.log", "server-1/server-1.log", + "server-1/statistics.gfs"); + } + + protected void connectIfNeeded() throws Exception { + if (!connector.isConnected()) { + connector.connect(locator); + } + } + + @Test + public void testExportLogsWithMemberName() throws Exception { + connectIfNeeded(); + connector.executeAndVerifyCommand("export logs --member=server-1"); + String zipPath = getZipPathFromCommandResult(connector.getGfshOutput()); + Set actualZipEntries = getZipEntries(zipPath); + + Set expectedFiles = Sets.newHashSet("server-1/server-1.log"); + assertThat(actualZipEntries).isEqualTo(expectedFiles); + } + + @Test + public void testExportLogsWithGroupName() throws Exception { + connectIfNeeded(); + connector.executeAndVerifyCommand("export logs --group=group1"); + String zipPath = getZipPathFromCommandResult(connector.getGfshOutput()); + Set actualZipEntries = getZipEntries(zipPath); + + Set expectedFiles = Sets.newHashSet("server-1/server-1.log", "server-2/server-2.log"); + assertThat(actualZipEntries).isEqualTo(expectedFiles); + + connector.executeAndVerifyCommand("export logs --group=group2"); + zipPath = getZipPathFromCommandResult(connector.getGfshOutput()); + actualZipEntries = getZipEntries(zipPath); + + expectedFiles = Sets.newHashSet("server-3/server-3.log"); + assertThat(actualZipEntries).isEqualTo(expectedFiles); + } + + @Test + public void testExportLogsWithGroupAndMemberName() throws Exception { + connectIfNeeded(); + CommandResult results = + connector.executeCommand("export logs --group=group1 --member=server-1"); + assertThat(results.getStatus()).isEqualTo(Result.Status.ERROR); + assertThat(connector.getGfshOutput()).contains("Can't specify both group and member"); + } + + + protected String getZipPathFromCommandResult(String message) { + return message.replaceAll("Logs exported to the connected member's file system: ", "").trim(); + } + + private static Set getZipEntries(String zipFilePath) throws IOException { + return new ZipFile(zipFilePath).stream().map(ZipEntry::getName).collect(Collectors.toSet()); + } +}