use of org.apache.qpid.server.model.BrokerImpl in project qpid-broker-j by apache.
the class DerbyVirtualHostNodeTest method createBroker.
private BrokerImpl createBroker() {
Map<String, Object> brokerAttributes = Collections.<String, Object>singletonMap(Broker.NAME, "Broker");
SystemConfig parent = BrokerTestHelper.mockWithSystemPrincipal(SystemConfig.class, mock(Principal.class));
when(parent.getEventLogger()).thenReturn(new EventLogger());
when(parent.getCategoryClass()).thenReturn(SystemConfig.class);
when(parent.getTaskExecutor()).thenReturn(_taskExecutor);
when(parent.getChildExecutor()).thenReturn(_taskExecutor);
when(parent.getModel()).thenReturn(BrokerModel.getInstance());
when(parent.getObjectFactory()).thenReturn(new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()));
BrokerImpl broker = new BrokerImpl(brokerAttributes, parent);
broker.start();
return broker;
}
use of org.apache.qpid.server.model.BrokerImpl in project qpid-broker-j by apache.
the class BrokerImplTest method testPurgeUser.
public void testPurgeUser() throws Exception {
final String testUsername = "testUser";
final String testPassword = "testPassword";
// setup broker
Map<String, Object> brokerAttributes = new HashMap<>();
brokerAttributes.put("name", "Broker");
brokerAttributes.put(Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
brokerAttributes.put(Broker.DURABLE, true);
_brokerImpl = new BrokerImpl(brokerAttributes, _systemConfig);
_brokerImpl.open();
// setup auth provider with testuser
final Map<String, Object> authProviderAttributes = new HashMap<>();
authProviderAttributes.put(ConfiguredObject.NAME, "testAuthProvider");
authProviderAttributes.put(ConfiguredObject.TYPE, "Simple");
SimpleAuthenticationManager authenticationProvider = new SimpleAuthenticationManager(authProviderAttributes, _brokerImpl);
authenticationProvider.create();
authenticationProvider.addUser(testUsername, testPassword);
// setup preference owned by testuser
final Map<String, Object> preferenceAttributes = new HashMap<>();
UUID preferenceId = UUID.randomUUID();
preferenceAttributes.put(Preference.ID_ATTRIBUTE, preferenceId);
preferenceAttributes.put(Preference.NAME_ATTRIBUTE, "testPref");
preferenceAttributes.put(Preference.TYPE_ATTRIBUTE, "X-testPrefType");
preferenceAttributes.put(Preference.VALUE_ATTRIBUTE, Collections.EMPTY_MAP);
Subject testUserSubject = new Subject();
testUserSubject.getPrincipals().add(new AuthenticatedPrincipal(new UsernamePrincipal(testUsername, authenticationProvider)));
testUserSubject.setReadOnly();
final Collection<Preference> preferences = Collections.singleton(PreferenceFactory.fromAttributes(_brokerImpl, preferenceAttributes));
Subject.doAs(testUserSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
try {
_brokerImpl.getUserPreferences().updateOrAppend(preferences).get(10, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
e.printStackTrace();
fail("Failed to put preference:");
}
return null;
}
});
// test pre-conditions
Collection<Preference> preferencesBeforePurge = getPreferencesAs(testUserSubject);
assertEquals("Unexpected number of preferences before userPurge", 1, preferencesBeforePurge.size());
assertEquals("Unexpected preference before userPurge", preferenceId, preferencesBeforePurge.iterator().next().getId());
assertTrue("User was not valid before userPurge", authenticationProvider.getUsers().containsKey(testUsername));
_brokerImpl.purgeUser(authenticationProvider, testUsername);
// test post-conditions
Collection<Preference> preferencesAfterPurge = getPreferencesAs(testUserSubject);
assertEquals("Preferences were not deleted during userPurge", Collections.EMPTY_SET, preferencesAfterPurge);
assertEquals("User was not deleted from authentication Provider", Collections.EMPTY_MAP, authenticationProvider.getUsers());
verify(_preferenceStore).replace(Collections.singleton(preferenceId), Collections.EMPTY_SET);
}
use of org.apache.qpid.server.model.BrokerImpl 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.model.BrokerImpl in project qpid-broker-j by apache.
the class BrokerImplTest method testNetworkBufferSize.
public void testNetworkBufferSize() {
Map<String, Object> attributes = new HashMap<>();
attributes.put(Broker.NAME, "Broker");
attributes.put(Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
attributes.put(Broker.DURABLE, true);
// testing successful case is not possible because of the static nature of QpidByteBuffer which *should* be unrelated
// testing unsuccessful case
attributes.put(Broker.CONTEXT, Collections.singletonMap(Broker.NETWORK_BUFFER_SIZE, Broker.MINIMUM_NETWORK_BUFFER_SIZE - 1));
_brokerImpl = new BrokerImpl(attributes, _systemConfig);
_brokerImpl.open();
assertEquals("Broker open should fail with network buffer size less then minimum", State.ERRORED, _brokerImpl.getState());
assertEquals("Unexpected buffer size", Broker.DEFAULT_NETWORK_BUFFER_SIZE, _brokerImpl.getNetworkBufferSize());
}
Aggregations