geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject geode git commit: GEODE-2313: Fix PulseDataExportTest
Date Tue, 24 Jan 2017 21:34:28 GMT
Repository: geode
Updated Branches:
  refs/heads/develop be8db8b7b -> ad003ef9b


GEODE-2313: Fix PulseDataExportTest

This closes #347


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

Branch: refs/heads/develop
Commit: ad003ef9b4a76ec33278baa379352996c26b064f
Parents: be8db8b
Author: Jared Stewart <jstewart@pivotal.io>
Authored: Wed Jan 18 14:13:48 2017 -0800
Committer: Kirk Lund <klund@apache.org>
Committed: Tue Jan 24 13:27:22 2017 -0800

----------------------------------------------------------------------
 .../management/internal/AgentUtilJUnitTest.java |   5 +-
 .../geode/tools/pulse/PulseDataExportTest.java  | 173 ++++++++++++++++++
 .../dunit/rules/LocatorServerStartupRule.java   |   4 +
 .../tools/pulse/tests/PulseDataExportTest.java  | 174 -------------------
 4 files changed, 181 insertions(+), 175 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/ad003ef9/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
b/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
index 33e274e..3a29e8a 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
@@ -25,6 +25,7 @@ import org.junit.experimental.categories.Category;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.File;
+import java.io.IOException;
 import java.nio.file.Path;
 
 @Category(IntegrationTest.class)
@@ -37,11 +38,13 @@ public class AgentUtilJUnitTest {
   public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
 
   @Before
-  public void setUp() {
+  public void setUp() throws IOException {
     // GEODE-958: We need to set gemfire.home to tell AgentUtil where to find wars in case
the env
     // variable GEMFIRE is not set
     Path installDir = new File(".").getAbsoluteFile().toPath().resolve("build").resolve("install")
         .resolve("apache-geode");
+    System.out.println("Current dir is " + new File(".").getCanonicalPath());
+    System.out.println("Setting gemfire.home to " + installDir);
     System.setProperty("gemfire.home", installDir.toString());
 
     version = GemFireVersion.getGemFireVersion();

http://git-wip-us.apache.org/repos/asf/geode/blob/ad003ef9/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
new file mode 100644
index 0000000..679f486
--- /dev/null
+++ b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.tools.pulse;
+
+import static com.jayway.awaitility.Awaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.test.dunit.IgnoredException;
+import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.Locator;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.http.Consts;
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+@Category(DistributedTest.class)
+public class PulseDataExportTest extends JUnit4DistributedTestCase {
+
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+
+  private Locator locator;
+  private org.apache.geode.test.dunit.rules.Server server;
+  private GfshShellConnectionRule gfshConnector;
+  private HttpClient httpClient;
+  private CookieStore cookieStore;
+
+
+  @Before
+  public void before() throws Throwable {
+    IgnoredException
+        .addIgnoredException("Failed to properly release resources held by the HTTP service:");
+    IgnoredException.addIgnoredException("!STOPPED");
+
+    locator = lsRule.startLocatorVMWithPulse(0, new Properties());
+
+    gfshConnector = new GfshShellConnectionRule(locator);
+    gfshConnector.connect();
+    assertThat(gfshConnector.isConnected()).isTrue();
+
+    server = lsRule.startServerVM(1, locator.getPort());
+
+    gfshConnector.executeAndVerifyCommand("create region --name=regionA --type=REPLICATE");
+    org.apache.geode.cache.Region<String, String> region = new ClientCacheFactory()
+        .addPoolLocator("localhost", locator.getPort()).create()
+        .<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY).create("regionA");
+
+    region.put("key1", "value1");
+    region.put("key2", "value2");
+    region.put("key3", "value3");
+    cookieStore = new BasicCookieStore();
+    httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
+
+    await().atMost(2, TimeUnit.MINUTES).until(this::pulseServerHasStarted);
+  }
+
+  @Test
+  public void dataBrowserExportWorksAsExpected() throws Throwable {
+    getAuthenticatedJSESSIONID();
+    HttpContext authenticatedHttpContext = buildAuthenticatedHttpContext();
+
+    HttpGet dataExportGET = buildDataExportGET();
+
+    HttpResponse response = httpClient.execute(dataExportGET, authenticatedHttpContext);
+    assertThat(response.getStatusLine().getStatusCode()).describedAs(response.toString())
+        .isEqualTo(200);
+
+    String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
+    assertThat(responseBody).describedAs(response.toString()).isEqualTo(
+        "{\"result\":[[\"java.lang.String\",\"value1\"],[\"java.lang.String\",\"value2\"],[\"java.lang.String\",\"value3\"]]}");
+  }
+
+  private HttpPost buildLoginPOST() {
+    HttpPost httpPost = new HttpPost("http://localhost:7070/pulse/login");
+
+    List<NameValuePair> formData = new ArrayList<>();
+    formData.add(new BasicNameValuePair("username", "admin"));
+    formData.add(new BasicNameValuePair("password", "admin"));
+
+    httpPost.setEntity(new UrlEncodedFormEntity(formData, Consts.UTF_8));
+
+    return httpPost;
+  }
+
+  private HttpGet buildDataExportGET() throws URISyntaxException {
+    URIBuilder builder = new URIBuilder();
+    builder.setScheme("http").setHost("localhost").setPort(7070).setPath("/pulse/dataBrowserExport")
+        .setParameter("query", "select * from /regionA a order by a");
+    return new HttpGet(builder.build());
+  }
+
+  private HttpContext buildAuthenticatedHttpContext() throws Throwable {
+    HttpContext localContext = new BasicHttpContext();
+    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
+
+    return localContext;
+  }
+
+  public void getAuthenticatedJSESSIONID() throws Throwable {
+    HttpResponse loginResponse = httpClient.execute(buildLoginPOST());
+    assertThat(loginResponse.getStatusLine().getStatusCode()).describedAs(loginResponse.toString())
+        .isEqualTo(302);
+
+    String JSESSIONIDFromSetCookieHeader = Arrays.stream(loginResponse.getHeaders("SET-COOKIE"))
+        .map(Header::getValue).filter(setCookie -> setCookie.contains("JSESSIONID")).findAny()
+        .orElseThrow(() -> new AssertionError(
+            "No JSESSIONID cookie was set in the login response: " + loginResponse.toString()));
+
+    Cookie JESSIONIDFromCookieStore = cookieStore.getCookies().stream()
+        .filter(cookie -> cookie.getName().equalsIgnoreCase("JSESSIONID")).findFirst()
+        .orElseThrow(() -> new AssertionError("No JSESSIONID cookie was set in the cookie
store"));
+
+    assertThat(JSESSIONIDFromSetCookieHeader).contains(JESSIONIDFromCookieStore.getValue());
+  }
+
+  private boolean pulseServerHasStarted() {
+    try {
+      httpClient.execute(buildLoginPOST());
+    } catch (IOException e) {
+      e.printStackTrace();
+      return false;
+    }
+
+    return true;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/ad003ef9/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
index 211a8c6..ac9221c 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
@@ -109,6 +109,10 @@ public class LocatorServerStartupRule extends ExternalResource implements
Serial
         .toPath().resolve("geode-assembly").resolve("build").resolve("install")
         .resolve("apache-geode").toString();
 
+    System.out.println("Current dir is " + new File(".").getCanonicalPath());
+    System.out.println("Setting gemfire.home to " + geodeInstallDir);
+
+
     VM locatorVM = getHost(0).getVM(index);
     int locatorPort = locatorVM.invoke(() -> {
       System.setProperty("user.dir", workingDir.getCanonicalPath());

http://git-wip-us.apache.org/repos/asf/geode/blob/ad003ef9/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/PulseDataExportTest.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/PulseDataExportTest.java
b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/PulseDataExportTest.java
deleted file mode 100644
index 364e4c4..0000000
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/PulseDataExportTest.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * 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.tools.pulse.tests;
-
-import static com.jayway.awaitility.Awaitility.await;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.geode.cache.client.ClientCacheFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
-import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
-import org.apache.geode.test.dunit.rules.Locator;
-import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.http.Consts;
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.CookieStore;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.cookie.Cookie;
-import org.apache.http.impl.client.BasicCookieStore;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.EntityUtils;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-@Category(DistributedTest.class)
-public class PulseDataExportTest extends JUnit4DistributedTestCase {
-
-  @Rule
-  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
-
-  private Locator locator;
-  private org.apache.geode.test.dunit.rules.Server server;
-  private GfshShellConnectionRule gfshConnector;
-  private HttpClient httpClient;
-  private CookieStore cookieStore;
-
-
-  @Before
-  public void before() throws Throwable {
-    IgnoredException
-        .addIgnoredException("Failed to properly release resources held by the HTTP service:");
-    IgnoredException.addIgnoredException("!STOPPED");
-
-    locator = lsRule.startLocatorVMWithPulse(0, new Properties());
-
-    gfshConnector = new GfshShellConnectionRule(locator);
-    gfshConnector.connect();
-    assertThat(gfshConnector.isConnected()).isTrue();
-
-    server = lsRule.startServerVM(1, locator.getPort());
-
-    gfshConnector.executeAndVerifyCommand("create region --name=regionA --type=REPLICATE");
-    org.apache.geode.cache.Region<String, String> region = new ClientCacheFactory()
-        .addPoolLocator("localhost", locator.getPort()).create()
-        .<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY).create("regionA");
-
-    region.put("key1", "value1");
-    region.put("key2", "value2");
-    region.put("key3", "value3");
-    cookieStore = new BasicCookieStore();
-    httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
-
-    await().atMost(2, TimeUnit.MINUTES).until(this::pulseServerHasStarted);
-  }
-
-  @Ignore // GEODE-2313
-  @Test
-  public void dataBrowserExportWorksAsExpected() throws Throwable {
-    getAuthenticatedJSESSIONID();
-    HttpContext authenticatedHttpContext = buildAuthenticatedHttpContext();
-
-    HttpGet dataExportGET = buildDataExportGET();
-
-    HttpResponse response = httpClient.execute(dataExportGET, authenticatedHttpContext);
-    assertThat(response.getStatusLine().getStatusCode()).describedAs(response.toString())
-        .isEqualTo(200);
-
-    String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
-    assertThat(responseBody).describedAs(response.toString()).isEqualTo(
-        "{\"result\":[[\"java.lang.String\",\"value1\"],[\"java.lang.String\",\"value2\"],[\"java.lang.String\",\"value3\"]]}");
-  }
-
-  private HttpPost buildLoginPOST() {
-    HttpPost httpPost = new HttpPost("http://localhost:7070/pulse/login");
-
-    List<NameValuePair> formData = new ArrayList<>();
-    formData.add(new BasicNameValuePair("username", "admin"));
-    formData.add(new BasicNameValuePair("password", "admin"));
-
-    httpPost.setEntity(new UrlEncodedFormEntity(formData, Consts.UTF_8));
-
-    return httpPost;
-  }
-
-  private HttpGet buildDataExportGET() throws URISyntaxException {
-    URIBuilder builder = new URIBuilder();
-    builder.setScheme("http").setHost("localhost").setPort(7070).setPath("/pulse/dataBrowserExport")
-        .setParameter("query", "select * from /regionA a order by a");
-    return new HttpGet(builder.build());
-  }
-
-  private HttpContext buildAuthenticatedHttpContext() throws Throwable {
-    HttpContext localContext = new BasicHttpContext();
-    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
-
-    return localContext;
-  }
-
-  public void getAuthenticatedJSESSIONID() throws Throwable {
-    HttpResponse loginResponse = httpClient.execute(buildLoginPOST());
-    assertThat(loginResponse.getStatusLine().getStatusCode()).describedAs(loginResponse.toString())
-        .isEqualTo(302);
-
-    String JSESSIONIDFromSetCookieHeader = Arrays.stream(loginResponse.getHeaders("SET-COOKIE"))
-        .map(Header::getValue).filter(setCookie -> setCookie.contains("JSESSIONID")).findAny()
-        .orElseThrow(() -> new AssertionError(
-            "No JSESSIONID cookie was set in the login response: " + loginResponse.toString()));
-
-    Cookie JESSIONIDFromCookieStore = cookieStore.getCookies().stream()
-        .filter(cookie -> cookie.getName().equalsIgnoreCase("JSESSIONID")).findFirst()
-        .orElseThrow(() -> new AssertionError("No JSESSIONID cookie was set in the cookie
store"));
-
-    assertThat(JSESSIONIDFromSetCookieHeader).contains(JESSIONIDFromCookieStore.getValue());
-  }
-
-  private boolean pulseServerHasStarted() {
-    try {
-      httpClient.execute(buildLoginPOST());
-    } catch (IOException e) {
-      e.printStackTrace();
-      return false;
-    }
-
-    return true;
-  }
-
-}


Mime
View raw message