use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ConsumerFilterTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
session = sf.createSession();
session.start();
session.createQueue("foo", RoutingType.ANYCAST, "foo");
producer = session.createProducer("foo");
consumer = session.createConsumer("foo", "animal='giraffe'");
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ConsumerStuckTest method testClientStuckTestWithDirectDelivery.
@Test
public void testClientStuckTestWithDirectDelivery() throws Exception {
ServerLocator locator = createNettyNonHALocator().setConnectionTTL(1000).setClientFailureCheckPeriod(100).setConsumerWindowSize(10 * 1024 * 1024).setCallTimeout(1000);
ClientSessionFactory sf = locator.createSessionFactory();
((ClientSessionFactoryImpl) sf).stopPingingAfterOne();
RemotingConnectionImpl remotingConnection = (RemotingConnectionImpl) sf.getConnection();
ClientSession session = sf.createSession(false, true, true, true);
session.createQueue(QUEUE, QUEUE, null, false);
final int numMessages = 10000;
final ClientConsumer consumer = session.createConsumer(QUEUE);
session.start();
final NettyConnection nettyConnection = (NettyConnection) remotingConnection.getTransportConnection();
Thread tReceive = new Thread() {
@Override
public void run() {
boolean first = true;
try {
while (!Thread.interrupted()) {
ClientMessage received = consumer.receive(500);
System.out.println("Received " + received);
if (first) {
first = false;
nettyConnection.getNettyChannel().config().setAutoRead(false);
}
if (received != null) {
received.acknowledge();
}
}
} catch (Throwable e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
}
};
tReceive.start();
Thread sender = new Thread() {
@Override
public void run() {
try (ServerLocator locator = createNettyNonHALocator();
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, true, true, true);
ClientProducer producer = session.createProducer(QUEUE)) {
for (int i = 0; i < numMessages; i++) {
ClientMessage message = createTextMessage(session, "m" + i);
producer.send(message);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
sender.start();
try {
long timeout = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < timeout && server.getSessions().size() != 2) {
Thread.sleep(10);
}
assertEquals(2, server.getSessions().size());
System.out.println("sessions = " + server.getSessions().size());
assertEquals(2, server.getConnectionCount());
timeout = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < timeout && server.getSessions().size() != 1) {
Thread.sleep(10);
}
System.out.println("Size = " + server.getConnectionCount());
System.out.println("sessions = " + server.getSessions().size());
if (server.getSessions().size() != 1) {
System.out.println(threadDump("Thread dump"));
fail("The cleanup wasn't able to finish cleaning the session. It's probably stuck, look at the thread dump generated by the test for more information");
}
sender.join();
timeout = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < timeout && server.getConnectionCount() != 0) {
Thread.sleep(10);
}
assertEquals(0, server.getConnectionCount());
} finally {
nettyConnection.getNettyChannel().config().setAutoRead(true);
tReceive.interrupt();
tReceive.join();
}
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ConsumerWindowSizeTest method testSaveBuffersOnLargeMessage.
@Test
public void testSaveBuffersOnLargeMessage() throws Exception {
ActiveMQServer server = createServer(false, isNetty());
ClientSession session1 = null;
try {
final int numberOfMessages = 10;
server.start();
locator.setConsumerWindowSize(0).setMinLargeMessageSize(100);
ClientSessionFactory sf = createSessionFactory(locator);
session1 = sf.createSession(false, true, true);
session1.start();
SimpleString ADDRESS = new SimpleString("some-queue");
session1.createQueue(ADDRESS, ADDRESS, true);
ClientConsumerInternal cons1 = (ClientConsumerInternal) session1.createConsumer(ADDRESS);
// Note we make sure we send the messages *before* cons2 is created
ClientProducer prod = session1.createProducer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage msg = session1.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[600]);
prod.send(msg);
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage msg = cons1.receive(1000);
Assert.assertNotNull("expected message at i = " + i, msg);
msg.saveToOutputStream(new FakeOutputStream());
msg.acknowledge();
Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!", 0, cons1.getBufferSize());
}
// just to make sure everything is flushed and no pending packets on the sending buffer, or
session1.close();
session1.close();
session1 = null;
Assert.assertEquals(0, getMessageCount(server, ADDRESS.toString()));
} finally {
try {
if (session1 != null) {
session1.close();
}
} catch (Exception ignored) {
}
}
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueue.
@Test
@BMRules(rules = { @BMRule(name = "interrupt", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "xaEnd", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ActiveMQMessageHandlerTest.interrupt();") })
public void testSimpleMessageReceivedOnQueue() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
resourceAdapter = qResourceAdapter;
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
qResourceAdapter.start(ctx);
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setMaxSession(1);
spec.setCallTimeout(1000L);
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
CountDownLatch latch = new CountDownLatch(1);
XADummyEndpoint endpoint = new XADummyEndpoint(latch, false);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
qResourceAdapter.endpointActivation(endpointFactory, spec);
ClientSession session = locator.createSessionFactory().createSession();
ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("teststring");
clientProducer.send(message);
session.close();
latch.await(5, TimeUnit.SECONDS);
assertNotNull(endpoint.lastMessage);
assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
Binding binding = server.getPostOffice().getBinding(SimpleString.toSimpleString(MDBQUEUEPREFIXED));
assertEquals(1, getMessageCount(((Queue) binding.getBindable())));
server.stop();
server.start();
ClientSessionFactory factory = locator.createSessionFactory();
session = factory.createSession(true, true);
session.start();
ClientConsumer consumer = session.createConsumer(MDBQUEUEPREFIXED);
assertNotNull(consumer.receive(5000));
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueTwoPhase.
@Test
@BMRules(rules = { @BMRule(name = "interrupt", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "xaEnd", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ActiveMQMessageHandlerTest.interrupt();") })
public void testSimpleMessageReceivedOnQueueTwoPhase() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
resourceAdapter = qResourceAdapter;
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
qResourceAdapter.start(ctx);
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setMaxSession(1);
spec.setCallTimeout(1000L);
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
CountDownLatch latch = new CountDownLatch(1);
XADummyEndpoint endpoint = new XADummyEndpoint(latch, true);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
qResourceAdapter.endpointActivation(endpointFactory, spec);
ClientSession session = locator.createSessionFactory().createSession();
ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("teststring");
clientProducer.send(message);
session.close();
latch.await(5, TimeUnit.SECONDS);
assertNotNull(endpoint.lastMessage);
assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
Binding binding = server.getPostOffice().getBinding(SimpleString.toSimpleString(MDBQUEUEPREFIXED));
assertEquals(1, getMessageCount(((Queue) binding.getBindable())));
server.stop();
server.start();
ClientSessionFactory factory = locator.createSessionFactory();
session = factory.createSession(true, true);
session.start();
ClientConsumer consumer = session.createConsumer(MDBQUEUEPREFIXED);
assertNotNull(consumer.receive(5000));
session.close();
}
Aggregations