Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java (original) +++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java Wed Oct 1 23:48:14 2014 @@ -37,7 +37,6 @@ import java.util.concurrent.ScheduledThr import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; import javax.security.auth.Subject; @@ -231,6 +230,47 @@ public abstract class AbstractVirtualHos } @Override + public void validateOnCreate() + { + super.validateOnCreate(); + validateMessageStoreCreation(); + } + + private void validateMessageStoreCreation() + { + MessageStore store = createMessageStore(); + if (store != null) + { + try + { + store.openMessageStore(this); + } + catch (Exception e) + { + throw new IllegalConfigurationException("Cannot open virtual host message store:" + e.getMessage(), e); + } + finally + { + try + { + store.closeMessageStore(); + } + catch(Exception e) + { + _logger.warn("Failed to close database", e); + } + } + } + } + + @Override + protected void onExceptionInOpen(RuntimeException e) + { + super.onExceptionInOpen(e); + closeMessageStore(); + } + + @Override protected void onOpen() { super.onOpen(); @@ -1355,7 +1395,7 @@ public abstract class AbstractVirtualHos getDurableConfigurationStore().create(new ConfiguredObjectRecordImpl(record.getId(), record.getType(), record.getAttributes())); } - @StateTransition( currentState = { State.UNINITIALIZED }, desiredState = State.ACTIVE ) + @StateTransition( currentState = { State.UNINITIALIZED,State.ERRORED }, desiredState = State.ACTIVE ) private void onActivate() { _houseKeepingTasks = new ScheduledThreadPoolExecutor(getHousekeepingThreadCount());
Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java (original) +++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java Wed Oct 1 23:48:14 2014 @@ -41,6 +41,7 @@ import org.apache.qpid.server.model.Virt import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.store.ConfiguredObjectRecord; import org.apache.qpid.server.store.ConfiguredObjectRecordImpl; +import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer; public abstract class AbstractStandardVirtualHostNode<X extends AbstractStandardVirtualHostNode<X>> extends AbstractVirtualHostNode<X> @@ -169,4 +170,33 @@ public abstract class AbstractStandardVi { return Collections.emptyList(); } + + @Override + public void validateOnCreate() + { + super.validateOnCreate(); + DurableConfigurationStore store = createConfigurationStore(); + if (store != null) + { + try + { + store.openConfigurationStore(this, false); + } + catch (Exception e) + { + throw new IllegalConfigurationException("Cannot open node configuration store:" + e.getMessage(), e); + } + finally + { + try + { + store.closeConfigurationStore(); + } + catch(Exception e) + { + LOGGER.warn("Failed to close database", e); + } + } + } + } } Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java (original) +++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java Wed Oct 1 23:48:14 2014 @@ -36,7 +36,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; import org.apache.log4j.Logger; @@ -100,8 +99,6 @@ public abstract class AbstractVirtualHos { super.onOpen(); _durableConfigurationStore = createConfigurationStore(); - _configurationStoreLogSubject = new MessageStoreLogSubject(getName(), _durableConfigurationStore.getClass().getSimpleName()); - } @Override @@ -167,11 +164,6 @@ public abstract class AbstractVirtualHos return _eventLogger; } - protected DurableConfigurationStore getDurableConfigurationStore() - { - return _durableConfigurationStore; - } - protected MessageStoreLogSubject getConfigurationStoreLogSubject() { return _configurationStoreLogSubject; @@ -205,11 +197,29 @@ public abstract class AbstractVirtualHos protected void stopAndSetStateTo(State stoppedState) { closeChildren(); - closeConfigurationStore(); + closeConfigurationStoreSafely(); setState(stoppedState); } @Override + protected void onExceptionInOpen(RuntimeException e) + { + super.onExceptionInOpen(e); + closeConfigurationStoreSafely(); + } + + @Override + protected void postResolve() + { + DurableConfigurationStore store = getConfigurationStore(); + if (store == null) + { + store = createConfigurationStore(); + } + _configurationStoreLogSubject = new MessageStoreLogSubject(getName(), store.getClass().getSimpleName()); + } + + @Override protected void onClose() { closeConfigurationStore(); @@ -262,6 +272,18 @@ public abstract class AbstractVirtualHos } } + private void closeConfigurationStoreSafely() + { + try + { + closeConfigurationStore(); + } + catch(Exception e) + { + LOGGER.warn("Unexpected exception on close of configuration store", e); + } + } + @Override public String getVirtualHostInitialConfiguration() { Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java?rev=1628867&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java (added) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java Wed Oct 1 23:48:14 2014 @@ -0,0 +1,76 @@ +/* + * + * 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.binding; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.qpid.common.AMQPFilterTypes; +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.exchange.ExchangeImpl; +import org.apache.qpid.server.model.Binding; +import org.apache.qpid.server.model.BrokerModel; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.test.utils.QpidTestCase; + +public class BindingImplTest extends QpidTestCase +{ + private TaskExecutor _taskExecutor; + private Model _model; + + public void setUp() throws Exception + { + super.setUp(); + _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); + _model = BrokerModel.getInstance(); + } + + public void testBindingValidationOnCreateWithInvalidSelector() + { + Map<String, String> arguments = new HashMap<>(); + arguments.put(AMQPFilterTypes.JMS_SELECTOR.toString(), "test in ("); + Map<String,Object> attributes = new HashMap<>(); + attributes.put(Binding.ARGUMENTS, arguments); + attributes.put(Binding.NAME, getTestName()); + AMQQueue queue = mock(AMQQueue.class); + when(queue.getTaskExecutor()).thenReturn(_taskExecutor); + when(queue.getModel()).thenReturn(_model); + ExchangeImpl exchange = mock(ExchangeImpl.class); + when(exchange.getTaskExecutor()).thenReturn(_taskExecutor); + when(exchange.getModel()).thenReturn(_model); + BindingImpl binding = new BindingImpl(attributes, queue, exchange); + try + { + binding.create(); + fail("Exception is expected on validation with invalid selector"); + } + catch (IllegalConfigurationException e) + { + assertTrue("Unexpected exception message " + e.getMessage(), e.getMessage().startsWith("Cannot parse JMS selector")); + } + } +} Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java Wed Oct 1 23:48:14 2014 @@ -63,7 +63,7 @@ public class FileKeyStoreCreationTest ex Map<String, Object> attributesCopy = new HashMap<String, Object>(attributes); Broker broker = mock(Broker.class); - TaskExecutor executor = new CurrentThreadTaskExecutor(); + TaskExecutor executor = CurrentThreadTaskExecutor.newStartedInstance(); when(broker.getObjectFactory()).thenReturn(_factory); when(broker.getModel()).thenReturn(_factory.getModel()); when(broker.getTaskExecutor()).thenReturn(executor); Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java Wed Oct 1 23:48:14 2014 @@ -34,6 +34,7 @@ import java.util.HashSet; import java.util.Map; import java.util.UUID; +import org.apache.qpid.server.model.BrokerShutdownProvider; import org.mockito.ArgumentCaptor; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -78,7 +79,8 @@ public class ManagementModeStoreHandlerT _taskExecutor.start(); _systemConfig = new JsonSystemConfigImpl(_taskExecutor, mock(EventLogger.class), - mock(LogRecorder.class), new BrokerOptions()); + mock(LogRecorder.class), new BrokerOptions(), + mock(BrokerShutdownProvider.class)); ConfiguredObjectRecord systemContextRecord = _systemConfig.asObjectRecord(); Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java Wed Oct 1 23:48:14 2014 @@ -26,7 +26,9 @@ import java.util.Map; import junit.framework.TestCase; +import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.testmodel.TestChildCategory; +import org.apache.qpid.server.model.testmodel.TestConfiguredObject; import org.apache.qpid.server.model.testmodel.TestModel; import org.apache.qpid.server.model.testmodel.TestRootCategory; import org.apache.qpid.server.store.ConfiguredObjectRecord; @@ -257,4 +259,129 @@ public class AbstractConfiguredObjectTes parent.getChildren(TestChildCategory.class).isEmpty()); } + public void testOpeningResultsInErroredStateWhenResolutionFails() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnPostResolve(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnPostResolve(false); + object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.ACTIVE)); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testOpeningInERROREDStateAfterFailedOpenOnDesiredStateChangeToActive() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnOpen(false); + object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.ACTIVE)); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testOpeningInERROREDStateAfterFailedOpenOnStart() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnOpen(false); + object.start(); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testDeletionERROREDStateAfterFailedOpenOnDelete() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.delete(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } + + public void testDeletionInERROREDStateAfterFailedOpenOnDesiredStateChangeToDelete() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.open(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setAttributes(Collections.<String, Object>singletonMap(Port.DESIRED_STATE, State.DELETED)); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } + + + public void testCreationWithExceptionThrownFromValidationOnCreate() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnValidationOnCreate(true); + try + { + object.create(); + fail("IllegalConfigurationException is expected to be thrown"); + } + catch(IllegalConfigurationException e) + { + //pass + } + assertFalse("Unexpected opened", object.isOpened()); + } + + public void testCreationWithoutExceptionThrownFromValidationOnCreate() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnValidationOnCreate(false); + object.create(); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testCreationWithExceptionThrownFromOnOpen() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnOpen(true); + object.create(); + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ERRORED, object.getState()); + + object.setThrowExceptionOnOpen(false); + object.start(); + assertTrue("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.ACTIVE, object.getState()); + } + + public void testCreationWithExceptionThrownFromOnCreate() throws Exception + { + TestConfiguredObject object = new TestConfiguredObject(getName()); + object.setThrowExceptionOnCreate(true); + try + { + object.create(); + fail("Exception should have been re-thrown"); + } + catch (RuntimeException re) + { + // pass + } + + assertFalse("Unexpected opened", object.isOpened()); + assertEquals("Unexpected state", State.DELETED, object.getState()); + } } Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java?rev=1628867&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java (added) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java Wed Oct 1 23:48:14 2014 @@ -0,0 +1,117 @@ +/* + * + * 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.model.adapter; + +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.security.SecurityManager; +import org.apache.qpid.test.utils.QpidTestCase; +import org.apache.qpid.test.utils.TestFileUtils; + +public class FileBasedGroupProviderImplTest extends QpidTestCase +{ + private TaskExecutor _taskExecutor; + private Broker _broker; + private File _groupFile; + + @Override + public void setUp() throws Exception + { + super.setUp(); + _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); + + _broker = mock(Broker.class); + when(_broker.getTaskExecutor()).thenReturn(_taskExecutor); + when(_broker.getModel()).thenReturn(BrokerModel.getInstance()); + when(_broker.getId()).thenReturn(UUID.randomUUID()); + when(_broker.getSecurityManager()).thenReturn(new SecurityManager(_broker, false)); + } + + @Override + public void tearDown() throws Exception + { + try + { + if (_groupFile.exists()) + { + _groupFile.delete(); + } + _taskExecutor.stop(); + } + finally + { + super.tearDown(); + } + } + + public void testValidationOnCreateWithInvalidPath() + { + Map<String,Object> attributes = new HashMap<>(); + _groupFile = TestFileUtils.createTempFile(this, "groups"); + + String groupsFile = _groupFile.getAbsolutePath() + File.separator + "groups"; + assertFalse("File should not exist", new File(groupsFile).exists()); + attributes.put(FileBasedGroupProvider.PATH, groupsFile); + attributes.put(FileBasedGroupProvider.NAME, getTestName()); + + FileBasedGroupProviderImpl groupsProvider = new FileBasedGroupProviderImpl(attributes, _broker); + try + { + groupsProvider.create(); + fail("Exception is expected on validation of groups provider with invalid path"); + } catch (IllegalConfigurationException e) + { + assertEquals("Unexpected exception message:" + e.getMessage(), String.format("Cannot create groups file at '%s'", groupsFile), e.getMessage()); + } + } + + public void testValidationOnCreateWithInvalidGroups() + { + _groupFile = TestFileUtils.createTempFile(this, "groups", "=blah"); + Map<String, Object> attributes = new HashMap<>(); + String groupsFile = _groupFile.getAbsolutePath(); + attributes.put(FileBasedGroupProvider.PATH, groupsFile); + attributes.put(FileBasedGroupProvider.NAME, getTestName()); + + FileBasedGroupProviderImpl groupsProvider = new FileBasedGroupProviderImpl(attributes, _broker); + try + { + groupsProvider.create(); + fail("Exception is expected on validation of groups provider with invalid group file"); + } + catch (IllegalConfigurationException e) + { + assertEquals("Unexpected exception message:" + e.getMessage(), String.format("Cannot load groups from '%s'", groupsFile), e.getMessage()); + } + } + +} Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderTest.java Wed Oct 1 23:48:14 2014 @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; 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.AuthenticationProvider; @@ -109,7 +110,7 @@ public class FileSystemPreferencesProvid attributes.put(ConfiguredObject.ID, UUID.randomUUID()); attributes.put(ConfiguredObject.NAME, getTestName()); _preferencesProvider = new FileSystemPreferencesProviderImpl(attributes, _authenticationProvider); - _preferencesProvider.open(); + _preferencesProvider.create(); assertEquals(State.ACTIVE, _preferencesProvider.getState()); assertTrue("Preferences file was not created", nonExistingFile.exists()); @@ -120,6 +121,57 @@ public class FileSystemPreferencesProvid } } + public void testValidationOnCreateForInvalidPath() throws Exception + { + File file = new File(TMP_FOLDER + File.separator + getTestName() + System.nanoTime() ); + file.createNewFile(); + String path = file.getAbsolutePath() + File.separator + "users"; + + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(FileSystemPreferencesProvider.PATH, path); + attributes.put(ConfiguredObject.ID, UUID.randomUUID()); + attributes.put(ConfiguredObject.NAME, getTestName()); + _preferencesProvider = new FileSystemPreferencesProviderImpl(attributes, _authenticationProvider); + + try + { + + _preferencesProvider.create(); + + fail("Creation of preferences provider with invalid path should have failed"); + } + catch(IllegalConfigurationException e) + { + assertEquals("Unexpected exception message:" + e.getMessage(), String.format("Cannot create preferences store file at '%s'", path), e.getMessage()); + } + } + + public void testValidationOnCreateWithInvalidPreferences() + { + File tmp = TestFileUtils.createTempFile(this, "preferences", "{blah:=boo}"); + try + { + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(FileSystemPreferencesProvider.PATH, tmp.getAbsolutePath()); + attributes.put(ConfiguredObject.ID, UUID.randomUUID()); + attributes.put(ConfiguredObject.NAME, getTestName()); + _preferencesProvider = new FileSystemPreferencesProviderImpl(attributes, _authenticationProvider); + try + { + _preferencesProvider.create(); + fail("Exception is expected on validation of groups provider with invalid preferences format"); + } + catch (IllegalConfigurationException e) + { + assertEquals("Unexpected exception message:" + e.getMessage(), "Cannot parse preferences json in " + tmp.getName(), e.getMessage()); + } + } + finally + { + tmp.delete(); + } + } + public void testConstructionWithEmptyFile() throws Exception { File emptyPrefsFile = new File(TMP_FOLDER, "preferences-" + getTestName() + ".json"); Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java Wed Oct 1 23:48:14 2014 @@ -54,7 +54,7 @@ import org.apache.qpid.test.utils.QpidTe public class PortFactoryTest extends QpidTestCase { private UUID _portId = UUID.randomUUID(); - private int _portNumber = 123; + private int _portNumber; private Set<String> _tcpStringSet = Collections.singleton(Transport.TCP.name()); private Set<Transport> _tcpTransports = Collections.singleton(Transport.TCP); private Set<String> _sslStringSet = Collections.singleton(Transport.SSL.name()); @@ -68,11 +68,13 @@ public class PortFactoryTest extends Qpi private String _authProviderName = "authProvider"; private AuthenticationProvider _authProvider = mock(AuthenticationProvider.class); private ConfiguredObjectFactoryImpl _factory; + private Port<?> _port; @Override protected void setUp() throws Exception { + _portNumber = findFreePort(); TaskExecutor executor = CurrentThreadTaskExecutor.newStartedInstance(); when(_authProvider.getName()).thenReturn(_authProviderName); when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(_authProvider)); @@ -109,30 +111,45 @@ public class PortFactoryTest extends Qpi _attributes.put(Port.BINDING_ADDRESS, "127.0.0.1"); } + public void tearDown() throws Exception + { + try + { + if (_port != null) + { + _port.close(); + } + } + finally + { + super.tearDown(); + } + } + public void testCreatePortWithMinimumAttributes() { Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(Port.PORT, 1); + attributes.put(Port.PORT, _portNumber); attributes.put(Port.NAME, getName()); attributes.put(Port.AUTHENTICATION_PROVIDER, _authProviderName); attributes.put(Port.DESIRED_STATE, State.QUIESCED); - Port<?> port = _factory.create(Port.class, attributes, _broker); + _port = _factory.create(Port.class, attributes, _broker); - assertNotNull(port); - assertTrue(port instanceof AmqpPort); - assertEquals("Unexpected port", 1, port.getPort()); - assertEquals("Unexpected transports", Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports()); + assertNotNull(_port); + assertTrue(_port instanceof AmqpPort); + assertEquals("Unexpected _port", _portNumber, _port.getPort()); + assertEquals("Unexpected transports", Collections.singleton(PortFactory.DEFAULT_TRANSPORT), _port.getTransports()); assertEquals("Unexpected send buffer size", PortFactory.DEFAULT_AMQP_SEND_BUFFER_SIZE, - port.getAttribute(AmqpPort.SEND_BUFFER_SIZE)); + _port.getAttribute(AmqpPort.SEND_BUFFER_SIZE)); assertEquals("Unexpected receive buffer size", PortFactory.DEFAULT_AMQP_RECEIVE_BUFFER_SIZE, - port.getAttribute(AmqpPort.RECEIVE_BUFFER_SIZE)); + _port.getAttribute(AmqpPort.RECEIVE_BUFFER_SIZE)); assertEquals("Unexpected need client auth", PortFactory.DEFAULT_AMQP_NEED_CLIENT_AUTH, - port.getAttribute(Port.NEED_CLIENT_AUTH)); + _port.getAttribute(Port.NEED_CLIENT_AUTH)); assertEquals("Unexpected want client auth", PortFactory.DEFAULT_AMQP_WANT_CLIENT_AUTH, - port.getAttribute(Port.WANT_CLIENT_AUTH)); - assertEquals("Unexpected tcp no delay", PortFactory.DEFAULT_AMQP_TCP_NO_DELAY, port.getAttribute(Port.TCP_NO_DELAY)); - assertEquals("Unexpected binding", PortFactory.DEFAULT_AMQP_BINDING, port.getAttribute(Port.BINDING_ADDRESS)); + _port.getAttribute(Port.WANT_CLIENT_AUTH)); + assertEquals("Unexpected tcp no delay", PortFactory.DEFAULT_AMQP_TCP_NO_DELAY, _port.getAttribute(Port.TCP_NO_DELAY)); + assertEquals("Unexpected binding", PortFactory.DEFAULT_AMQP_BINDING, _port.getAttribute(Port.BINDING_ADDRESS)); } public void testCreateAmqpPort() @@ -256,27 +273,27 @@ public class PortFactoryTest extends Qpi _attributes.put(Port.DESIRED_STATE, State.QUIESCED); - Port<?> port = _factory.create(Port.class, _attributes, _broker); + _port = _factory.create(Port.class, _attributes, _broker); - assertNotNull(port); - assertTrue(port instanceof AmqpPort); - assertEquals(_portId, port.getId()); - assertEquals(_portNumber, port.getPort()); + assertNotNull(_port); + assertTrue(_port instanceof AmqpPort); + assertEquals(_portId, _port.getId()); + assertEquals(_portNumber, _port.getPort()); if(useSslTransport) { - assertEquals(_sslTransports, port.getTransports()); + assertEquals(_sslTransports, _port.getTransports()); } else { - assertEquals(_tcpTransports, port.getTransports()); + assertEquals(_tcpTransports, _port.getTransports()); } - assertEquals(amqp010ProtocolSet, port.getProtocols()); - assertEquals("Unexpected send buffer size", 2, port.getAttribute(AmqpPort.SEND_BUFFER_SIZE)); - assertEquals("Unexpected receive buffer size", 1, port.getAttribute(AmqpPort.RECEIVE_BUFFER_SIZE)); - assertEquals("Unexpected need client auth", needClientAuth, port.getAttribute(Port.NEED_CLIENT_AUTH)); - assertEquals("Unexpected want client auth", wantClientAuth, port.getAttribute(Port.WANT_CLIENT_AUTH)); - assertEquals("Unexpected tcp no delay", true, port.getAttribute(Port.TCP_NO_DELAY)); - assertEquals("Unexpected binding", "127.0.0.1", port.getAttribute(Port.BINDING_ADDRESS)); + assertEquals(amqp010ProtocolSet, _port.getProtocols()); + assertEquals("Unexpected send buffer size", 2, _port.getAttribute(AmqpPort.SEND_BUFFER_SIZE)); + assertEquals("Unexpected receive buffer size", 1, _port.getAttribute(AmqpPort.RECEIVE_BUFFER_SIZE)); + assertEquals("Unexpected need client auth", needClientAuth, _port.getAttribute(Port.NEED_CLIENT_AUTH)); + assertEquals("Unexpected want client auth", wantClientAuth, _port.getAttribute(Port.WANT_CLIENT_AUTH)); + assertEquals("Unexpected tcp no delay", true, _port.getAttribute(Port.TCP_NO_DELAY)); + assertEquals("Unexpected binding", "127.0.0.1", _port.getAttribute(Port.BINDING_ADDRESS)); } public void testCreateNonAmqpPort() @@ -291,14 +308,14 @@ public class PortFactoryTest extends Qpi _attributes.put(Port.NAME, getName()); _attributes.put(Port.ID, _portId); - Port<?> port = _factory.create(Port.class, _attributes, _broker); + _port = _factory.create(Port.class, _attributes, _broker); - assertNotNull(port); - assertFalse("Port should not be an AMQP-specific subclass", port instanceof AmqpPort); - assertEquals(_portId, port.getId()); - assertEquals(_portNumber, port.getPort()); - assertEquals(_tcpTransports, port.getTransports()); - assertEquals(nonAmqpProtocolSet, port.getProtocols()); + assertNotNull(_port); + assertFalse("Port should not be an AMQP-specific subclass", _port instanceof AmqpPort); + assertEquals(_portId, _port.getId()); + assertEquals(_portNumber, _port.getPort()); + assertEquals(_tcpTransports, _port.getTransports()); + assertEquals(nonAmqpProtocolSet, _port.getProtocols()); } public void testCreateNonAmqpPortWithPartiallySetAttributes() @@ -312,14 +329,14 @@ public class PortFactoryTest extends Qpi _attributes.put(Port.NAME, getName()); _attributes.put(Port.ID, _portId); - Port<?> port = _factory.create(Port.class, _attributes, _broker); + _port = _factory.create(Port.class, _attributes, _broker); - assertNotNull(port); - assertFalse("Port not be an AMQP-specific port subclass", port instanceof AmqpPort); - assertEquals(_portId, port.getId()); - assertEquals(_portNumber, port.getPort()); - assertEquals(Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports()); - assertEquals(nonAmqpProtocolSet, port.getProtocols()); + assertNotNull(_port); + assertFalse("Port not be an AMQP-specific _port subclass", _port instanceof AmqpPort); + assertEquals(_portId, _port.getId()); + assertEquals(_portNumber, _port.getPort()); + assertEquals(Collections.singleton(PortFactory.DEFAULT_TRANSPORT), _port.getTransports()); + assertEquals(nonAmqpProtocolSet, _port.getProtocols()); } @@ -330,7 +347,7 @@ public class PortFactoryTest extends Qpi try { - Port<?> port = _factory.create(Port.class, _attributes, _broker); + _port = _factory.create(Port.class, _attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException e) @@ -353,7 +370,7 @@ public class PortFactoryTest extends Qpi try { - Port<?> port = _factory.create(Port.class, attributes, _broker); + _port = _factory.create(Port.class, attributes, _broker); fail("RMI port creation should fail as another one already exist"); } catch(IllegalConfigurationException e) @@ -377,7 +394,7 @@ public class PortFactoryTest extends Qpi try { - Port<?> port = _factory.create(Port.class, attributes, _broker); + _port = _factory.create(Port.class, attributes, _broker); fail("RMI port creation should fail due to requesting SSL"); } catch(IllegalConfigurationException e) Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/port/AmqpPortImplTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/port/AmqpPortImplTest.java?rev=1628867&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/port/AmqpPortImplTest.java (added) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/port/AmqpPortImplTest.java Wed Oct 1 23:48:14 2014 @@ -0,0 +1,104 @@ +package org.apache.qpid.server.model.port; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.util.Collections; +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.logging.EventLogger; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerModel; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.security.SecurityManager; +import org.apache.qpid.test.utils.QpidTestCase; + +public class AmqpPortImplTest extends QpidTestCase +{ + private static final String AUTHENTICATION_PROVIDER_NAME = "test"; + private TaskExecutor _taskExecutor; + private Broker _broker; + private ServerSocket _socket; + private AmqpPortImpl _port; + + @Override + public void setUp() throws Exception + { + super.setUp(); + _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); + Model model = BrokerModel.getInstance(); + + _broker = mock(Broker.class); + when(_broker.getTaskExecutor()).thenReturn(_taskExecutor); + when(_broker.getModel()).thenReturn(model); + when(_broker.getId()).thenReturn(UUID.randomUUID()); + when(_broker.getSecurityManager()).thenReturn(new SecurityManager(_broker, false)); + when(_broker.getCategoryClass()).thenReturn(Broker.class); + when(_broker.getEventLogger()).thenReturn(new EventLogger()); + AuthenticationProvider<?> provider = mock(AuthenticationProvider.class); + when(provider.getName()).thenReturn(AUTHENTICATION_PROVIDER_NAME); + when(provider.getParent(Broker.class)).thenReturn(_broker); + when(_broker.getChildren(AuthenticationProvider.class)).thenReturn(Collections.<AuthenticationProvider>singleton(provider)); + when(_broker.getChildByName(AuthenticationProvider.class, AUTHENTICATION_PROVIDER_NAME)).thenReturn(provider); + } + + @Override + public void tearDown() throws Exception + { + try + { + if (_socket != null) + { + _socket.close(); + } + _taskExecutor.stop(); + } + finally + { + if (_port != null) + { + _port.close(); + } + super.tearDown(); + } + } + + public void testValidateOnCreate() throws Exception + { + _socket = openSocket(); + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(AmqpPort.PORT, _socket.getLocalPort()); + attributes.put(AmqpPort.NAME, getTestName()); + attributes.put(AmqpPort.AUTHENTICATION_PROVIDER, AUTHENTICATION_PROVIDER_NAME); + _port = new AmqpPortImpl(attributes, _broker); + try + { + _port.create(); + fail("Creation should fail due to validation check"); + } + catch (IllegalConfigurationException e) + { + assertEquals("Unexpected exception message", + String.format("Cannot bind to port %d and binding address '%s'. Port is already is use.", + _socket.getLocalPort(), "*"), e.getMessage()); + } + } + + private ServerSocket openSocket() throws IOException + { + ServerSocket serverSocket = new ServerSocket(); + serverSocket.setReuseAddress(true); + serverSocket.bind(new InetSocketAddress(findFreePort())); + return serverSocket; + } +} Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java?rev=1628867&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java (added) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestConfiguredObject.java Wed Oct 1 23:48:14 2014 @@ -0,0 +1,123 @@ +package org.apache.qpid.server.model.testmodel; + +import static org.mockito.Mockito.mock; + +import java.util.Collections; +import java.util.Map; + +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.AbstractConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.StateTransition; + +@ManagedObject +public class TestConfiguredObject extends AbstractConfiguredObject +{ + private boolean _throwExceptionOnOpen; + private boolean _opened; + private boolean _throwExceptionOnValidationOnCreate; + private boolean _throwExceptionOnPostResolve; + private boolean _throwExceptionOnCreate; + + public TestConfiguredObject(String name) + { + this(createParents(), Collections.<String, Object>singletonMap(ConfiguredObject.NAME, name), createTaskExecutor(), new TestModel(null)); + } + + public final static Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> createParents() + { + return Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(null, mock(ConfiguredObject.class)); + } + + public final static TaskExecutor createTaskExecutor() + { + TaskExecutor taskExecutor = new CurrentThreadTaskExecutor(); + taskExecutor.start(); + return taskExecutor; + } + + public TestConfiguredObject(Map parents, Map<String, Object> attributes, TaskExecutor taskExecutor, Model model) + { + super(parents, attributes, taskExecutor, model); + _opened = false; + } + + @Override + protected void postResolve() + { + if (_throwExceptionOnPostResolve) + { + throw new IllegalConfigurationException("Cannot resolve"); + } + } + + @Override + protected void onCreate() + { + if (_throwExceptionOnCreate) + { + throw new IllegalConfigurationException("Cannot create"); + } + } + + @Override + protected void onOpen() + { + if (_throwExceptionOnOpen) + { + throw new IllegalConfigurationException("Cannot open"); + } + _opened = true; + } + + @Override + protected void validateOnCreate() + { + if (_throwExceptionOnValidationOnCreate) + { + throw new IllegalConfigurationException("Cannot validate on create"); + } + } + + @StateTransition( currentState = {State.ERRORED, State.UNINITIALIZED}, desiredState = State.ACTIVE ) + protected void activate() + { + setState(State.ACTIVE); + } + + @StateTransition( currentState = {State.ERRORED, State.UNINITIALIZED}, desiredState = State.DELETED ) + protected void doDelete() + { + setState(State.DELETED); + } + + public boolean isOpened() + { + return _opened; + } + + public void setThrowExceptionOnOpen(boolean throwException) + { + _throwExceptionOnOpen = throwException; + } + + public void setThrowExceptionOnValidationOnCreate(boolean throwException) + { + _throwExceptionOnValidationOnCreate = throwException; + } + + public void setThrowExceptionOnPostResolve(boolean throwException) + { + _throwExceptionOnPostResolve = throwException; + } + + public void setThrowExceptionOnCreate(boolean throwExceptionOnCreate) + { + _throwExceptionOnCreate = throwExceptionOnCreate; + } +} Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java Wed Oct 1 23:48:14 2014 @@ -90,31 +90,28 @@ public class PrincipalDatabaseAuthentica private void setupMocks() throws Exception { - _principalDatabase = mock(PrincipalDatabase.class); - - when(_principalDatabase.getMechanisms()).thenReturn(Collections.singletonList(MOCK_MECH_NAME)); - when(_principalDatabase.createSaslServer(MOCK_MECH_NAME, LOCALHOST, null)).thenReturn(new MySaslServer(false, true)); + setUpPrincipalDatabase(); setupManager(false); _manager.initialise(); } + private void setUpPrincipalDatabase() throws SaslException + { + _principalDatabase = mock(PrincipalDatabase.class); + + when(_principalDatabase.getMechanisms()).thenReturn(Collections.singletonList(MOCK_MECH_NAME)); + when(_principalDatabase.createSaslServer(MOCK_MECH_NAME, LOCALHOST, null)).thenReturn(new MySaslServer(false, true)); + } + private void setupManager(final boolean recovering) { Map<String,Object> attrs = new HashMap<String, Object>(); attrs.put(ConfiguredObject.ID, UUID.randomUUID()); attrs.put(ConfiguredObject.NAME, getTestName()); attrs.put("path", _passwordFileLocation); - _manager = new PrincipalDatabaseAuthenticationManager(attrs, BrokerTestHelper.createBrokerMock()) - { - @Override - protected PrincipalDatabase createDatabase() - { - return _principalDatabase; - } - - }; + _manager = getPrincipalDatabaseAuthenticationManager(attrs); if(recovering) { _manager.open(); @@ -273,6 +270,41 @@ public class PrincipalDatabaseAuthentica assertFalse("Password file was not deleted", new File(_passwordFileLocation).exists()); } + public void testCreateForInvalidPath() throws Exception + { + setUpPrincipalDatabase(); + + Map<String,Object> attrs = new HashMap<>(); + attrs.put(ConfiguredObject.ID, UUID.randomUUID()); + attrs.put(ConfiguredObject.NAME, getTestName()); + String path = TMP_FOLDER + File.separator + getTestName() + System.nanoTime() + File.separator + "users"; + attrs.put("path", path); + + _manager = getPrincipalDatabaseAuthenticationManager(attrs); + try + { + _manager.create(); + fail("Creation with invalid path should have failed"); + } + catch(IllegalConfigurationException e) + { + assertEquals("Unexpected exception message:" + e.getMessage(), String.format("Cannot create password file at '%s'", path), e.getMessage()); + } + } + + PrincipalDatabaseAuthenticationManager getPrincipalDatabaseAuthenticationManager(final Map<String, Object> attrs) + { + return new PrincipalDatabaseAuthenticationManager(attrs, BrokerTestHelper.createBrokerMock()) + { + @Override + protected PrincipalDatabase createDatabase() + { + return _principalDatabase; + } + + }; + } + private void deletePasswordFileIfExists() { File passwordFile = new File(_passwordFileLocation); Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerRecovererTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerRecovererTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerRecovererTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerRecovererTest.java Wed Oct 1 23:48:14 2014 @@ -21,7 +21,9 @@ package org.apache.qpid.server.store; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; import java.util.Arrays; import java.util.Collections; @@ -40,6 +42,7 @@ import org.apache.qpid.server.logging.Lo import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.BrokerModel; +import org.apache.qpid.server.model.BrokerShutdownProvider; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.model.JsonSystemConfigImpl; @@ -55,6 +58,7 @@ public class BrokerRecovererTest extends private UUID _authenticationProvider1Id = UUID.randomUUID(); private SystemConfig<?> _systemConfig; private TaskExecutor _taskExecutor; + private BrokerShutdownProvider _brokerShutdownProvider; @Override protected void setUp() throws Exception @@ -63,8 +67,11 @@ public class BrokerRecovererTest extends _taskExecutor = new CurrentThreadTaskExecutor(); _taskExecutor.start(); + _brokerShutdownProvider = mock(BrokerShutdownProvider.class); _systemConfig = new JsonSystemConfigImpl(_taskExecutor, - mock(EventLogger.class), mock(LogRecorder.class), new BrokerOptions()); + mock(EventLogger.class), mock(LogRecorder.class), + new BrokerOptions(), + _brokerShutdownProvider); when(_brokerEntry.getId()).thenReturn(_brokerId); when(_brokerEntry.getType()).thenReturn(Broker.class.getSimpleName()); @@ -251,18 +258,10 @@ public class BrokerRecovererTest extends brokerAttributes.put(Broker.NAME, getName()); when(_brokerEntry.getAttributes()).thenReturn(brokerAttributes); - try - { - resolveObjects(_brokerEntry); - Broker<?> broker = _systemConfig.getBroker(); - broker.open(); - fail("The broker creation should fail due to unsupported model version"); - } - catch (IllegalConfigurationException e) - { - assertEquals("The model version '" + incompatibleVersion - + "' in configuration is incompatible with the broker model version '" + BrokerModel.MODEL_VERSION + "'", e.getMessage()); - } + resolveObjects(_brokerEntry); + Broker<?> broker = _systemConfig.getBroker(); + broker.open(); + verify(_brokerShutdownProvider).shutdown(); } } @@ -276,20 +275,12 @@ public class BrokerRecovererTest extends when(_brokerEntry.getAttributes()).thenReturn(brokerAttributes); - try - { - UnresolvedConfiguredObject<? extends ConfiguredObject> recover = - _systemConfig.getObjectFactory().recover(_brokerEntry, _systemConfig); + UnresolvedConfiguredObject<? extends ConfiguredObject> recover = + _systemConfig.getObjectFactory().recover(_brokerEntry, _systemConfig); - Broker<?> broker = (Broker<?>) recover.resolve(); - broker.open(); - fail("The broker creation should fail due to unsupported model version"); - } - catch (IllegalConfigurationException e) - { - assertEquals("The model version '" + incompatibleVersion - + "' in configuration is incompatible with the broker model version '" + BrokerModel.MODEL_VERSION + "'", e.getMessage()); - } + Broker<?> broker = (Broker<?>) recover.resolve(); + broker.open(); + verify(_brokerShutdownProvider).shutdown(); } public void testIncorrectModelVersion() throws Exception @@ -303,18 +294,12 @@ public class BrokerRecovererTest extends brokerAttributes.put(Broker.MODEL_VERSION, modelVersion); when(_brokerEntry.getAttributes()).thenReturn(brokerAttributes); - try - { - UnresolvedConfiguredObject<? extends ConfiguredObject> recover = - _systemConfig.getObjectFactory().recover(_brokerEntry, _systemConfig); - Broker<?> broker = (Broker<?>) recover.resolve(); - broker.open(); - fail("The broker creation should fail due to unsupported model version"); - } - catch (IllegalConfigurationException e) - { - // pass - } + UnresolvedConfiguredObject<? extends ConfiguredObject> recover = + _systemConfig.getObjectFactory().recover(_brokerEntry, _systemConfig); + Broker<?> broker = (Broker<?>) recover.resolve(); + broker.open(); + verify(_brokerShutdownProvider).shutdown(); + reset(_brokerShutdownProvider); } } Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/BrokerStoreUpgraderAndRecovererTest.java Wed Oct 1 23:48:14 2014 @@ -32,6 +32,7 @@ import org.apache.qpid.server.BrokerOpti import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; import org.apache.qpid.server.logging.EventLogger; import org.apache.qpid.server.logging.LogRecorder; +import org.apache.qpid.server.model.BrokerShutdownProvider; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.JsonSystemConfigImpl; import org.apache.qpid.server.model.SystemConfig; @@ -60,7 +61,8 @@ public class BrokerStoreUpgraderAndRecov _systemConfig = new JsonSystemConfigImpl(_taskExecutor, mock(EventLogger.class), mock(LogRecorder.class), - new BrokerOptions()); + new BrokerOptions(), + mock(BrokerShutdownProvider.class)); } public void testUpgradeVirtualHostWithJDBCStoreAndBoneCPPool() Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java?rev=1628867&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java (added) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/AbstractVirtualHostTest.java Wed Oct 1 23:48:14 2014 @@ -0,0 +1,247 @@ +/* + * + * 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; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.doThrow; + +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.configuration.updater.TaskExecutorImpl; +import org.apache.qpid.server.logging.EventLogger; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerModel; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.SystemConfig; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.model.VirtualHostNode; +import org.apache.qpid.server.security.SecurityManager; +import org.apache.qpid.server.store.DurableConfigurationStore; +import org.apache.qpid.server.store.MessageStore; +import org.apache.qpid.test.utils.QpidTestCase; +import org.mockito.verification.VerificationMode; + +public class AbstractVirtualHostTest extends QpidTestCase +{ + private TaskExecutor _taskExecutor; + private VirtualHostNode<?> _node; + private MessageStore _failingStore; + + @Override + public void setUp() throws Exception + { + super.setUp(); + + SystemConfig systemConfig = mock(SystemConfig.class); + when(systemConfig.getEventLogger()).thenReturn(mock(EventLogger.class)); + Broker<?> broker = mock(Broker.class); + when(broker.getParent(SystemConfig.class)).thenReturn(systemConfig); + when(broker.getSecurityManager()).thenReturn(new SecurityManager(broker, false)); + + _taskExecutor = new TaskExecutorImpl(); + _taskExecutor.start(); + when(broker.getTaskExecutor()).thenReturn(_taskExecutor); + + _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)); + + _failingStore = mock(MessageStore.class); + doThrow(new RuntimeException("Cannot open store")).when(_failingStore).openMessageStore(any(ConfiguredObject.class)); + } + + @Override + public void tearDown() throws Exception + { + try + { + if (_taskExecutor != null) + { + _taskExecutor.stopImmediately(); + } + } + finally + { + super.tearDown(); + } + } + + public void testValidateOnCreateFails() + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return _failingStore; + } + }; + + try + { + host.validateOnCreate(); + fail("Validation on creation should fail"); + } + catch(IllegalConfigurationException e) + { + assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open virtual host message store")); + } + } + + public void testValidateOnCreateSucceeds() + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + final MessageStore store = mock(MessageStore.class); + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return store; + } + }; + + host.validateOnCreate(); + verify(store).openMessageStore(host); + verify(store).closeMessageStore(); + } + + public void testOpenFails() + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return _failingStore; + } + }; + + host.open(); + assertEquals("Unexpected host state", State.ERRORED, host.getState()); + } + + public void testOpenSucceeds() + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + final MessageStore store = mock(MessageStore.class); + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return store; + } + }; + + host.open(); + assertEquals("Unexpected host state", State.ACTIVE, host.getState()); + verify(store).openMessageStore(host); + + // make sure that method AbstractVirtualHost.onExceptionInOpen was not called + verify(store, times(0)).closeMessageStore(); + } + + public void testDeleteInErrorStateAfterOpen() + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return _failingStore; + } + }; + + host.open(); + + assertEquals("Unexpected state", State.ERRORED, host.getState()); + + host.delete(); + assertEquals("Unexpected state", State.DELETED, host.getState()); + } + + public void testActivateInErrorStateAfterOpen() throws Exception + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + final MessageStore store = mock(MessageStore.class); + doThrow(new RuntimeException("Cannot open store")).when(store).openMessageStore(any(ConfiguredObject.class)); + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return store; + } + }; + + host.open(); + assertEquals("Unexpected state", State.ERRORED, host.getState()); + + doNothing().when(store).openMessageStore(any(ConfiguredObject.class)); + + host.setAttributes(Collections.<String, Object>singletonMap(VirtualHost.DESIRED_STATE, State.ACTIVE)); + assertEquals("Unexpected state", State.ACTIVE, host.getState()); + } + + public void testStartInErrorStateAfterOpen() throws Exception + { + Map<String,Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName()); + final MessageStore store = mock(MessageStore.class); + doThrow(new RuntimeException("Cannot open store")).when(store).openMessageStore(any(ConfiguredObject.class)); + AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) + { + @Override + protected MessageStore createMessageStore() + { + return store; + } + }; + + host.open(); + assertEquals("Unexpected state", State.ERRORED, host.getState()); + + doNothing().when(store).openMessageStore(any(ConfiguredObject.class)); + + host.start(); + assertEquals("Unexpected state", State.ACTIVE, host.getState()); + } +} Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java Wed Oct 1 23:48:14 2014 @@ -20,22 +20,30 @@ */ package org.apache.qpid.server.virtualhostnode; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.security.AccessControlException; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; +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.ConfiguredObject; import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl; import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.model.RemoteReplicationNode; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.SystemConfig; import org.apache.qpid.server.model.VirtualHost; @@ -348,6 +356,132 @@ public class AbstractStandardVirtualHost assertEquals("Virtual host node state changed unexpectedly", State.ACTIVE, node.getState()); } + public void testValidateOnCreateFails() throws Exception + { + String nodeName = getTestName(); + Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName); + + final DurableConfigurationStore store = mock(DurableConfigurationStore.class); + doThrow(new RuntimeException("Cannot open store")).when(store).openConfigurationStore(any(ConfiguredObject.class), any(boolean.class)); + AbstractStandardVirtualHostNode node = createAbstractStandardVirtualHostNode(attributes, store); + + try + { + node.validateOnCreate(); + fail("Cannot create node"); + } + catch (IllegalConfigurationException e) + { + assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store")); + } + } + + 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 = createAbstractStandardVirtualHostNode(attributes, store); + + node.validateOnCreate(); + verify(store).openConfigurationStore(node, false); + verify(store).closeConfigurationStore(); + } + + public void testOpenFails() throws Exception + { + String nodeName = getTestName(); + Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName); + + DurableConfigurationStore store = mock(DurableConfigurationStore.class); + AbstractVirtualHostNode node = new TestAbstractVirtualHostNode( _broker, attributes, store); + node.open(); + assertEquals("Unexpected node state", State.ERRORED, node.getState()); + } + + 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()); + } + + + public void testDeleteInErrorStateAfterOpen() + { + String nodeName = getTestName(); + Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName); + + final DurableConfigurationStore store = mock(DurableConfigurationStore.class); + doThrow(new RuntimeException("Cannot open store")).when(store).openConfigurationStore(any(ConfiguredObject.class), any(boolean.class)); + AbstractStandardVirtualHostNode node = createAbstractStandardVirtualHostNode(attributes, store); + node.open(); + assertEquals("Unexpected node state", State.ERRORED, node.getState()); + + node.delete(); + assertEquals("Unexpected state", State.DELETED, node.getState()); + } + + 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).openConfigurationStore(any(ConfiguredObject.class), any(boolean.class)); + AbstractVirtualHostNode node = createAbstractStandardVirtualHostNode(attributes, store); + node.open(); + assertEquals("Unexpected node state", State.ERRORED, node.getState()); + doNothing().when(store).openConfigurationStore(any(ConfiguredObject.class), any(boolean.class)); + + node.setAttributes(Collections.<String, Object>singletonMap(VirtualHostNode.DESIRED_STATE, State.ACTIVE)); + assertEquals("Unexpected state", State.ACTIVE, node.getState()); + } + + public void testStartInErrorStateAfterOpen() 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).openConfigurationStore(any(ConfiguredObject.class), any(boolean.class)); + AbstractVirtualHostNode node = createAbstractStandardVirtualHostNode(attributes, store); + node.open(); + assertEquals("Unexpected node state", State.ERRORED, node.getState()); + doNothing().when(store).openConfigurationStore(any(ConfiguredObject.class), any(boolean.class)); + + node.start(); + assertEquals("Unexpected state", State.ACTIVE, node.getState()); + } + private ConfiguredObjectRecord createVirtualHostConfiguredObjectRecord(UUID virtualHostId) { Map<String, Object> virtualHostAttributes = new HashMap<>(); @@ -384,4 +518,62 @@ public class AbstractStandardVirtualHost return configStoreThatProduces(null); } + + private AbstractStandardVirtualHostNode createAbstractStandardVirtualHostNode(final Map<String, Object> attributes, final DurableConfigurationStore store) + { + return new AbstractStandardVirtualHostNode(attributes, _broker){ + + @Override + protected void writeLocationEventLog() + { + + } + + @Override + protected DurableConfigurationStore createConfigurationStore() + { + return store; + } + }; + } + + private class TestAbstractVirtualHostNode extends AbstractVirtualHostNode + { + private DurableConfigurationStore _store; + + public TestAbstractVirtualHostNode(Broker parent, Map attributes, DurableConfigurationStore store) + { + super(parent, attributes); + _store = store; + } + + @Override + public void onValidate() + { + throw new RuntimeException("Cannot validate"); + } + + @Override + protected DurableConfigurationStore createConfigurationStore() + { + return _store; + } + + @Override + protected void activate() + { + } + + @Override + protected ConfiguredObjectRecord enrichInitialVirtualHostRootRecord(ConfiguredObjectRecord vhostRecord) + { + return null; + } + + @Override + public Collection<? extends RemoteReplicationNode> getRemoteReplicationNodes() + { + return null; + } + } } Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java (original) +++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java Wed Oct 1 23:48:14 2014 @@ -53,6 +53,12 @@ public class TestVirtualHostNode extends } @Override + public DurableConfigurationStore getConfigurationStore() + { + return _store; + } + + @Override protected void writeLocationEventLog() { } Modified: qpid/trunk/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java (original) +++ qpid/trunk/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImpl.java Wed Oct 1 23:48:14 2014 @@ -25,10 +25,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; import org.apache.log4j.Logger; +import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.AccessControlProvider; import org.apache.qpid.server.model.Broker; @@ -83,6 +83,29 @@ public class ACLFileAccessControlProvide } @Override + protected void validateOnCreate() + { + DefaultAccessControl accessControl = null; + try + { + accessControl = new DefaultAccessControl(getPath(), _broker); + accessControl.validate(); + accessControl.open(); + } + catch(RuntimeException e) + { + throw new IllegalConfigurationException(e.getMessage(), e); + } + finally + { + if (accessControl != null) + { + accessControl.close(); + } + } + } + + @Override protected void onOpen() { super.onOpen(); @@ -105,6 +128,7 @@ public class ACLFileAccessControlProvide @StateTransition(currentState = {State.UNINITIALIZED, State.QUIESCED, State.ERRORED}, desiredState = State.ACTIVE) private void activate() { + if(_broker.isManagementMode()) { @@ -136,7 +160,10 @@ public class ACLFileAccessControlProvide protected void onClose() { super.onClose(); - _accessControl.close(); + if (_accessControl != null) + { + _accessControl.close(); + } } @StateTransition(currentState = State.UNINITIALIZED, desiredState = State.QUIESCED) Added: qpid/trunk/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImplTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImplTest.java?rev=1628867&view=auto ============================================================================== --- qpid/trunk/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImplTest.java (added) +++ qpid/trunk/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProviderImplTest.java Wed Oct 1 23:48:14 2014 @@ -0,0 +1,79 @@ +/* + * + * 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.security.access.plugins; + + +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.Model; +import org.apache.qpid.test.utils.QpidTestCase; + +public class ACLFileAccessControlProviderImplTest extends QpidTestCase +{ + private TaskExecutor _taskExecutor; + private Model _model; + private Broker _broker; + + public void setUp() throws Exception + { + super.setUp(); + _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); + _model = BrokerModel.getInstance(); + + _broker = mock(Broker.class); + when(_broker.getTaskExecutor()).thenReturn(_taskExecutor); + when(_broker.getModel()).thenReturn(_model); + when(_broker.getId()).thenReturn(UUID.randomUUID()); + } + + public void testValidationOnCreateWithNonExistingACLFile() + { + Map<String,Object> attributes = new HashMap<>(); + String aclFilePath = TMP_FOLDER + File.separator + "test_" + getTestName() + System.nanoTime() + ".acl"; + attributes.put("path", aclFilePath); + attributes.put(ACLFileAccessControlProvider.NAME, getTestName()); + + + ACLFileAccessControlProviderImpl aclProvider = new ACLFileAccessControlProviderImpl(attributes, _broker); + try + { + aclProvider.create(); + fail("Exception is expected on validation with non-existing ACL file"); + } + catch (IllegalConfigurationException e) + { + assertEquals("Unexpected exception message:" + e.getMessage(), String.format("ACL file '%s' is not found", aclFilePath ), e.getMessage()); + } + } + +} Modified: qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbySystemConfigImpl.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbySystemConfigImpl.java?rev=1628867&r1=1628866&r2=1628867&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbySystemConfigImpl.java (original) +++ qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbySystemConfigImpl.java Wed Oct 1 23:48:14 2014 @@ -26,6 +26,7 @@ import org.apache.qpid.server.logging.Ev import org.apache.qpid.server.logging.LogRecorder; import org.apache.qpid.server.model.AbstractSystemConfig; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.BrokerShutdownProvider; import org.apache.qpid.server.model.ManagedAttributeField; import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.SystemConfigFactoryConstructor; @@ -47,9 +48,10 @@ public class DerbySystemConfigImpl exten public DerbySystemConfigImpl(final TaskExecutor taskExecutor, final EventLogger eventLogger, final LogRecorder logRecorder, - final BrokerOptions brokerOptions) + final BrokerOptions brokerOptions, + final BrokerShutdownProvider brokerShutdownProvider) { - super(taskExecutor, eventLogger, logRecorder, brokerOptions); + super(taskExecutor, eventLogger, logRecorder, brokerOptions, brokerShutdownProvider); } @Override --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org