use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal 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());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ProducerFlowControlTest method testProducerCreditsCaching6.
@Test
public void testProducerCreditsCaching6() 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);
for (int i = 0; i < ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE; i++) {
ClientProducer prod = session.createProducer((String) null);
prod.send("address", session.createMessage(false));
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 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());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class BMFailoverTest method testFailoverOnCommit2.
@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "start(javax.transaction.xa.Xid, int)", targetLocation = "AT EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)") })
public void testFailoverOnCommit2() throws Exception {
serverToStop = liveServer;
locator = getServerLocator().setFailoverOnInitialConnection(true);
SimpleString inQueue = new SimpleString("inQueue");
SimpleString outQueue = new SimpleString("outQueue");
createSessionFactory();
createSessionFactory2();
// closeable will take care of closing it
try (ClientSession session = sf.createSession(false, true, true);
ClientProducer sendInitialProducer = session.createProducer()) {
session.createQueue(inQueue, inQueue, null, true);
session.createQueue(outQueue, outQueue, null, true);
sendInitialProducer.send(inQueue, createMessage(session, 0, true));
}
ClientSession xaSessionRec = addClientSession(sf.createSession(true, false, false));
ClientConsumer consumer = addClientConsumer(xaSessionRec.createConsumer(inQueue));
byte[] globalTransactionId = UUIDGenerator.getInstance().generateStringUUID().getBytes();
Xid xidRec = new XidImpl("xa2".getBytes(), 1, globalTransactionId);
xaSessionRec.start();
xaSessionRec.getXAResource().start(xidRec, XAResource.TMNOFLAGS);
// failover is now occurring, receive, ack and end will be called whilst this is happening.
ClientMessageImpl m = (ClientMessageImpl) consumer.receive(5000);
assertNotNull(m);
System.out.println("********************" + m.getIntProperty("counter"));
// the mdb would ack the message before calling onMessage()
m.acknowledge();
try {
// this may fail but thats ok, it depends on the race and when failover actually happens
xaSessionRec.end(xidRec, XAResource.TMSUCCESS);
} catch (XAException ignore) {
}
// we always reset the client on the RA
((ClientSessionInternal) xaSessionRec).resetIfNeeded();
// closeable will take care of closing it
try (ClientSession session = sf.createSession(false, true, true);
ClientProducer sendInitialProducer = session.createProducer()) {
sendInitialProducer.send(inQueue, createMessage(session, 0, true));
}
// now receive and send a message successfully
globalTransactionId = UUIDGenerator.getInstance().generateStringUUID().getBytes();
xidRec = new XidImpl("xa4".getBytes(), 1, globalTransactionId);
xaSessionRec.getXAResource().start(xidRec, XAResource.TMNOFLAGS);
Binding binding = backupServer.getServer().getPostOffice().getBinding(inQueue);
Queue inQ = (Queue) binding.getBindable();
m = (ClientMessageImpl) consumer.receive(5000);
assertNotNull(m);
// the mdb would ack the message before calling onMessage()
m.acknowledge();
System.out.println("********************" + m.getIntProperty("counter"));
xaSessionRec.getXAResource().end(xidRec, XAResource.TMSUCCESS);
xaSessionRec.getXAResource().prepare(xidRec);
xaSessionRec.getXAResource().commit(xidRec, false);
// let's close the consumer so anything pending is handled
consumer.close();
assertEquals(1, getMessageCount(inQ));
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReattachTest method testReattachAttemptsFailsToReconnect.
@Test
public void testReattachAttemptsFailsToReconnect() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 3;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeString("aardvarks");
producer.send(message);
}
session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
// Sleep for longer than max retries so should fail to reconnect
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(retryInterval * (reconnectAttempts + 1));
} catch (InterruptedException ignore) {
}
InVMConnector.failOnCreateConnection = false;
}
};
t.start();
conn.fail(new ActiveMQNotConnectedException());
try {
session.start();
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
sf.close();
t.join();
}
Aggregations