Search in sources :

Example 6 with ConfiguredObjectRecordHandler

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()]));
    }
}
Also used : ArrayList(java.util.ArrayList) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 7 with ConfiguredObjectRecordHandler

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();
}
Also used : HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 8 with ConfiguredObjectRecordHandler

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);
    }
}
Also used : Task(org.apache.qpid.server.configuration.updater.Task) StatisticsReportingTask(org.apache.qpid.server.stats.StatisticsReportingTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) URL(java.net.URL) BufferedInputStream(java.io.BufferedInputStream) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) MessageStoreSerializer(org.apache.qpid.server.store.serializer.MessageStoreSerializer) UUID(java.util.UUID) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 9 with ConfiguredObjectRecordHandler

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);
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) AbstractSystemConfig(org.apache.qpid.server.model.AbstractSystemConfig) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) Port(org.apache.qpid.server.model.Port) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) JsonSystemConfigImpl(org.apache.qpid.server.model.JsonSystemConfigImpl) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 10 with ConfiguredObjectRecordHandler

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()));
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Aggregations

ConfiguredObjectRecordHandler (org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)11 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 UUID (java.util.UUID)2 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 VirtualHost (org.apache.qpid.server.model.VirtualHost)2 ConfiguredObjectRecordImpl (org.apache.qpid.server.store.ConfiguredObjectRecordImpl)2 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)2 Matchers.anyString (org.mockito.Matchers.anyString)2 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1