use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class TestBrokerConfiguration method clearStore.
public void clearStore(final DurableConfigurationStore configurationStore) {
final List<ConfiguredObjectRecord> recordsToDelete = new ArrayList<>();
configurationStore.openConfigurationStore(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
recordsToDelete.add(record);
}
});
if (!recordsToDelete.isEmpty()) {
configurationStore.remove(recordsToDelete.toArray(new ConfiguredObjectRecord[recordsToDelete.size()]));
}
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class JsonFileConfigStoreTest method testInsertAndUpdateTopLevelObject.
public void testInsertAndUpdateTopLevelObject() throws Exception {
_store.init(_parent);
_store.openConfigurationStore(mock(ConfiguredObjectRecordHandler.class));
createRootRecord();
_store.closeConfigurationStore();
_store.init(_parent);
_store.openConfigurationStore(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
}
});
Map<String, Object> newAttributes = new HashMap<String, Object>(_rootRecord.getAttributes());
newAttributes.put("attributeName", "attributeValue");
_store.update(false, new ConfiguredObjectRecordImpl(_rootRecord.getId(), _rootRecord.getType(), newAttributes));
_store.closeConfigurationStore();
_store.init(_parent);
_store.openConfigurationStore(_handler);
Map<String, Object> expectedAttributes = new HashMap<String, Object>(newAttributes);
verify(_handler, times(1)).handle(matchesRecord(_rootRecord.getId(), _rootRecord.getType(), expectedAttributes));
_store.closeConfigurationStore();
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class AbstractVirtualHost method importMessageStore.
@Override
public void importMessageStore(final String source) {
try {
final URL url = convertStringToURL(source);
try (InputStream input = url.openStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(input);
DataInputStream data = new DataInputStream(bufferedInputStream)) {
final MessageStoreSerializer serializer = MessageStoreSerializer.FACTORY.newInstance(data);
doSync(doOnConfigThread(new Task<ListenableFuture<Void>, IOException>() {
@Override
public ListenableFuture<Void> execute() throws IOException {
if (getState() != State.STOPPED) {
throw new IllegalArgumentException("The importMessageStore operation can only be called when the virtual host is stopped");
}
try {
_messageStore.openMessageStore(AbstractVirtualHost.this);
checkMessageStoreEmpty();
final Map<String, UUID> queueMap = new HashMap<>();
getDurableConfigurationStore().reload(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
if (record.getType().equals(Queue.class.getSimpleName())) {
queueMap.put((String) record.getAttributes().get(ConfiguredObject.NAME), record.getId());
}
}
});
serializer.deserialize(queueMap, _messageStore, data);
} finally {
_messageStore.closeMessageStore();
}
return Futures.immediateFuture(null);
}
@Override
public String getObject() {
return AbstractVirtualHost.this.toString();
}
@Override
public String getAction() {
return "importMessageStore";
}
@Override
public String getArguments() {
if (url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("file")) {
return "source=" + source;
} else if (url.getProtocol().equalsIgnoreCase("data")) {
return "source=<data stream>";
} else {
return "source=<unknown source type>";
}
}
}));
}
} catch (IOException e) {
throw new IllegalConfigurationException("Cannot convert '" + source + "' to a readable resource", e);
}
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class ManagementModeStoreHandlerTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
_rootId = UUID.randomUUID();
_portEntryId = UUID.randomUUID();
_store = mock(DurableConfigurationStore.class);
_taskExecutor = new CurrentThreadTaskExecutor();
_taskExecutor.start();
_systemConfig = new JsonSystemConfigImpl(_taskExecutor, mock(EventLogger.class), null, new HashMap<String, Object>());
ConfiguredObjectRecord systemContextRecord = _systemConfig.asObjectRecord();
_root = new ConfiguredObjectRecordImpl(_rootId, Broker.class.getSimpleName(), Collections.singletonMap(Broker.NAME, (Object) "broker"), Collections.singletonMap(SystemConfig.class.getSimpleName(), systemContextRecord.getId()));
_portEntry = mock(ConfiguredObjectRecord.class);
when(_portEntry.getId()).thenReturn(_portEntryId);
when(_portEntry.getParents()).thenReturn(Collections.singletonMap(Broker.class.getSimpleName(), _root.getId()));
when(_portEntry.getType()).thenReturn(Port.class.getSimpleName());
final ArgumentCaptor<ConfiguredObjectRecordHandler> recovererArgumentCaptor = ArgumentCaptor.forClass(ConfiguredObjectRecordHandler.class);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
ConfiguredObjectRecordHandler recoverer = recovererArgumentCaptor.getValue();
recoverer.handle(_root);
recoverer.handle(_portEntry);
return false;
}
}).when(_store).openConfigurationStore(recovererArgumentCaptor.capture());
_systemConfigAttributes = new HashMap<>();
_handler = new ManagementModeStoreHandler(_store, _systemConfig);
;
_handler.init(_systemConfig);
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler 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()));
}
Aggregations