use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class OptimizedAckTest method testReceivedMessageNotInFlightAfterScheduledAckFires.
public void testReceivedMessageNotInFlightAfterScheduledAckFires() throws Exception {
connection.setOptimizedAckScheduledAckInterval(TimeUnit.SECONDS.toMillis(10));
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("test");
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
producer.send(session.createTextMessage("Hello" + i));
}
MessageConsumer consumer = session.createConsumer(queue);
ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 10 == coreQueue.getDeliveringCount();
}
}));
for (int i = 0; i < 6; i++) {
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
}
for (int i = 6; i < 10; i++) {
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 3 == coreQueue.getDeliveringCount();
}
}));
}
assertTrue("After delay the scheduled ack should ack all inflight.", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("inflight count: " + coreQueue.getDeliveringCount());
return 0 == coreQueue.getDeliveringCount();
}
}));
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class OptimizedAckTest method testReceivedMessageStillInflight.
public void testReceivedMessageStillInflight() throws Exception {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("test");
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
producer.send(session.createTextMessage("Hello" + i));
}
MessageConsumer consumer = session.createConsumer(queue);
// check queue delivering count is 10
ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
assertTrue("delivering count is 10", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 10 == coreQueue.getDeliveringCount();
}
}));
for (int i = 0; i < 6; i++) {
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
}
for (int i = 6; i < 10; i++) {
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 3 == coreQueue.getDeliveringCount();
}
}));
}
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class OptimizedAckTest method testVerySlowReceivedMessageStillInflight.
public void testVerySlowReceivedMessageStillInflight() throws Exception {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("test");
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 10; i++) {
producer.send(session.createTextMessage("Hello" + i));
}
MessageConsumer consumer = session.createConsumer(queue);
// check queue delivering count is 10
ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 10 == coreQueue.getDeliveringCount();
}
}));
for (int i = 0; i < 6; i++) {
Thread.sleep(400);
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
}
for (int i = 6; i < 10; i++) {
Thread.sleep(400);
javax.jms.Message msg = consumer.receive(4000);
assertNotNull(msg);
assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 3 == coreQueue.getDeliveringCount();
}
}));
}
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class DirectDeliverTest method testDirectDeliver.
@Test
public void testDirectDeliver() throws Exception {
final String foo = "foo";
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession();
session.createQueue(foo, RoutingType.ANYCAST, foo);
Binding binding = server.getPostOffice().getBinding(new SimpleString(foo));
Queue queue = (Queue) binding.getBindable();
assertTrue(queue.isDirectDeliver());
ClientProducer prod = session.createProducer(foo);
ClientConsumer cons = session.createConsumer(foo);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage msg = session.createMessage(true);
prod.send(msg);
}
queue.flushExecutor();
// Consumer is not started so should go queued
assertFalse(queue.isDirectDeliver());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage msg = cons.receive(10000);
assertNotNull(msg);
msg.acknowledge();
}
Thread.sleep((long) (QueueImpl.CHECK_QUEUE_SIZE_PERIOD * 1.5));
// Add another message, should go direct
ClientMessage msg = session.createMessage(true);
prod.send(msg);
queue.flushExecutor();
assertTrue(queue.isDirectDeliver());
// Send some more
for (int i = 0; i < numMessages; i++) {
msg = session.createMessage(true);
prod.send(msg);
}
for (int i = 0; i < numMessages + 1; i++) {
msg = cons.receive(10000);
assertNotNull(msg);
msg.acknowledge();
}
assertTrue(queue.isDirectDeliver());
session.stop();
for (int i = 0; i < numMessages; i++) {
msg = session.createMessage(true);
prod.send(msg);
}
assertFalse(queue.isDirectDeliver());
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class ActiveMQMessageHandlerSecurityTest method testSimpleMessageReceivedOnQueueWithSecuritySucceeds.
@Test
public void testSimpleMessageReceivedOnQueueWithSecuritySucceeds() throws Exception {
ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
securityManager.getConfiguration().addUser("testuser", "testpassword");
securityManager.getConfiguration().addRole("testuser", "arole");
Role role = new Role("arole", false, true, false, false, false, false, false, false, false, false);
Set<Role> roles = new HashSet<>();
roles.add(role);
server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.start(ctx);
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
spec.setUser("testuser");
spec.setPassword("testpassword");
spec.setSetupAttempts(0);
qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
CountDownLatch latch = new CountDownLatch(1);
DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
qResourceAdapter.endpointActivation(endpointFactory, spec);
Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
}
Aggregations