Search in sources :

Example 1 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testActivateInErrorStateAfterOpen.

@Test
public void testActivateInErrorStateAfterOpen() throws Exception {
    String nodeName = getTestName();
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName);
    DurableConfigurationStore store = mock(DurableConfigurationStore.class);
    doThrow(new RuntimeException("Cannot open store")).when(store).init(any(ConfiguredObject.class));
    AbstractVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
    node.open();
    assertEquals("Unexpected node state", State.ERRORED, node.getState());
    doNothing().when(store).init(any(ConfiguredObject.class));
    node.setAttributes(Collections.<String, Object>singletonMap(VirtualHostNode.DESIRED_STATE, State.ACTIVE));
    assertEquals("Unexpected state", State.ACTIVE, node.getState());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 2 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testOpenSucceeds.

@Test
public void testOpenSucceeds() throws Exception {
    String nodeName = getTestName();
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName);
    final AtomicBoolean onFailureFlag = new AtomicBoolean();
    DurableConfigurationStore store = mock(DurableConfigurationStore.class);
    AbstractVirtualHostNode node = new TestAbstractVirtualHostNode(_broker, attributes, store) {

        @Override
        public void onValidate() {
        // no op
        }

        @Override
        protected void onExceptionInOpen(RuntimeException e) {
            try {
                super.onExceptionInOpen(e);
            } finally {
                onFailureFlag.set(true);
            }
        }
    };
    node.open();
    assertEquals("Unexpected node state", State.ACTIVE, node.getState());
    assertFalse("onExceptionInOpen was called", onFailureFlag.get());
    node.close();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 3 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testActivateVHN_StoreHasNoVH.

/**
 *  Tests activating a virtualhostnode with a config store which does not specify
 *  a virtualhost.  Checks no virtualhost is created.
 */
@Test
public void testActivateVHN_StoreHasNoVH() throws Exception {
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.open();
    node.start();
    VirtualHost<?> virtualHost = node.getVirtualHost();
    assertNull("Virtual host should not be automatically created", virtualHost);
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 4 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testStopStartVHN.

@Test
public void testStopStartVHN() throws Exception {
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.open();
    node.start();
    assertEquals("Unexpected virtual host node state", State.ACTIVE, node.getState());
    node.stop();
    assertEquals("Unexpected virtual host node state after stop", State.STOPPED, node.getState());
    node.start();
    assertEquals("Unexpected virtual host node state after start", State.ACTIVE, node.getState());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 5 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testValidateOnCreateSucceeds.

@Test
public void testValidateOnCreateSucceeds() throws Exception {
    String nodeName = getTestName();
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName);
    final DurableConfigurationStore store = mock(DurableConfigurationStore.class);
    AbstractStandardVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
    node.create();
    // once of validation, once for real
    verify(store, times(2)).init(node);
    verify(store, times(1)).closeConfigurationStore();
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)30 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)21 Test (org.junit.Test)18 HashMap (java.util.HashMap)14 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)4 AccessControlException (java.security.AccessControlException)3 AccessControl (org.apache.qpid.server.security.AccessControl)3 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)3 UUID (java.util.UUID)2 AbstractSystemConfig (org.apache.qpid.server.model.AbstractSystemConfig)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 TestMemoryVirtualHost (org.apache.qpid.server.virtualhost.TestMemoryVirtualHost)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 ReplicationGroupAdmin (com.sleepycat.je.rep.util.ReplicationGroupAdmin)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1