use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class VirtualHostTest method testModifyDurableChildAfterRestartingVirtualHost.
public void testModifyDurableChildAfterRestartingVirtualHost() {
String virtualHostName = getName();
VirtualHost<?> virtualHost = createVirtualHost(virtualHostName);
final ConfiguredObjectRecord virtualHostCor = virtualHost.asObjectRecord();
// Give virtualhost a queue and an exchange
Queue queue = virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, "myQueue"));
final ConfiguredObjectRecord queueCor = queue.asObjectRecord();
final List<ConfiguredObjectRecord> allObjects = new ArrayList<>();
allObjects.add(virtualHostCor);
allObjects.add(queueCor);
((AbstractConfiguredObject<?>) virtualHost).stop();
assertEquals("Unexpected state", State.STOPPED, virtualHost.getState());
// Setup an answer that will return the configured object records
doAnswer(new Answer() {
final Iterator<ConfiguredObjectRecord> corIterator = allObjects.iterator();
@Override
public Object answer(final InvocationOnMock invocation) {
ConfiguredObjectRecordHandler handler = (ConfiguredObjectRecordHandler) invocation.getArguments()[0];
while (corIterator.hasNext()) {
handler.handle(corIterator.next());
}
return null;
}
}).when(_configStore).reload(any(ConfiguredObjectRecordHandler.class));
((AbstractConfiguredObject<?>) virtualHost).start();
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
final Collection<Queue> queues = virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after restart", 1, queues.size());
final Queue recoveredQueue = queues.iterator().next();
recoveredQueue.setAttributes(Collections.singletonMap(ConfiguredObject.DESCRIPTION, "testDescription"));
final ConfiguredObjectRecord recoveredQueueCor = queue.asObjectRecord();
verify(_configStore).update(eq(false), matchesRecord(recoveredQueueCor.getId(), recoveredQueueCor.getType()));
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractConfiguredObjectTest method testAuditInformationPersistenceAndRecovery.
public void testAuditInformationPersistenceAndRecovery() throws Exception {
final String creatingUser = "creatingUser";
final Subject creatorSubject = createTestAuthenticatedSubject(creatingUser);
final String objectName = "myName";
final Map<String, Object> attributes = new HashMap<>();
attributes.put(TestSingleton.NAME, objectName);
final TestSingleton object = Subject.doAs(creatorSubject, new PrivilegedAction<TestSingleton>() {
@Override
public TestSingleton run() {
return _model.getObjectFactory().create(TestSingleton.class, attributes, null);
}
});
final ConfiguredObjectRecord cor = object.asObjectRecord();
final Map<String, Object> recordedAttributes = cor.getAttributes();
assertTrue(recordedAttributes.containsKey(ConfiguredObject.LAST_UPDATED_BY));
assertTrue(recordedAttributes.containsKey(ConfiguredObject.LAST_UPDATED_TIME));
assertTrue(recordedAttributes.containsKey(ConfiguredObject.CREATED_BY));
assertTrue(recordedAttributes.containsKey(ConfiguredObject.CREATED_TIME));
assertEquals(creatingUser, recordedAttributes.get(ConfiguredObject.CREATED_BY));
assertEquals(creatingUser, recordedAttributes.get(ConfiguredObject.LAST_UPDATED_BY));
// Now recover the object
final SystemConfig mockSystemConfig = mock(SystemConfig.class);
when(mockSystemConfig.getId()).thenReturn(UUID.randomUUID());
when(mockSystemConfig.getModel()).thenReturn(TestModel.getInstance());
final TestSingleton recovered = (TestSingleton) _model.getObjectFactory().recover(cor, mockSystemConfig).resolve();
recovered.open();
assertEquals("Unexpected recovered object created by", object.getCreatedBy(), recovered.getCreatedBy());
assertEquals("Unexpected recovered object created time", object.getCreatedTime(), recovered.getCreatedTime());
assertEquals("Unexpected recovered object updated by", object.getLastUpdatedBy(), recovered.getLastUpdatedBy());
assertEquals("Unexpected recovered object updated time", object.getLastUpdatedTime(), recovered.getLastUpdatedTime());
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method createVirtualHostConfiguredObjectRecord.
private ConfiguredObjectRecord createVirtualHostConfiguredObjectRecord(UUID virtualHostId) {
Map<String, Object> virtualHostAttributes = new HashMap<>();
virtualHostAttributes.put(VirtualHost.NAME, TEST_VIRTUAL_HOST_NAME);
virtualHostAttributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
virtualHostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION);
ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
when(record.getId()).thenReturn(virtualHostId);
when(record.getAttributes()).thenReturn(virtualHostAttributes);
when(record.getType()).thenReturn(VirtualHost.class.getSimpleName());
return record;
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testActivateVHNWithVHBlueprint_StoreHasExistingVH.
/**
* Tests activating a virtualhostnode with a blueprint context variable. Config store
* does specify a virtualhost. Checks that virtualhost is recovered from store and
* blueprint is ignored..
*/
public void testActivateVHNWithVHBlueprint_StoreHasExistingVH() throws Exception {
UUID virtualHostId = UUID.randomUUID();
ConfiguredObjectRecord record = createVirtualHostConfiguredObjectRecord(virtualHostId);
DurableConfigurationStore configStore = configStoreThatProduces(record);
String vhBlueprint = String.format("{ \"type\" : \"%s\", \"name\" : \"%s\"}", TestMemoryVirtualHost.VIRTUAL_HOST_TYPE, "vhFromBlueprint");
Map<String, String> context = Collections.singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, vhBlueprint);
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
nodeAttributes.put(VirtualHostNode.ID, _nodeId);
nodeAttributes.put(VirtualHostNode.CONTEXT, context);
VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
node.open();
node.start();
VirtualHost<?> virtualHost = node.getVirtualHost();
assertNotNull("Virtual host should be recovered", virtualHost);
assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NAME, virtualHost.getName());
assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
assertEquals("Unexpected virtual host id", virtualHostId, virtualHost.getId());
node.close();
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testActivateVHN_StoreHasVH.
/**
* Tests activating a virtualhostnode with a config store that specifies a
* virtualhost. Ensures that the virtualhost created.
*/
public void testActivateVHN_StoreHasVH() throws Exception {
UUID virtualHostId = UUID.randomUUID();
ConfiguredObjectRecord vhostRecord = createVirtualHostConfiguredObjectRecord(virtualHostId);
DurableConfigurationStore configStore = configStoreThatProduces(vhostRecord);
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
nodeAttributes.put(VirtualHostNode.ID, _nodeId);
VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
node.open();
node.start();
VirtualHost<?> virtualHost = node.getVirtualHost();
assertNotNull("Virtual host was not recovered", virtualHost);
assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NAME, virtualHost.getName());
assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
assertEquals("Unexpected virtual host id", virtualHostId, virtualHost.getId());
node.close();
}
Aggregations