diff options
| author | Keith Wall <kwall@apache.org> | 2014-05-20 15:04:11 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2014-05-20 15:04:11 +0000 |
| commit | 65af0e588588f15bbb1498403ee49f3c41ed04a0 (patch) | |
| tree | 6c249ba8f011e0b033caa5ef77ec10fc5dbcfdc4 /qpid/java/systests | |
| parent | 7371feb185388d4bedda4ac10ee7c78a17023a7e (diff) | |
| download | qpid-python-65af0e588588f15bbb1498403ee49f3c41ed04a0.tar.gz | |
QPID-5715: [Java Broker] Make virtualhosts respect the states ACTIVE and STOPPED
* Changes in virtualhost state are now persisted to store.
* VirtualHostState eliminated. The PASSIVE state used when a BDB HA Virtualhost is in replica is replaced by UNAVAILABLE.
Work by me and Andrew MacBean <andymacbean@gmail.com>.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1596281 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests')
3 files changed, 84 insertions, 32 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java index 691c533565..666409048c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java @@ -30,6 +30,8 @@ import java.util.Map; import javax.jms.JMSException; +import junit.framework.TestCase; + import org.apache.qpid.client.AMQConnection; import org.apache.qpid.server.model.Binding; import org.apache.qpid.server.model.Broker; @@ -399,4 +401,15 @@ public class Asserts assertBinding(queueName, queueName, exchange, binding); } + public static void assertActualAndDesiredState(final String expectedDesiredState, + final String expectedActualState, + final Map<String, Object> data) + { + String name = (String) data.get(ConfiguredObject.NAME); + TestCase.assertEquals("Object with name " + name + " has unexpected desired state", + expectedDesiredState, + data.get(ConfiguredObject.DESIRED_STATE)); + TestCase.assertEquals("Object with name " + name + " has unexpected actual state", + expectedActualState, data.get(ConfiguredObject.STATE)); + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java index ee638f6776..214a961b00 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java @@ -85,20 +85,20 @@ public class VirtualHostNodeRestTest extends QpidRestTestCase startBroker(); String restUrl = "virtualhostnode/" + TEST3_VIRTUALHOST; - assertVirtualHostStates(restUrl, "STOPPED", "STOPPED"); + assertActualAndDesireStates(restUrl, "STOPPED", "STOPPED"); } public void testMutateState() throws Exception { String restUrl = "virtualhostnode/" + TEST3_VIRTUALHOST; - assertVirtualHostStates(restUrl, "ACTIVE", "ACTIVE"); + assertActualAndDesireStates(restUrl, "ACTIVE", "ACTIVE"); mutateVirtualHostDesiredState(restUrl, "STOPPED"); - assertVirtualHostStates(restUrl, "STOPPED", "STOPPED"); + assertActualAndDesireStates(restUrl, "STOPPED", "STOPPED"); mutateVirtualHostDesiredState(restUrl, "ACTIVE"); - assertVirtualHostStates(restUrl, "ACTIVE", "ACTIVE"); + assertActualAndDesireStates(restUrl, "ACTIVE", "ACTIVE"); } public void testMutateAttributes() throws Exception @@ -137,16 +137,12 @@ public class VirtualHostNodeRestTest extends QpidRestTestCase assertEquals("Host should be deleted", 0, virtualHostNodes.size()); } - private void assertVirtualHostStates(final String restUrl, - final String expectedDesiredState, - final String expectedActualState) throws IOException + private void assertActualAndDesireStates(final String restUrl, + final String expectedDesiredState, + final String expectedActualState) throws IOException { Map<String, Object> virtualhostNode = getRestTestHelper().getJsonAsSingletonList(restUrl); - assertEquals("Virtualhostnode has unexpected desired state", - expectedDesiredState, - virtualhostNode.get(VirtualHostNode.DESIRED_STATE)); - assertEquals("Virtualhostnode has unexpected actual state", - expectedActualState, virtualhostNode.get(VirtualHostNode.STATE)); + Asserts.assertActualAndDesiredState(expectedDesiredState, expectedActualState, virtualhostNode); } private void mutateVirtualHostDesiredState(final String restUrl, final String newState) throws IOException diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java index 546898eb7b..9d2d79f555 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java @@ -22,6 +22,7 @@ package org.apache.qpid.systest.rest; import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -129,8 +130,9 @@ public class VirtualHostRestTest extends QpidRestTestCase public void testDeleteHost() throws Exception { - int responseCode = getRestTestHelper().submitRequest("virtualhost/" + TEST3_VIRTUALHOST + "/" + TEST3_VIRTUALHOST, "DELETE"); - assertEquals("Unexpected response code", 200, responseCode); + getRestTestHelper().submitRequest("virtualhost/" + TEST3_VIRTUALHOST + "/" + TEST3_VIRTUALHOST, + "DELETE", + HttpServletResponse.SC_OK); List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("virtualhost/" + TEST3_VIRTUALHOST); assertEquals("Host should be deleted", 0, hosts.size()); @@ -138,36 +140,66 @@ public class VirtualHostRestTest extends QpidRestTestCase public void testDeleteDefaultHostFails() throws Exception { - int responseCode = getRestTestHelper().submitRequest("virtualhost/" + TEST1_VIRTUALHOST, "DELETE"); - assertEquals("Unexpected response code", 409, responseCode); - - restartBroker(); - - List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("virtualhost/" + TEST1_VIRTUALHOST); - assertEquals("Host should be deleted", 1, hosts.size()); + getRestTestHelper().submitRequest("virtualhost/" + TEST1_VIRTUALHOST, "DELETE", HttpServletResponse.SC_CONFLICT); } - public void testUpdateActiveHost() throws Exception + public void testMutateAttributes() throws Exception { String hostToUpdate = TEST3_VIRTUALHOST; String restHostUrl = "virtualhost/" + hostToUpdate + "/" + hostToUpdate; + Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList(restHostUrl); Asserts.assertVirtualHost(hostToUpdate, hostDetails); - Map<String, Object> newAttributes = new HashMap<String, Object>(); - newAttributes.put(VirtualHost.NAME, hostToUpdate); - newAttributes.put(VirtualHost.DESCRIPTION, "This is a virtual host"); - - int response = getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes); - assertEquals("Unexpected response code", 200, response); - - restartBroker(); + Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(VirtualHost.DESCRIPTION, "This is a virtual host"); + getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); Map<String, Object> rereadHostDetails = getRestTestHelper().getJsonAsSingletonList(restHostUrl); Asserts.assertVirtualHost(hostToUpdate, rereadHostDetails); assertEquals("This is a virtual host", rereadHostDetails.get(VirtualHost.DESCRIPTION)); } + public void testMutateState() throws Exception + { + String hostToUpdate = TEST3_VIRTUALHOST; + String restHostUrl = "virtualhost/" + hostToUpdate + "/" + hostToUpdate; + + assertActualAndDesireStates(restHostUrl, "ACTIVE", "ACTIVE"); + + Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(VirtualHost.DESIRED_STATE, "STOPPED"); + getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); + + assertActualAndDesireStates(restHostUrl, "STOPPED", "STOPPED"); + + newAttributes = Collections.<String, Object>singletonMap(VirtualHost.DESIRED_STATE, "ACTIVE"); + getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); + + assertActualAndDesireStates(restHostUrl, "ACTIVE", "ACTIVE"); + } + + public void testRecoverVirtualHostInDesiredStateStoppedWithDescription() throws Exception + { + String hostToUpdate = TEST3_VIRTUALHOST; + String restUrl = "virtualhost/" + hostToUpdate + "/" + hostToUpdate; + + assertActualAndDesireStates(restUrl, "ACTIVE", "ACTIVE"); + + Map<String, Object> newAttributes = new HashMap<>(); + newAttributes.put(VirtualHost.DESIRED_STATE, "STOPPED"); + newAttributes.put(VirtualHost.DESCRIPTION, "My description"); + + getRestTestHelper().submitRequest(restUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); + + assertActualAndDesireStates(restUrl, "STOPPED", "STOPPED"); + + restartBroker(); + + Map<String, Object> rereadVirtualhost = getRestTestHelper().getJsonAsSingletonList(restUrl); + Asserts.assertActualAndDesiredState("STOPPED", "STOPPED", rereadVirtualhost); + + assertEquals("Unexpected description after restart", "My description", rereadVirtualhost.get(VirtualHost.DESCRIPTION)); + } + public void testPutCreateQueue() throws Exception { String queueName = getTestQueueName(); @@ -497,7 +529,7 @@ public class VirtualHostRestTest extends QpidRestTestCase JsonMappingException { String storePath = getStoreLocation(hostName); - int responseCode = tryCreateVirtualHost(hostName, storeType, storePath, configPath); + int responseCode = tryCreateVirtualHostNode(hostName, storeType, storePath, configPath); assertEquals("Unexpected response code", 201, responseCode); return storePath; } @@ -507,7 +539,10 @@ public class VirtualHostRestTest extends QpidRestTestCase return new File(TMP_FOLDER, "store-" + hostName + "-" + System.currentTimeMillis()).getAbsolutePath(); } - private int tryCreateVirtualHost(String hostName, String virtualHostNodeType, String storePath, String configPath) throws IOException, + private int tryCreateVirtualHostNode(String hostName, + String virtualHostNodeType, + String storePath, + String configPath) throws IOException, JsonGenerationException, JsonMappingException { @@ -542,4 +577,12 @@ public class VirtualHostRestTest extends QpidRestTestCase assertNull("Unexpected connections", hostDetails.get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE)); } + private void assertActualAndDesireStates(final String restUrl, + final String expectedDesiredState, + final String expectedActualState) throws IOException + { + Map<String, Object> virtualhost = getRestTestHelper().getJsonAsSingletonList(restUrl); + Asserts.assertActualAndDesiredState(expectedDesiredState, expectedActualState, virtualhost); + } + } |
