Search in sources :

Example 1 with IllegalStateTransitionException

use of org.apache.qpid.server.model.IllegalStateTransitionException 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(0, 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 2 with IllegalStateTransitionException

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

the class InternalBrokerHolder method start.

public void start(final Map<String, Object> systemConfig) throws Exception {
    if (Thread.getDefaultUncaughtExceptionHandler() == null) {
        Thread.setDefaultUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
    }
    LOGGER.info("Starting internal broker (same JVM)");
    _systemLauncher = new SystemLauncher(new LogbackLoggingSystemLauncherListener(), new SystemLauncherListener.DefaultSystemLauncherListener() {

        @Override
        public void onShutdown(final int exitCode) {
            _systemLauncher = null;
        }

        @Override
        public void exceptionOnShutdown(final Exception e) {
            if (e instanceof IllegalStateException || e instanceof IllegalStateTransitionException) {
                System.out.println("IllegalStateException occurred on broker shutdown in test " + getClassQualifiedTestName());
            }
        }
    });
    _systemLauncher.startup(systemConfig);
}
Also used : SystemLauncher(org.apache.qpid.server.SystemLauncher) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException)

Example 3 with IllegalStateTransitionException

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

the class BDBHARemoteReplicationNodeImpl method onDelete.

@Override
protected ListenableFuture<Void> onDelete() {
    if (!_nodeLeft) {
        SettableFuture<Void> future = SettableFuture.create();
        String nodeName = getName();
        boolean deletionAllowed;
        try {
            getEventLogger().message(_virtualHostNodeLogSubject, HighAvailabilityMessages.DELETED());
            deletionAllowed = _replicatedEnvironmentFacade.removeNodeFromGroup(nodeName);
            if (deletionAllowed) {
                future.set(null);
            } else {
                future.setException(new IllegalStateTransitionException(String.format("Node '%s' cannot be deleted when role is a master", nodeName)));
            }
        } catch (ServerScopedRuntimeException e) {
            future.setException(e);
            throw e;
        } catch (RuntimeException e) {
            future.setException(new IllegalStateTransitionException(String.format("Unexpected exception on node '%s' deletion", nodeName), e));
        }
        return future;
    } else {
        return super.onDelete();
    }
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SystemLauncher (org.apache.qpid.server.SystemLauncher)1 LogbackLoggingSystemLauncherListener (org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener)1 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 State (org.apache.qpid.server.model.State)1 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)1 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)1