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;
}
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);
}
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;
}
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();
}
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();
}
Aggregations