qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject [1/3] qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP] Refactor VirtualHostLoggerTest
Date Fri, 09 Feb 2018 11:31:10 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/master a9667120e -> a2732dd69


QPID-8083 [System Tests] [REST/HTTP] Refactor VirtualHostLoggerTest


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/a2732dd6
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/a2732dd6
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/a2732dd6

Branch: refs/heads/master
Commit: a2732dd69bd8ac3053c51f7b13e5a9bf8e581c70
Parents: 81d8172
Author: Keith Wall <kwall@apache.org>
Authored: Fri Feb 9 10:25:01 2018 +0000
Committer: Keith Wall <kwall@apache.org>
Committed: Fri Feb 9 11:30:52 2018 +0000

----------------------------------------------------------------------
 .../endtoend/logging/VirtualHostLoggerTest.java | 192 +++++++++++++++++++
 .../qpid/tests/http/rest/model/CreateTest.java  |  15 +-
 .../systest/rest/VirtualHostLoggerRestTest.java | 141 --------------
 test-profiles/JavaTransientExcludes             |   1 -
 4 files changed, 206 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/a2732dd6/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/logging/VirtualHostLoggerTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/logging/VirtualHostLoggerTest.java
b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/logging/VirtualHostLoggerTest.java
new file mode 100644
index 0000000..86694b5
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/logging/VirtualHostLoggerTest.java
@@ -0,0 +1,192 @@
+/*
+ * 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.qpid.tests.http.endtoend.logging;
+
+import static javax.servlet.http.HttpServletResponse.SC_CREATED;
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import java.io.File;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.google.common.io.CharStreams;
+import org.junit.Test;
+
+import org.apache.qpid.server.logging.logback.VirtualHostFileLogger;
+import org.apache.qpid.server.logging.logback.VirtualHostNameAndLevelLogInclusionRule;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.tests.http.HttpRequestConfig;
+import org.apache.qpid.tests.http.HttpTestBase;
+
+@HttpRequestConfig(useVirtualHostAsHost = true)
+public class VirtualHostLoggerTest extends HttpTestBase
+{
+    private static final String LOGGER_NAME = "testLogger1";
+    private static final String LOGGER_RULE = "testRule";
+
+    @Test
+    public void createVirtualHostLoggerAndRule() throws Exception
+    {
+        Map<String, Object> loggerAttributes = new HashMap<>();
+        loggerAttributes.put(ConfiguredObject.NAME, LOGGER_NAME);
+        loggerAttributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
+
+        getHelper().submitRequest(String.format("virtualhostlogger/%s", LOGGER_NAME),
+                                  "PUT",
+                                  loggerAttributes,
+                                  SC_CREATED);
+
+        Map<String, Object> ruleAttributes = new HashMap<>();
+        ruleAttributes.put(ConfiguredObject.NAME, LOGGER_RULE);
+        ruleAttributes.put(ConfiguredObject.TYPE, VirtualHostNameAndLevelLogInclusionRule.TYPE);
+
+        String loggerRuleRestUrl = String.format("virtualhostloginclusionrule/%s/%s", LOGGER_NAME,
LOGGER_RULE);
+
+        getHelper().submitRequest(loggerRuleRestUrl, "PUT", ruleAttributes, SC_CREATED);
+        getHelper().submitRequest(loggerRuleRestUrl, "GET", SC_OK);
+    }
+
+    @Test
+    public void dynamicConfiguration() throws Exception
+    {
+        final String loggerUrl = String.format("virtualhostlogger/%s", LOGGER_NAME);
+        final String loggerRuleUrl = String.format("virtualhostloginclusionrule/%s/%s", LOGGER_NAME,
LOGGER_RULE);
+
+        Map<String, Object> loggerAttributes = new HashMap<>();
+        loggerAttributes.put(ConfiguredObject.NAME, LOGGER_NAME);
+        loggerAttributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
+
+        getHelper().submitRequest(loggerUrl,
+                                  "PUT",
+                                  loggerAttributes,
+                                  SC_CREATED);
+
+        Map<String, Object> ruleAttributes = new HashMap<>();
+        ruleAttributes.put(ConfiguredObject.NAME, LOGGER_RULE);
+        ruleAttributes.put(ConfiguredObject.TYPE, VirtualHostNameAndLevelLogInclusionRule.TYPE);
+        ruleAttributes.put("loggerName", "qpid.message.*");
+
+        getHelper().submitRequest(loggerRuleUrl, "PUT", ruleAttributes, SC_CREATED);
+        getHelper().submitRequest(loggerRuleUrl, "GET", SC_OK);
+
+        Map<String, Object> loggerData = getHelper().getJsonAsMap(loggerUrl);
+        String logFileLocation = String.valueOf(loggerData.get(VirtualHostFileLogger.FILE_NAME));
+        assertThat(logFileLocation, is(notNullValue()));
+        final File logFile = new File(logFileLocation);
+
+        final String downloadUrl = String.format("%s/getFile?fileName=%s", loggerUrl, logFile.getName());
+
+        final int queueCreateMatchesBefore = countLogFileMatches(downloadUrl, "QUE-1001");
+        assertThat("Unexpected queue matches before queue creation", queueCreateMatchesBefore,
is(equalTo(0)));
+
+        getHelper().submitRequest("queue/myqueue", "PUT", Collections.emptyMap(), SC_CREATED);
+
+        final int queueCreateMatchesAfter = countLogFileMatches(downloadUrl, "QUE-1001");
+        assertThat("Unexpected queue matches before queue creation", queueCreateMatchesAfter,
is(equalTo(1)));
+
+        ruleAttributes.put("level", "OFF");
+        getHelper().submitRequest(loggerRuleUrl, "PUT", ruleAttributes, SC_OK);
+
+        getHelper().submitRequest("queue/myqueue2", "PUT", Collections.emptyMap(), SC_CREATED);
+
+        final int afterLevelChange = countLogFileMatches(downloadUrl, "QUE-1001");
+        assertThat("Unexpected queue matches after level change", afterLevelChange, is(equalTo(queueCreateMatchesAfter)));
+
+        ruleAttributes.put("level", "INFO");
+        getHelper().submitRequest(loggerRuleUrl, "PUT", ruleAttributes, SC_OK);
+
+        getHelper().submitRequest("queue/myqueue3", "PUT", Collections.emptyMap(), SC_CREATED);
+
+        final int afterSecondLevelChange = countLogFileMatches(downloadUrl, "QUE-1001");
+        assertThat("Unexpected queue matches after level change", afterSecondLevelChange,
is(equalTo(afterLevelChange + 1)));
+    }
+
+    @Test
+    public void deleteVirtualHostLogger() throws Exception
+    {
+        final String loggerRestUrl = String.format("virtualhostlogger/%s", LOGGER_NAME);
+        Map<String, Object> attributes = new HashMap<>();
+        attributes.put(ConfiguredObject.NAME, LOGGER_NAME);
+        attributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
+
+        getHelper().submitRequest(loggerRestUrl, "PUT", attributes, SC_CREATED);
+        getHelper().submitRequest(loggerRestUrl, "GET", SC_OK);
+
+        getHelper().submitRequest(loggerRestUrl, "DELETE", null, SC_OK);
+        getHelper().submitRequest(loggerRestUrl, "GET", SC_NOT_FOUND);
+    }
+
+    @Test
+    public void recoverAfterDeletedVirtualHostLoggerAndRules_QPID_8066() throws Exception
+    {
+        assumeThat(getBrokerAdmin().supportsRestart(), is(true));
+
+        final String hostUrl = "virtualhost";
+        final String loggerUrl = String.format("virtualhostlogger/%s", LOGGER_NAME);
+        final String loggerRuleUrl = String.format("virtualhostloginclusionrule/%s/%s", LOGGER_NAME,
LOGGER_RULE);
+
+        Map<String, Object> loggerAttributes = new HashMap<>();
+        loggerAttributes.put(ConfiguredObject.NAME, LOGGER_NAME);
+        loggerAttributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
+        getHelper().submitRequest(loggerUrl, "PUT", loggerAttributes, SC_CREATED);
+
+        Map<String, Object> ruleAttributes = new HashMap<>();
+        ruleAttributes.put(ConfiguredObject.NAME, LOGGER_RULE);
+        ruleAttributes.put(ConfiguredObject.TYPE, VirtualHostNameAndLevelLogInclusionRule.TYPE);
+        getHelper().submitRequest(loggerRuleUrl, "PUT", ruleAttributes, SC_CREATED);
+
+        Map<String, Object> host = getHelper().getJsonAsMap(hostUrl);
+        assertThat(host.get(ConfiguredObject.STATE), is(equalTo(State.ACTIVE.name())));
+        assertThat(getHelper().getJsonAsList("virtualhostlogger").size(), is(equalTo(1)));
+
+        getHelper().submitRequest(loggerUrl, "DELETE", SC_OK);
+
+        getBrokerAdmin().restart();
+
+        host = getHelper().getJsonAsMap(hostUrl);
+        assertThat(host.get(ConfiguredObject.STATE), is(equalTo(State.ACTIVE.name())));
+
+        assertThat(getHelper().getJsonAsList("virtualhostlogger").size(), is(equalTo(0)));
+    }
+
+    private int countLogFileMatches(final String url, final String searchTerm) throws Exception
+    {
+        HttpURLConnection httpCon = getHelper().openManagementConnection(url, "GET");
+        httpCon.connect();
+
+        try (InputStreamReader r = new InputStreamReader(httpCon.getInputStream()))
+        {
+            final List<String> strings = CharStreams.readLines(r);
+            return strings.stream().map(line -> line.contains(searchTerm)).collect(Collectors.toList()).size();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/a2732dd6/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
index d3e5683..cbf77dc 100644
--- a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
@@ -61,7 +61,7 @@ public class CreateTest extends HttpTestBase
     }
 
     @Test
-    public void locationHeader() throws Exception
+    public void putToUriLocationHeader() throws Exception
     {
         final String queueUrl = "queue/myqueue";
         Map<String, List<String>> headers = new HashMap<>();
@@ -73,6 +73,19 @@ public class CreateTest extends HttpTestBase
     }
 
     @Test
+    public void putToParentUriLocationHeader() throws Exception
+    {
+        final String parentUrl = "queue";
+        final String queueUrl = "queue/myqueue";
+        Map<String, List<String>> headers = new HashMap<>();
+        int responseCode = getHelper().submitRequest(parentUrl, "PUT", Collections.singletonMap(ConfiguredObject.NAME,
"myqueue"), headers);
+        assertThat(responseCode, is(equalTo(SC_CREATED)));
+        List<String> location = headers.get("Location");
+        assertThat(location.size(), is(equalTo(1)));
+        assertThat(location.get(0), endsWith(queueUrl));
+    }
+
+    @Test
     public void createSubtype() throws Exception
     {
         final String queueUrl = "queue/myqueue";

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/a2732dd6/systests/src/test/java/org/apache/qpid/systest/rest/VirtualHostLoggerRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/VirtualHostLoggerRestTest.java
b/systests/src/test/java/org/apache/qpid/systest/rest/VirtualHostLoggerRestTest.java
deleted file mode 100644
index 488c131..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/VirtualHostLoggerRestTest.java
+++ /dev/null
@@ -1,141 +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.qpid.systest.rest;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.qpid.server.logging.logback.VirtualHostFileLogger;
-import org.apache.qpid.server.logging.logback.VirtualHostNameAndLevelLogInclusionRule;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.Queue;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHostLogger;
-import org.apache.qpid.util.LogMonitor;
-
-public class VirtualHostLoggerRestTest extends QpidRestTestCase
-{
-
-    public void testCreateVirtualHostLoggerAndRule() throws Exception
-    {
-        String loggerName = "testLogger1";
-        String loggerRestUrlBase = "virtualhostlogger/" + TEST1_VIRTUALHOST + "/" + TEST1_VIRTUALHOST;
-        String loggerRestUrl = loggerRestUrlBase + "/" + loggerName;
-
-        Map<String, Object> virtualHostLoggerAttributes = new HashMap<>();
-        virtualHostLoggerAttributes.put(VirtualHostLogger.NAME, loggerName);
-        virtualHostLoggerAttributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
-
-        getRestTestHelper().submitRequest(loggerRestUrlBase, "PUT", virtualHostLoggerAttributes,
HttpServletResponse.SC_CREATED);
-        Map<String, Object> loggerData = getRestTestHelper().getJsonAsMap(loggerRestUrl);
-
-        String loggerRuleName = "testRule";
-        Map<String, Object> virtualHostRuleAttributes = new HashMap<>();
-        virtualHostRuleAttributes.put("name", loggerRuleName);
-        virtualHostRuleAttributes.put("level", "DEBUG");
-        virtualHostRuleAttributes.put("type", VirtualHostNameAndLevelLogInclusionRule.TYPE);
-
-        String loggerRuleRestUrlBase = "virtualhostloginclusionrule/" + TEST1_VIRTUALHOST
+ "/" + TEST1_VIRTUALHOST + "/" + loggerName;
-        String loggerRuleRestUrl = loggerRuleRestUrlBase + "/" + loggerRuleName;
-
-        getRestTestHelper().submitRequest(loggerRuleRestUrlBase, "PUT", virtualHostRuleAttributes,
HttpServletResponse.SC_CREATED);
-        getRestTestHelper().submitRequest(loggerRuleRestUrl, "GET", HttpServletResponse.SC_OK);
-
-        String logFileLocation = String.valueOf(loggerData.get(VirtualHostFileLogger.FILE_NAME));
-        assertNotNull("Log file attribute is not set ", logFileLocation);
-        assertTrue(String.format("Log file '%s' does not exists", logFileLocation), new File(logFileLocation).exists());
-
-
-        LogMonitor logMonitor = new LogMonitor(new File(logFileLocation));
-        try
-        {
-            List<String> logs = logMonitor.findMatches("QUE-1001");
-            assertEquals("Unexpected number of Queue creation operational logs before Queue
creation", 0, logs.size());
-            Map<String, Object> queueAttributes = Collections.<String, Object>singletonMap(Queue.NAME,
getTestQueueName());
-            getRestTestHelper().submitRequest("queue/" + TEST1_VIRTUALHOST + "/" + TEST1_VIRTUALHOST,
"PUT", queueAttributes, HttpServletResponse.SC_CREATED);
-            logs = logMonitor.waitAndFindMatches("QUE-1001", 1000);
-            assertEquals("Unexpected number of Queue creation operational logs after Queue
creation", 1, logs.size());
-        }
-        finally
-        {
-            logMonitor.close();
-        }
-    }
-
-    public void testDeleteVirtualHostLoggerAndRule() throws Exception
-    {
-        String loggerName = "testLogger1";
-        Map<String, Object> attributes = new HashMap<>();
-        attributes.put(VirtualHostLogger.NAME, loggerName);
-        attributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
-        String loggerRestUrlBase = "virtualhostlogger/" + TEST1_VIRTUALHOST + "/" + TEST1_VIRTUALHOST;
-        String loggerRestUrl = loggerRestUrlBase + "/" + loggerName;
-
-        getRestTestHelper().submitRequest(loggerRestUrlBase, "PUT", attributes, HttpServletResponse.SC_CREATED);
-        getRestTestHelper().submitRequest(loggerRestUrl, "GET", HttpServletResponse.SC_OK);
-
-        getRestTestHelper().submitRequest(loggerRestUrl, "DELETE", null, HttpServletResponse.SC_OK);
-        getRestTestHelper().submitRequest(loggerRestUrl, "GET", HttpServletResponse.SC_NOT_FOUND);
-    }
-
-    public void testDeleteVirtualHostLoggerAndRule_QPID_8066() throws Exception
-    {
-        final String hostRestUrl = "virtualhost/" + TEST1_VIRTUALHOST + "/" + TEST1_VIRTUALHOST;
-        final String loggerRestUrlBase = "virtualhostlogger/" + TEST1_VIRTUALHOST + "/" +
TEST1_VIRTUALHOST;
-
-        String loggerName = "testLogger1";
-        Map<String, Object> attributes = new HashMap<>();
-        attributes.put(VirtualHostLogger.NAME, loggerName);
-        attributes.put(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
-        getRestTestHelper().submitRequest(loggerRestUrlBase, "PUT", attributes, HttpServletResponse.SC_CREATED);
-
-        final String loggerRuleRestUrlBase = "virtualhostloginclusionrule/" + TEST1_VIRTUALHOST
+ "/" + TEST1_VIRTUALHOST + "/" + loggerName;
-
-        String loggerRuleName = "loggerRuleName";
-        Map<String, Object> virtualHostRuleAttributes = new HashMap<>();
-        virtualHostRuleAttributes.put("name", loggerRuleName);
-        virtualHostRuleAttributes.put("type", VirtualHostNameAndLevelLogInclusionRule.TYPE);
-        getRestTestHelper().submitRequest(loggerRuleRestUrlBase, "PUT", virtualHostRuleAttributes,
HttpServletResponse.SC_CREATED);
-
-
-        Map<String, Object> host = getRestTestHelper().getJsonAsMap(hostRestUrl);
-        assertEquals("Unexpected state before restart",
-                     State.ACTIVE.name(), host.get(ConfiguredObject.STATE));
-        assertEquals("Unexpected number of loggers before restart",
-                     1, getRestTestHelper().getJsonAsList(loggerRestUrlBase).size());
-
-        getRestTestHelper().submitRequest(loggerRestUrlBase, "DELETE", null, HttpServletResponse.SC_OK);
-
-        restartDefaultBroker();
-
-        host = getRestTestHelper().getJsonAsMap(hostRestUrl);
-        assertEquals("Unexpected state after restart",
-                     State.ACTIVE.name(), host.get(ConfiguredObject.STATE));
-
-        assertEquals("Unexpected number of loggers after restart",
-                     0, getRestTestHelper().getJsonAsList(loggerRestUrlBase).size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/a2732dd6/test-profiles/JavaTransientExcludes
----------------------------------------------------------------------
diff --git a/test-profiles/JavaTransientExcludes b/test-profiles/JavaTransientExcludes
index 6938e3b..89f437b 100644
--- a/test-profiles/JavaTransientExcludes
+++ b/test-profiles/JavaTransientExcludes
@@ -30,5 +30,4 @@ org.apache.qpid.systest.rest.VirtualHostRestTest#testRecoverVirtualHostInDesired
 org.apache.qpid.systest.rest.VirtualHostRestTest#testMutateStateOfVirtualHostWithQueuesAndMessages
 
 org.apache.qpid.systest.rest.VirtualHostNodeRestTest#testCreateAndDeleteVirtualHostNode
-org.apache.qpid.systest.rest.VirtualHostLoggerRestTest#testDeleteVirtualHostLoggerAndRule_QPID_8066
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message