Search in sources :

Example 26 with ClientSessionInternal

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();
        }
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) MessageConsumer(javax.jms.MessageConsumer) Transaction(javax.transaction.Transaction) XASession(javax.jms.XASession) XAConnection(javax.jms.XAConnection) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) XAConnection(javax.jms.XAConnection) XASession(javax.jms.XASession) Session(javax.jms.Session) Test(org.junit.Test)

Example 27 with ClientSessionInternal

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());
    }
}
Also used : ClientProducerInternal(org.apache.activemq.artemis.core.client.impl.ClientProducerInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientProducerCredits(org.apache.activemq.artemis.core.client.impl.ClientProducerCredits) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 28 with ClientSessionInternal

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());
    }
}
Also used : ClientProducerInternal(org.apache.activemq.artemis.core.client.impl.ClientProducerInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientProducerCredits(org.apache.activemq.artemis.core.client.impl.ClientProducerCredits) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 29 with ClientSessionInternal

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());
    }
}
Also used : ClientProducerInternal(org.apache.activemq.artemis.core.client.impl.ClientProducerInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientProducerCredits(org.apache.activemq.artemis.core.client.impl.ClientProducerCredits) ArrayList(java.util.ArrayList) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 30 with ClientSessionInternal

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());
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)46 Test (org.junit.Test)35 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)21 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)20 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)19 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 Connection (javax.jms.Connection)12 Session (javax.jms.Session)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)11 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)10 MessageConsumer (javax.jms.MessageConsumer)8 MessageProducer (javax.jms.MessageProducer)8 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 TextMessage (javax.jms.TextMessage)7 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)7 XAConnection (javax.jms.XAConnection)5 XASession (javax.jms.XASession)5