use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class XATest method testMultipleSessionsOneTxRollbackSend.
@Test
public void testMultipleSessionsOneTxRollbackSend() throws Exception {
XAConnection conn = null;
Connection conn2 = null;
try {
conn = xacf.createXAConnection();
conn.start();
tm.begin();
// Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource();
XASession sess2 = conn.createXASession();
ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource();
res1.setForceNotSameRM(true);
res2.setForceNotSameRM(true);
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
// Send 2 messages - one from each session
MessageProducer prod1 = sess1.createProducer(queue1);
MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
// rollback
tm.rollback();
// Messages should not be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage) cons.receive(100);
Assert.assertNull(r1);
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ProducerFlowControlTest method testProducerCreditsCaching2.
@Test
public void testProducerCreditsCaching2() throws Exception {
server = createServer(false, isNetty());
server.start();
waitForServerToStart(server);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
for (int i = 0; i < ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE * 2; i++) {
ClientProducer prod = session.createProducer("address");
ClientProducerCredits newCredits = ((ClientProducerInternal) prod).getProducerCredits();
if (credits != null) {
Assert.assertTrue(newCredits == credits);
}
credits = newCredits;
prod.close();
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ProducerFlowControlTest method testProducerCreditsCaching3.
@Test
public void testProducerCreditsCaching3() throws Exception {
server = createServer(false, isNetty());
server.start();
waitForServerToStart(server);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
for (int i = 0; i < ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE; i++) {
ClientProducer prod = session.createProducer("address" + i);
ClientProducerCredits newCredits = ((ClientProducerInternal) prod).getProducerCredits();
if (credits != null) {
Assert.assertFalse(newCredits == credits);
}
credits = newCredits;
Assert.assertEquals(i + 1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ProducerFlowControlTest method testProducerCreditsCaching5.
@Test
public void testProducerCreditsCaching5() throws Exception {
server = createServer(false, isNetty());
server.start();
waitForServerToStart(server);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
List<ClientProducerCredits> creditsList = new ArrayList<>();
for (int i = 0; i < ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE; i++) {
ClientProducer prod = session.createProducer("address" + i);
ClientProducerCredits newCredits = ((ClientProducerInternal) prod).getProducerCredits();
if (credits != null) {
Assert.assertFalse(newCredits == credits);
}
credits = newCredits;
Assert.assertEquals(i + 1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
creditsList.add(credits);
}
Iterator<ClientProducerCredits> iter = creditsList.iterator();
for (int i = 0; i < ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE; i++) {
ClientProducer prod = session.createProducer("address" + i);
ClientProducerCredits newCredits = ((ClientProducerInternal) prod).getProducerCredits();
Assert.assertTrue(newCredits == iter.next());
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
for (int i = 0; i < 10; i++) {
session.createProducer("address" + (i + ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE));
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE + i + 1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ProducerFlowControlTest method testProducerCreditsRefCounting.
@Test
public void testProducerCreditsRefCounting() throws Exception {
server = createServer(false, isNetty());
server.start();
waitForServerToStart(server);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
session.createQueue("address", "queue1", null, false);
ClientProducer prod1 = session.createProducer("address");
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
ClientProducer prod2 = session.createProducer("address");
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
ClientProducer prod3 = session.createProducer("address");
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
prod1.close();
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
prod2.close();
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
prod3.close();
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
Aggregations