Search in sources :

Example 11 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost 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;
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) AbstractVirtualHost(org.apache.qpid.server.virtualhost.AbstractVirtualHost) QpidTestCase(org.apache.qpid.test.utils.QpidTestCase) AbstractVirtualHost(org.apache.qpid.server.virtualhost.AbstractVirtualHost) TestMemoryVirtualHost(org.apache.qpid.server.virtualhost.TestMemoryVirtualHost) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore)

Example 12 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class BrokerImplTest method doAssignTargetSizeTest.

private void doAssignTargetSizeTest(final long[] virtualHostQueueSizes, final long flowToDiskThreshold) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("name", "Broker");
    attributes.put(Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
    attributes.put(Broker.DURABLE, true);
    attributes.put("context", Collections.singletonMap(Broker.BROKER_FLOW_TO_DISK_THRESHOLD, flowToDiskThreshold));
    _brokerImpl = new BrokerImpl(attributes, _systemConfig);
    _brokerImpl.open();
    assertEquals("Unexpected broker state", State.ACTIVE, _brokerImpl.getState());
    for (int i = 0; i < virtualHostQueueSizes.length; i++) {
        createVhnWithVh(_brokerImpl, i, virtualHostQueueSizes[i]);
    }
    long totalAssignedTargetSize = 0;
    for (VirtualHostNode<?> vhn : _brokerImpl.getVirtualHostNodes()) {
        VirtualHost<?> virtualHost = vhn.getVirtualHost();
        if (virtualHost instanceof QueueManagingVirtualHost) {
            long targetSize = ((QueueManagingVirtualHost<?>) virtualHost).getTargetSize();
            assertTrue("A virtualhost's target size cannot be zero", targetSize > 0);
            totalAssignedTargetSize += targetSize;
        }
    }
    long diff = Math.abs(flowToDiskThreshold - totalAssignedTargetSize);
    long tolerance = _brokerImpl.getVirtualHostNodes().size() * 2;
    assertTrue(String.format("Assigned target size not within expected tolerance. Diff %d Tolerance %d", diff, tolerance), diff < tolerance);
}
Also used : BrokerImpl(org.apache.qpid.server.model.BrokerImpl) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 13 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class AbstractDurableConfigurationStoreTestCase method createTestQueue.

private Queue<?> createTestQueue(String queueName, String queueOwner, boolean exclusive, final Map<String, Object> arguments) throws StoreException {
    Queue queue = BrokerTestHelper.mockWithSystemPrincipal(Queue.class, mock(Principal.class));
    when(queue.getName()).thenReturn(queueName);
    when(queue.isExclusive()).thenReturn(exclusive);
    when(queue.getId()).thenReturn(_queueId);
    when(queue.getType()).thenReturn(STANDARD);
    when(queue.getCategoryClass()).thenReturn(Queue.class);
    when(queue.isDurable()).thenReturn(true);
    TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
    when(queue.getTaskExecutor()).thenReturn(taskExecutor);
    when(queue.getChildExecutor()).thenReturn(taskExecutor);
    final QueueManagingVirtualHost vh = mock(QueueManagingVirtualHost.class);
    when(queue.getVirtualHost()).thenReturn(vh);
    final Map<String, Object> attributes = arguments == null ? new LinkedHashMap<>() : new LinkedHashMap<>(arguments);
    attributes.put(Queue.NAME, queueName);
    attributes.put(Queue.TYPE, STANDARD);
    if (exclusive) {
        when(queue.getOwner()).thenReturn(queueOwner);
        attributes.put(Queue.OWNER, queueOwner);
        attributes.put(Queue.EXCLUSIVE, ExclusivityPolicy.CONTAINER);
    }
    when(queue.getAvailableAttributes()).thenReturn(attributes.keySet());
    final ArgumentCaptor<String> requestedAttribute = ArgumentCaptor.forClass(String.class);
    when(queue.getAttribute(requestedAttribute.capture())).then(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            String attrName = requestedAttribute.getValue();
            return attributes.get(attrName);
        }
    });
    when(queue.getActualAttributes()).thenReturn(attributes);
    when(queue.getObjectFactory()).thenReturn(_factory);
    when(queue.getModel()).thenReturn(_factory.getModel());
    ConfiguredObjectRecord objectRecord = mock(ConfiguredObjectRecord.class);
    when(objectRecord.getId()).thenReturn(_queueId);
    when(objectRecord.getType()).thenReturn(Queue.class.getSimpleName());
    when(objectRecord.getAttributes()).thenReturn(attributes);
    when(objectRecord.getParents()).thenReturn(Collections.singletonMap(_rootRecord.getType(), _rootRecord.getId()));
    when(queue.asObjectRecord()).thenReturn(objectRecord);
    return queue;
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) Answer(org.mockito.stubbing.Answer) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Queue(org.apache.qpid.server.model.Queue) Principal(java.security.Principal)

Example 14 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class LastValueQueueListTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Map<String, Object> queueAttributes = new HashMap<String, Object>();
    queueAttributes.put(Queue.ID, UUID.randomUUID());
    queueAttributes.put(Queue.NAME, getName());
    queueAttributes.put(LastValueQueue.LVQ_KEY, CONFLATION_KEY);
    final QueueManagingVirtualHost virtualHost = BrokerTestHelper.createVirtualHost("testVH");
    _queue = new LastValueQueueImpl(queueAttributes, virtualHost);
    _queue.open();
    _list = _queue.getEntries();
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap)

Example 15 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class SimpleQueueEntryImplTest method setUp.

@Override
public void setUp() throws Exception {
    Map<String, Object> queueAttributes = new HashMap<String, Object>();
    queueAttributes.put(Queue.ID, UUID.randomUUID());
    queueAttributes.put(Queue.NAME, "SimpleQueueEntryImplTest");
    final QueueManagingVirtualHost virtualHost = BrokerTestHelper.createVirtualHost("testVH");
    StandardQueueImpl queue = new StandardQueueImpl(queueAttributes, virtualHost);
    queue.open();
    queueEntryList = queue.getEntries();
    super.setUp();
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap)

Aggregations

QueueManagingVirtualHost (org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)18 HashMap (java.util.HashMap)12 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)3 AccessControlException (java.security.AccessControlException)2 Principal (java.security.Principal)2 Collection (java.util.Collection)2 Map (java.util.Map)2 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 Queue (org.apache.qpid.server.model.Queue)2 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)2 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 LogWriteException (com.sleepycat.je.LogWriteException)1 InetSocketAddress (java.net.InetSocketAddress)1