Search in sources :

Example 1 with AbstractConfigurationChangeListener

use of org.apache.qpid.server.model.AbstractConfigurationChangeListener in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testIntruderProtectionInManagementMode.

@Test
public void testIntruderProtectionInManagementMode() throws Exception {
    int nodePortNumber = _portHelper.getNextAvailable();
    int intruderPortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + nodePortNumber;
    String groupName = "group";
    String nodeName = "node";
    Map<String, Object> nodeAttributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
    BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(nodeAttributes);
    final CountDownLatch stopLatch = new CountDownLatch(1);
    ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
            if (newState == State.ERRORED) {
                stopLatch.countDown();
            }
        }
    };
    node.addChangeListener(listener);
    File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + "intruder");
    Durability durability = Durability.parse((String) nodeAttributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(intruderPortNumber, "intruder", groupName, helperAddress, durability, environmentPathFile);
    LOGGER.debug("Permitted and intruder nodes are created");
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
    LOGGER.debug("Master node transited into ERRORED state due to intruder protection");
    when(_helper.getBroker().isManagementMode()).thenReturn(true);
    LOGGER.debug("Starting node in management mode");
    final CountDownLatch stateChangeLatch = new CountDownLatch(1);
    final CountDownLatch roleChangeLatch = new CountDownLatch(1);
    node.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
            if (newState == State.ERRORED) {
                stateChangeLatch.countDown();
            }
        }

        @Override
        public void attributeSet(final ConfiguredObject<?> object, final String attributeName, final Object oldAttributeValue, final Object newAttributeValue) {
            if (BDBHAVirtualHostNode.ROLE.equals(attributeName) && NodeRole.DETACHED.equals(NodeRole.DETACHED)) {
                roleChangeLatch.countDown();
            }
        }
    });
    node.start();
    LOGGER.debug("Node is started");
    // verify that intruder detection is triggered after restart and environment is closed
    assertTrue("Node state was not set to ERRORED", stateChangeLatch.await(10, TimeUnit.SECONDS));
    assertTrue("Node role was not set to DETACHED", roleChangeLatch.await(10, TimeUnit.SECONDS));
}
Also used : Durability(com.sleepycat.je.Durability) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfigurationChangeListener(org.apache.qpid.server.model.ConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) File(java.io.File) Test(org.junit.Test)

Example 2 with AbstractConfigurationChangeListener

use of org.apache.qpid.server.model.AbstractConfigurationChangeListener in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testIntruderConnected.

@Test
public void testIntruderConnected() throws Exception {
    int node1PortNumber = _portHelper.getNextAvailable();
    int node2PortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + node1PortNumber;
    String groupName = "group";
    String nodeName = "node1";
    Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
    BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
    final CountDownLatch stopLatch = new CountDownLatch(1);
    ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
            if (newState == State.ERRORED) {
                stopLatch.countDown();
            }
        }
    };
    node1.addChangeListener(listener);
    String node2Name = "node2";
    File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + node2Name);
    Durability durability = Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(node2PortNumber, node2Name, groupName, helperAddress, durability, environmentPathFile);
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS));
}
Also used : ConfigurationChangeListener(org.apache.qpid.server.model.ConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) State(org.apache.qpid.server.model.State) Durability(com.sleepycat.je.Durability) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) Test(org.junit.Test)

Example 3 with AbstractConfigurationChangeListener

use of org.apache.qpid.server.model.AbstractConfigurationChangeListener in project qpid-broker-j by apache.

the class AbstractConfiguredObjectTest method XtestUnsuccessfulStateTransitionDoesNotInvokesListener.

// TODO - not sure if I want to keep the state transition methods on delete
public void XtestUnsuccessfulStateTransitionDoesNotInvokesListener() throws Exception {
    final IllegalStateTransitionException expectedException = new IllegalStateTransitionException("This test fails the state transition.");
    TestConfiguredObject parent = new TestConfiguredObject("parent") {

        @Override
        protected ListenableFuture<Void> doDelete() {
            throw expectedException;
        }
    };
    parent.create();
    final AtomicInteger callCounter = new AtomicInteger();
    parent.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State old, final State state) {
            super.stateChanged(object, old, state);
            callCounter.incrementAndGet();
        }

        @Override
        public void attributeSet(ConfiguredObject<?> object, String attributeName, Object oldAttributeValue, Object newAttributeValue) {
            super.attributeSet(object, attributeName, oldAttributeValue, newAttributeValue);
            callCounter.incrementAndGet();
        }
    });
    try {
        parent.delete();
        fail("Exception not thrown.");
    } catch (RuntimeException e) {
        assertSame("State transition threw unexpected exception.", expectedException, e);
    }
    assertEquals((long) 0, (long) callCounter.get());
    assertEquals(State.ACTIVE, parent.getDesiredState());
    assertEquals(State.ACTIVE, parent.getState());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 4 with AbstractConfigurationChangeListener

use of org.apache.qpid.server.model.AbstractConfigurationChangeListener in project qpid-broker-j by apache.

the class AbstractConfiguredObjectTest method testSuccessfulStateTransitionInvokesListener.

@Test
public void testSuccessfulStateTransitionInvokesListener() throws Exception {
    TestConfiguredObject parent = new TestConfiguredObject("parent");
    parent.create();
    final AtomicReference<State> newState = new AtomicReference<>();
    final AtomicInteger callCounter = new AtomicInteger();
    parent.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State old, final State state) {
            super.stateChanged(object, old, state);
            callCounter.incrementAndGet();
            newState.set(state);
        }
    });
    parent.delete();
    assertEquals(State.DELETED, newState.get());
    assertEquals((long) 1, (long) callCounter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) State(org.apache.qpid.server.model.State) AtomicReference(java.util.concurrent.atomic.AtomicReference) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) Test(org.junit.Test)

Example 5 with AbstractConfigurationChangeListener

use of org.apache.qpid.server.model.AbstractConfigurationChangeListener in project qpid-broker-j by apache.

the class AbstractTrustStore method initializeExpiryChecking.

void initializeExpiryChecking() {
    int checkFrequency = getCertificateExpiryCheckFrequency();
    if (getBroker().getState() == State.ACTIVE) {
        _checkExpiryTaskFuture = getBroker().scheduleHouseKeepingTask(checkFrequency, TimeUnit.DAYS, this::checkCertificateExpiry);
    } else {
        final int frequency = checkFrequency;
        getBroker().addChangeListener(new AbstractConfigurationChangeListener() {

            @Override
            public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
                if (newState == State.ACTIVE) {
                    _checkExpiryTaskFuture = getBroker().scheduleHouseKeepingTask(frequency, TimeUnit.DAYS, () -> checkCertificateExpiry());
                    getBroker().removeChangeListener(this);
                }
            }
        });
    }
}
Also used : State(org.apache.qpid.server.model.State) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Aggregations

AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)17 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)14 State (org.apache.qpid.server.model.State)11 Test (org.junit.Test)10 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Durability (com.sleepycat.je.Durability)3 File (java.io.File)3 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)3 ConfigurationChangeListener (org.apache.qpid.server.model.ConfigurationChangeListener)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)2 VirtualHost (org.apache.qpid.server.model.VirtualHost)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 Collection (java.util.Collection)1 StoreConfigurationChangeListener (org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener)1 Broker (org.apache.qpid.server.model.Broker)1