use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class CommitRollbackTest method testReceiveWithCommit.
@Test
public void testReceiveWithCommit() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
ClientSession session = cf.createSession(false, false, false);
sendSession.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientConsumer cc = session.createConsumer(queueA);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
}
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = cc.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
}
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Assert.assertEquals(numMessages, q.getDeliveringCount());
session.commit();
Assert.assertEquals(0, q.getDeliveringCount());
session.close();
sendSession.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class CommitRollbackTest method testReceiveWithRollback.
@Test
public void testReceiveWithRollback() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
ClientSession session = cf.createSession(false, false, false);
sendSession.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientConsumer cc = session.createConsumer(queueA);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
}
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = cc.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
}
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Assert.assertEquals(numMessages, q.getDeliveringCount());
session.rollback();
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = cc.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
}
Assert.assertEquals(numMessages, q.getDeliveringCount());
session.close();
sendSession.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class CommitRollbackTest method testReceiveWithRollbackMultipleConsumersDifferentQueues.
@Test
public void testReceiveWithRollbackMultipleConsumersDifferentQueues() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
ClientSession session = cf.createSession(false, false, false);
sendSession.createQueue(addressA, queueA, false);
sendSession.createQueue(addressB, queueB, false);
ClientProducer cp = sendSession.createProducer(addressA);
ClientProducer cp2 = sendSession.createProducer(addressB);
ClientConsumer cc = session.createConsumer(queueA);
ClientConsumer cc2 = session.createConsumer(queueB);
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
cp2.send(sendSession.createMessage(false));
}
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage cm = cc.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
cm = cc2.receive(5000);
Assert.assertNotNull(cm);
cm.acknowledge();
}
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
Queue q2 = (Queue) server.getPostOffice().getBinding(queueB).getBindable();
Assert.assertEquals(numMessages, q.getDeliveringCount());
cc.close();
cc2.close();
session.rollback();
Assert.assertEquals(0, q2.getDeliveringCount());
Assert.assertEquals(numMessages, getMessageCount(q));
Assert.assertEquals(0, q2.getDeliveringCount());
Assert.assertEquals(numMessages, getMessageCount(q));
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class BlockingSendTest method testSinglePersistentBlockingNonSync.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testSinglePersistentBlockingNonSync() throws Exception {
ActiveMQServer server = createServer(true);
ClientSession session = null;
ClientSessionFactory factory = null;
ServerLocator locator = null;
server.getConfiguration().setJournalSyncNonTransactional(false);
server.getConfiguration().setJournalBufferTimeout_AIO(15000);
server.start();
System.out.println("sync = " + server.getConfiguration().isJournalSyncNonTransactional());
locator = createInVMNonHALocator().setBlockOnDurableSend(true);
factory = createSessionFactory(locator);
session = factory.createSession();
session.createQueue("address", RoutingType.ANYCAST, "queue");
ClientProducer prod = session.createProducer("address");
ClientMessage message = session.createMessage(true);
prod.send(message);
ClientConsumer consumer = session.createConsumer("queue");
session.start();
ClientMessage msg = consumer.receive(5000);
Assert.assertNotNull(msg);
msg.acknowledge();
}
use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project activemq-artemis by apache.
the class ConcurrentCreateDeleteProduceTest method testConcurrentProduceCreateAndDelete.
@Test
public void testConcurrentProduceCreateAndDelete() throws Throwable {
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(true, true);
ClientProducer producer = session.createProducer(ADDRESS);
// just to make it page forever
Queue serverQueue = server.createQueue(ADDRESS, RoutingType.ANYCAST, SimpleString.toSimpleString("everPage"), null, true, false);
serverQueue.getPageSubscription().getPagingStore().startPaging();
Consumer[] consumers = new Consumer[10];
for (int i = 0; i < consumers.length; i++) {
consumers[i] = new Consumer();
consumers[i].start();
}
for (int i = 0; i < 50000 && running; i++) {
producer.send(session.createMessage(true));
// Thread.sleep(10);
}
session.close();
running = false;
for (Consumer consumer : consumers) {
consumer.join();
if (consumer.ex != null) {
throw consumer.ex;
}
}
}
Aggregations