Search in sources :

Example 1 with ClientProducerCredits

use of org.apache.activemq.artemis.core.client.impl.ClientProducerCredits in project activemq-artemis by apache.

the class ProducerFlowControlTest method testProducerCreditsCaching4.

@Test
public void testProducerCreditsCaching4() 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;
        prod.close();
        Assert.assertEquals(i + 1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
        Assert.assertEquals(i + 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 2 with ClientProducerCredits

use of org.apache.activemq.artemis.core.client.impl.ClientProducerCredits in project activemq-artemis by apache.

the class ProducerFlowControlTest method testProducerCreditsCaching1.

@Test
public void testProducerCreditsCaching1() 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;
        Assert.assertEquals(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 3 with ClientProducerCredits

use of org.apache.activemq.artemis.core.client.impl.ClientProducerCredits 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 4 with ClientProducerCredits

use of org.apache.activemq.artemis.core.client.impl.ClientProducerCredits 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 5 with ClientProducerCredits

use of org.apache.activemq.artemis.core.client.impl.ClientProducerCredits 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)

Aggregations

ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)5 ClientProducerCredits (org.apache.activemq.artemis.core.client.impl.ClientProducerCredits)5 ClientProducerInternal (org.apache.activemq.artemis.core.client.impl.ClientProducerInternal)5 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)1