use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class BrokerTestHelper method createVirtualHost.
private static QueueManagingVirtualHost<?> createVirtualHost(final Map<String, Object> attributes, final Broker<?> broker, boolean defaultVHN, AccessControl accessControl) {
ConfiguredObjectFactory objectFactory = broker.getObjectFactory();
VirtualHostNode virtualHostNode = mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, SYSTEM_PRINCIPAL, accessControl);
String virtualHostNodeName = String.format("%s_%s", attributes.get(VirtualHostNode.NAME), "_node");
when(virtualHostNode.getName()).thenReturn(virtualHostNodeName);
when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.getChildExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.isDefaultVirtualHostNode()).thenReturn(defaultVHN);
when(virtualHostNode.getParent()).thenReturn(broker);
Collection<VirtualHostNode<?>> nodes = broker.getVirtualHostNodes();
nodes = new ArrayList<>(nodes != null ? nodes : Collections.<VirtualHostNode<?>>emptyList());
nodes.add(virtualHostNode);
when(broker.getVirtualHostNodes()).thenReturn(nodes);
DurableConfigurationStore dcs = mock(DurableConfigurationStore.class);
when(virtualHostNode.getConfigurationStore()).thenReturn(dcs);
when(virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
when(virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
when(virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.getChildExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
AbstractVirtualHost host = (AbstractVirtualHost) objectFactory.create(VirtualHost.class, attributes, virtualHostNode);
host.start();
when(virtualHostNode.getVirtualHost()).thenReturn(host);
_createdVirtualHosts.add(host);
QpidTestCase testCase = QpidTestCase.getCurrentInstance();
testCase.registerTearDown(_closeVirtualHosts);
return host;
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class TestBrokerConfiguration method save.
public boolean save(File configFile) {
Map<String, Object> attributes = new HashMap<>();
attributes.put("storePath", configFile.getAbsolutePath());
SystemConfigFactory configFactory = (new PluggableFactoryLoader<>(SystemConfigFactory.class)).get(_storeType);
attributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, false);
attributes.put(ConfiguredObject.DESIRED_STATE, State.QUIESCED);
final SystemConfig parentObject = configFactory.newInstance(_taskExecutor, mock(EventLogger.class), null, attributes);
parentObject.open();
DurableConfigurationStore configurationStore = parentObject.getConfigurationStore();
configurationStore.closeConfigurationStore();
final List<ConfiguredObjectRecord> records = getConfiguredObjectRecords();
configurationStore.init(parentObject);
clearStore(configurationStore);
configurationStore.update(true, records.toArray(new ConfiguredObjectRecord[records.size()]));
configurationStore.closeConfigurationStore();
parentObject.close();
return true;
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeImpl method onDelete.
@Override
protected ListenableFuture<Void> onDelete() {
final Set<InetSocketAddress> helpers = getRemoteNodeAddresses();
return doAfterAlways(closeVirtualHostIfExists(), () -> {
closeEnvironment();
DurableConfigurationStore configurationStore = getConfigurationStore();
if (configurationStore != null) {
configurationStore.closeConfigurationStore();
configurationStore.onDelete(BDBHAVirtualHostNodeImpl.this);
getEventLogger().message(getVirtualHostNodeLogSubject(), HighAvailabilityMessages.DELETE(getName(), String.valueOf(Outcome.SUCCESS)));
}
if (!helpers.isEmpty()) {
try {
new ReplicationGroupAdmin(_groupName, helpers).removeMember(getName());
} catch (DatabaseException e) {
LOGGER.warn(String.format("The deletion of node %s on remote nodes failed due to: %s. To finish deletion a " + "removal of the node from any of remote nodes (%s) is required.", this, e.getMessage(), helpers));
}
}
onCloseOrDelete();
});
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeTest method testCreateAndActivateVirtualHostNode.
@Test
public void testCreateAndActivateVirtualHostNode() throws Exception {
int node1PortNumber = _portHelper.getNextAvailable();
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
String messageStorePath = (String) attributes.get(BDBHAVirtualHostNode.STORE_PATH);
String repStreamTimeout = "2 h";
Map<String, String> context = (Map<String, String>) attributes.get(BDBHAVirtualHostNode.CONTEXT);
context.put(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout);
context.put(EnvironmentConfig.ENV_IS_TRANSACTIONAL, "false");
try {
_helper.createHaVHN(attributes);
fail("Exception was not thrown.");
} catch (RuntimeException e) {
final boolean condition = e.getCause() instanceof IllegalArgumentException;
assertTrue("Unexpected Exception being thrown.", condition);
}
context.put(EnvironmentConfig.ENV_IS_TRANSACTIONAL, "true");
BDBHAVirtualHostNode<?> node = _helper.createHaVHN(attributes);
node.start();
_helper.assertNodeRole(node, NodeRole.MASTER, NodeRole.REPLICA);
assertEquals("Unexpected node state", State.ACTIVE, node.getState());
DurableConfigurationStore store = node.getConfigurationStore();
assertNotNull(store);
BDBConfigurationStore bdbConfigurationStore = (BDBConfigurationStore) store;
ReplicatedEnvironmentFacade environmentFacade = (ReplicatedEnvironmentFacade) bdbConfigurationStore.getEnvironmentFacade();
assertEquals(nodeName, environmentFacade.getNodeName());
assertEquals(groupName, environmentFacade.getGroupName());
assertEquals(helperAddress, environmentFacade.getHostPort());
assertEquals(helperAddress, environmentFacade.getHelperHostPort());
assertEquals("SYNC,NO_SYNC,SIMPLE_MAJORITY", environmentFacade.getMessageStoreDurability().toString());
_helper.awaitForVirtualhost(node);
VirtualHost<?> virtualHost = node.getVirtualHost();
assertNotNull("Virtual host child was not added", virtualHost);
assertEquals("Unexpected virtual host name", groupName, virtualHost.getName());
assertEquals("Unexpected virtual host store", bdbConfigurationStore.getMessageStore(), virtualHost.getMessageStore());
assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
node.stop();
assertEquals("Unexpected state returned after stop", State.STOPPED, node.getState());
assertEquals("Unexpected state", State.STOPPED, node.getState());
assertNull("Virtual host is not destroyed", node.getVirtualHost());
node.delete();
assertEquals("Unexpected state returned after delete", State.DELETED, node.getState());
assertEquals("Unexpected state", State.DELETED, node.getState());
assertFalse("Store still exists " + messageStorePath, new File(messageStorePath).exists());
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class AbstractVirtualHostNode method closeConfigurationStore.
private void closeConfigurationStore() {
DurableConfigurationStore configurationStore = getConfigurationStore();
if (configurationStore != null) {
configurationStore.closeConfigurationStore();
getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.CLOSE());
}
}
Aggregations