use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.
the class XBeanConfigTest method setUp.
@Override
protected void setUp() throws Exception {
System.setProperty("brokername", "testbroker");
brokerService = createBroker();
broker = brokerService.getBroker();
// started automatically
// brokerService.start();
context = new ConnectionContext();
context.setBroker(broker);
info = new ConnectionInfo();
info.setClientId("James");
info.setUserName("James");
info.setConnectionId(new ConnectionId("1234"));
try {
broker.addConnection(context, info);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
assertNotNull("No broker created!");
}
use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.
the class DurableSubscriptionUnsubscribeTest method doDirectUnsubscribe.
public void doDirectUnsubscribe(boolean restart) throws Exception {
createSubscriptions();
createAdvisorySubscription();
Thread.sleep(1000);
assertCount(100, 0);
if (restart) {
restartBroker();
createAdvisorySubscription();
assertCount(100, 0);
}
for (int i = 0; i < 100; i++) {
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
info.setClientId(getName());
info.setSubscriptionName("SubsId" + i);
ConnectionContext context = new ConnectionContext();
context.setBroker(broker.getRegionBroker());
context.setClientId(getName());
broker.getBroker().removeSubscription(context, info);
if (i % 20 == 0) {
Thread.sleep(1000);
assertCount(100 - i - 1, 0);
}
}
assertCount(0, 0);
if (restart) {
restartBroker();
createAdvisorySubscription();
assertCount(0, 0);
}
}
use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.
the class QueueDuplicatesFromStoreTest method doTestNoDuplicateAfterCacheFullAndAcked.
public void doTestNoDuplicateAfterCacheFullAndAcked(final int auditDepth) throws Exception {
final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
final ConnectionContext contextNotInTx = new ConnectionContext();
final ConsumerInfo consumerInfo = new ConsumerInfo();
final DestinationStatistics destinationStatistics = new DestinationStatistics();
consumerInfo.setExclusive(true);
final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, brokerService.getTaskRunnerFactory());
// a workaround for this issue
// queue.setUseCache(false);
queue.systemUsage.getMemoryUsage().setLimit(1024 * 1024 * 10);
queue.setMaxAuditDepth(auditDepth);
queue.initialize();
queue.start();
ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
ProducerInfo producerInfo = new ProducerInfo();
ProducerState producerState = new ProducerState(producerInfo);
producerExchange.setProducerState(producerState);
producerExchange.setConnectionContext(contextNotInTx);
final CountDownLatch receivedLatch = new CountDownLatch(count);
final AtomicLong ackedCount = new AtomicLong(0);
final AtomicLong enqueueCounter = new AtomicLong(0);
final Vector<String> errors = new Vector<>();
// populate the queue store, exceed memory limit so that cache is disabled
for (int i = 0; i < count; i++) {
Message message = getMessage(i);
queue.send(producerExchange, message);
}
assertEquals("store count is correct", count, queueMessageStore.getMessageCount());
// pull from store in small windows
Subscription subscription = new Subscription() {
private SubscriptionStatistics subscriptionStatistics = new SubscriptionStatistics();
@Override
public long getPendingMessageSize() {
return 0;
}
@Override
public void add(MessageReference node) throws Exception {
if (enqueueCounter.get() != node.getMessageId().getProducerSequenceId()) {
errors.add("Not in sequence at: " + enqueueCounter.get() + ", received: " + node.getMessageId().getProducerSequenceId());
}
assertEquals("is in order", enqueueCounter.get(), node.getMessageId().getProducerSequenceId());
receivedLatch.countDown();
enqueueCounter.incrementAndGet();
node.decrementReferenceCount();
}
@Override
public void add(ConnectionContext context, Destination destination) throws Exception {
}
@Override
public int countBeforeFull() {
if (isFull()) {
return 0;
} else {
return fullWindow - (int) (enqueueCounter.get() - ackedCount.get());
}
}
@Override
public void destroy() {
}
@Override
public void gc() {
}
@Override
public ConsumerInfo getConsumerInfo() {
return consumerInfo;
}
@Override
public ConnectionContext getContext() {
return null;
}
@Override
public long getDequeueCounter() {
return 0;
}
@Override
public long getDispatchedCounter() {
return 0;
}
@Override
public int getDispatchedQueueSize() {
return 0;
}
@Override
public long getEnqueueCounter() {
return 0;
}
@Override
public int getInFlightSize() {
return 0;
}
@Override
public int getInFlightUsage() {
return 0;
}
@Override
public ObjectName getObjectName() {
return null;
}
@Override
public int getPendingQueueSize() {
return 0;
}
@Override
public int getPrefetchSize() {
return 0;
}
@Override
public String getSelector() {
return null;
}
@Override
public boolean isBrowser() {
return false;
}
@Override
public boolean isFull() {
return (enqueueCounter.get() - ackedCount.get()) >= fullWindow;
}
@Override
public boolean isHighWaterMark() {
return false;
}
@Override
public boolean isLowWaterMark() {
return false;
}
@Override
public boolean isRecoveryRequired() {
return false;
}
@Override
public boolean matches(MessageReference node, MessageEvaluationContext context) throws IOException {
return true;
}
@Override
public boolean matches(ActiveMQDestination destination) {
return true;
}
@Override
public void processMessageDispatchNotification(MessageDispatchNotification mdn) throws Exception {
}
@Override
public Response pullMessage(ConnectionContext context, MessagePull pull) throws Exception {
return null;
}
@Override
public boolean isWildcard() {
return false;
}
@Override
public List<MessageReference> remove(ConnectionContext context, Destination destination) throws Exception {
return null;
}
@Override
public void setObjectName(ObjectName objectName) {
}
@Override
public void setSelector(String selector) throws InvalidSelectorException, UnsupportedOperationException {
}
@Override
public void updateConsumerPrefetch(int newPrefetch) {
}
@Override
public boolean addRecoveredMessage(ConnectionContext context, MessageReference message) throws Exception {
return false;
}
@Override
public ActiveMQDestination getActiveMQDestination() {
return destination;
}
@Override
public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
}
@Override
public int getCursorMemoryHighWaterMark() {
return 0;
}
@Override
public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark) {
}
@Override
public boolean isSlowConsumer() {
return false;
}
@Override
public void unmatched(MessageReference node) throws IOException {
}
@Override
public long getTimeOfLastMessageAck() {
return 0;
}
@Override
public long getConsumedCount() {
return 0;
}
@Override
public void incrementConsumedCount() {
}
@Override
public void resetConsumedCount() {
}
@Override
public SubscriptionStatistics getSubscriptionStatistics() {
return subscriptionStatistics;
}
@Override
public long getInFlightMessageSize() {
return subscriptionStatistics.getInflightMessageSize().getTotalSize();
}
};
queue.addSubscription(contextNotInTx, subscription);
int removeIndex = 0;
do {
// Simulate periodic acks in small but recent windows
long receivedCount = enqueueCounter.get();
if (receivedCount > ackStartIndex) {
if (receivedCount >= removeIndex + ackWindow) {
for (int j = 0; j < ackBatchSize; j++, removeIndex++) {
ackedCount.incrementAndGet();
MessageAck ack = new MessageAck();
ack.setLastMessageId(new MessageId(mesageIdRoot + removeIndex));
ack.setMessageCount(1);
queue.removeMessage(contextNotInTx, subscription, new IndirectMessageReference(getMessage(removeIndex)), ack);
queue.wakeup();
}
if (removeIndex % 1000 == 0) {
LOG.info("acked: " + removeIndex);
persistenceAdapter.checkpoint(true);
}
}
}
} while (!receivedLatch.await(0, TimeUnit.MILLISECONDS) && errors.isEmpty());
assertTrue("There are no errors: " + errors, errors.isEmpty());
assertEquals(count, enqueueCounter.get());
assertEquals("store count is correct", count - removeIndex, queueMessageStore.getMessageCount());
}
use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.
the class StoreQueueCursorNoDuplicateTest method testNoDuplicateAfterCacheFullAndReadPast.
public void testNoDuplicateAfterCacheFullAndReadPast() throws Exception {
final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
final ConsumerInfo consumerInfo = new ConsumerInfo();
final DestinationStatistics destinationStatistics = new DestinationStatistics();
consumerInfo.setExclusive(true);
final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
queueMessageStore.start();
queueMessageStore.registerIndexListener(null);
QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
SystemUsage systemUsage = new SystemUsage();
// ensure memory limit is reached
systemUsage.getMemoryUsage().setLimit(messageBytesSize * (count + 2));
underTest.setSystemUsage(systemUsage);
underTest.setEnableAudit(false);
underTest.start();
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
final ConnectionContext contextNotInTx = new ConnectionContext();
for (int i = 0; i < count; i++) {
ActiveMQTextMessage msg = getMessage(i);
msg.setMemoryUsage(systemUsage.getMemoryUsage());
queueMessageStore.addMessage(contextNotInTx, msg);
underTest.addMessageLast(msg);
}
assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
int dequeueCount = 0;
underTest.setMaxBatchSize(2);
underTest.reset();
while (underTest.hasNext() && dequeueCount < count) {
MessageReference ref = underTest.next();
ref.decrementReferenceCount();
underTest.remove();
LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
}
underTest.release();
assertEquals(count, dequeueCount);
}
use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.
the class JaasDualAuthenticationBrokerTest method testSecureConnector.
public void testSecureConnector() {
Connector connector = new TransportConnector(sslTransportServer);
connectionContext.setConnector(connector);
connectionInfo.setTransportContext(new StubX509Certificate[] {});
try {
authBroker.addConnection(connectionContext, connectionInfo);
} catch (Exception e) {
fail("Call to addConnection failed: " + e.getMessage());
}
assertEquals("Number of addConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.addConnectionData.size());
ConnectionContext receivedContext = receiveBroker.addConnectionData.getFirst().connectionContext;
assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.", DN_USERNAME, receivedContext.getSecurityContext().getUserName());
Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
assertEquals("2 Principals received", 2, receivedPrincipals.size());
for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext(); ) {
Principal currentPrincipal = iter.next();
if (currentPrincipal instanceof UserPrincipal) {
assertEquals("UserPrincipal is '" + DN_USERNAME + "'", DN_USERNAME, currentPrincipal.getName());
} else if (currentPrincipal instanceof GroupPrincipal) {
assertEquals("GroupPrincipal is '" + DN_GROUP + "'", DN_GROUP, currentPrincipal.getName());
} else {
fail("Unexpected Principal subclass found.");
}
}
try {
authBroker.removeConnection(connectionContext, connectionInfo, null);
} catch (Exception e) {
fail("Call to removeConnection failed: " + e.getMessage());
}
assertEquals("Number of removeConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.removeConnectionData.size());
}
Aggregations