diff options
| author | Alex Rudyy <orudyy@apache.org> | 2014-10-01 23:48:14 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2014-10-01 23:48:14 +0000 |
| commit | a638bc903339cac26e522df787ad4fcbca2344aa (patch) | |
| tree | 94a5bae92749b96c229ca36590e681032f6aa752 /qpid/java/bdbstore/src/test | |
| parent | f84ed512e919a6c717cbdbcc22e8139bc64bc205 (diff) | |
| download | qpid-python-a638bc903339cac26e522df787ad4fcbca2344aa.tar.gz | |
QPID-6126: Add ability to validate CO attributes on creation, transit COs into ERRORED state if exception occurs on recovery, allow ERRORED CO restart after remediation of configuration problem
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1628867 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore/src/test')
3 files changed, 285 insertions, 0 deletions
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java index e9bcc5d754..16486e3564 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java @@ -23,6 +23,8 @@ package org.apache.qpid.server.store.berkeleydb; import static org.mockito.Mockito.when; import java.io.File; +import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -53,6 +55,8 @@ import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNodeTes import org.apache.qpid.server.virtualhostnode.berkeleydb.NodeRole; import org.apache.qpid.test.utils.PortHelper; import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.util.FileUtils; public class BDBHAVirtualHostNodeTest extends QpidTestCase { @@ -587,4 +591,87 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS)); } + public void testValidateOnCreateForNonExistingHelperNode() throws Exception + { + int node1PortNumber = findFreePort(); + int node2PortNumber = getNextAvailable(node1PortNumber + 1); + + + Map<String, Object> attributes = _helper.createNodeAttributes("node1", "group", "localhost:" + node1PortNumber, + "localhost:" + node2PortNumber, "node2", node1PortNumber, node1PortNumber, node2PortNumber); + try + { + _helper.createAndStartHaVHN(attributes); + fail("Node creation should fail because of invalid helper address"); + } + catch(IllegalConfigurationException e) + { + assertEquals("Unexpected exception on connection to non-existing helper address", + String.format("Cannot connect to '%s'", "localhost:" + node2PortNumber), e.getMessage()); + } + } + + public void testValidateOnCreateForAlreadyBoundAddress() throws Exception + { + int node1PortNumber = findFreePort(); + + ServerSocket serverSocket = null; + try + { + serverSocket = new ServerSocket(); + serverSocket.setReuseAddress(true); + serverSocket.bind(new InetSocketAddress("localhost", node1PortNumber)); + + + Map<String, Object> attributes = _helper.createNodeAttributes("node1", "group", "localhost:" + node1PortNumber, + "localhost:" + node1PortNumber, "node2", node1PortNumber, node1PortNumber); + try + { + _helper.createAndStartHaVHN(attributes); + fail("Node creation should fail because of invalid address"); + } + catch(IllegalConfigurationException e) + { + assertEquals("Unexpected exception on attempt to create node with already bound address", + String.format("Cannot bind to address '%s'. Address is already in use.", "localhost:" + node1PortNumber), e.getMessage()); + } + } + finally + { + if (serverSocket != null) + { + serverSocket.close(); + } + } + } + + public void testValidateOnCreateForInvalidStorePath() throws Exception + { + int node1PortNumber = findFreePort(); + + File storeBaseFolder = TestFileUtils.createTestDirectory(); + File file = new File(storeBaseFolder, getTestName()); + file.createNewFile(); + File storePath = new File(file, "test"); + try + { + Map<String, Object> attributes = _helper.createNodeAttributes("node1", "group", "localhost:" + node1PortNumber, + "localhost:" + node1PortNumber, "node2", node1PortNumber, node1PortNumber); + attributes.put(BDBHAVirtualHostNode.STORE_PATH, storePath.getAbsoluteFile()); + try + { + _helper.createAndStartHaVHN(attributes); + fail("Node creation should fail because of invalid store path"); + } + catch (IllegalConfigurationException e) + { + assertEquals("Unexpected exception on attempt to create environment in invalid location", + String.format("Store path '%s' is not a folder", storePath.getAbsoluteFile()), e.getMessage()); + } + } + finally + { + FileUtils.delete(storeBaseFolder, true); + } + } } diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBVirtualHostImplTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBVirtualHostImplTest.java new file mode 100644 index 0000000000..92da465dbd --- /dev/null +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBVirtualHostImplTest.java @@ -0,0 +1,106 @@ +/* + * + * 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.server.virtualhost.berkeleydb; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerModel; +import org.apache.qpid.server.model.VirtualHostNode; +import org.apache.qpid.server.store.DurableConfigurationStore; +import org.apache.qpid.server.util.BrokerTestHelper; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.util.FileUtils; + +public class BDBVirtualHostImplTest extends QpidTestCase +{ + private File _storePath; + private VirtualHostNode<?> _node; + + @Override + public void setUp() throws Exception + { + super.setUp(); + Broker broker = BrokerTestHelper.createBrokerMock(); + + TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); + when(broker.getTaskExecutor()).thenReturn(taskExecutor); + + _storePath = TestFileUtils.createTestDirectory(); + + _node = mock(VirtualHostNode.class); + when(_node.getParent(Broker.class)).thenReturn(broker); + when(_node.getModel()).thenReturn(BrokerModel.getInstance()); + when(_node.getTaskExecutor()).thenReturn(taskExecutor); + when(_node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class)); + when(_node.getId()).thenReturn(UUID.randomUUID()); + } + + @Override + public void tearDown() throws Exception + { + try + { + if (_storePath != null) + { + FileUtils.delete(_storePath, true); + } + } + finally + { + super.tearDown(); + } + } + + public void testValidateOnCreateForInvalidStorePath() throws Exception + { + String hostName = getTestName(); + File file = new File(_storePath + File.separator + hostName); + assertTrue("Empty file is not created", file.createNewFile()); + Map<String, Object> attributes = new HashMap<>(); + attributes.put(BDBVirtualHost.ID, UUID.randomUUID()); + attributes.put(BDBVirtualHost.TYPE, BDBVirtualHostImpl.VIRTUAL_HOST_TYPE); + attributes.put(BDBVirtualHost.NAME, hostName); + attributes.put(BDBVirtualHost.STORE_PATH, file.getAbsoluteFile()); + + BDBVirtualHostImpl host = new BDBVirtualHostImpl(attributes, _node); + try + { + host.create(); + fail("Cannot create DBD virtual host from existing empty file"); + } + catch (IllegalConfigurationException e) + { + assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open virtual host message store")); + } + } + +} diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java new file mode 100644 index 0000000000..6608312088 --- /dev/null +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java @@ -0,0 +1,92 @@ +/* + * + * 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.server.virtualhostnode.berkeleydb; + +import static org.mockito.Mockito.when; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.util.BrokerTestHelper; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.util.FileUtils; + +public class BDBVirtualHostNodeTest extends QpidTestCase +{ + private Broker<?> _broker; + private File _storePath; + + @Override + public void setUp() throws Exception + { + super.setUp(); + _broker = BrokerTestHelper.createBrokerMock(); + when(_broker.getTaskExecutor()).thenReturn(CurrentThreadTaskExecutor.newStartedInstance()); + + _storePath = TestFileUtils.createTestDirectory(); + } + + @Override + public void tearDown() throws Exception + { + try + { + if (_storePath != null) + { + FileUtils.delete(_storePath, true); + } + } + finally + { + super.tearDown(); + } + } + + public void testValidateOnCreateForInvalidStorePath() throws Exception + { + String nodeName = getTestName(); + File file = new File(_storePath + File.separator + nodeName); + assertTrue("Empty file is not created", file.createNewFile()); + Map<String, Object> attributes = new HashMap<>(); + attributes.put(BDBVirtualHostNode.ID, UUID.randomUUID()); + attributes.put(BDBVirtualHostNode.TYPE, BDBVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE); + attributes.put(BDBVirtualHostNode.NAME, nodeName); + attributes.put(BDBVirtualHostNode.STORE_PATH, file.getAbsolutePath()); + + BDBVirtualHostNodeImpl node = new BDBVirtualHostNodeImpl(attributes, _broker); + try + { + node.create(); + fail("Cannot create DBD node from existing empty file"); + } + catch (IllegalConfigurationException e) + { + assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store")); + } + } + +} |
