use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ProducerFlowControlTest method testProducerCreditsCaching7.
@Test
public void testProducerCreditsCaching7() 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" + i, session.createMessage(false));
Assert.assertEquals(i + 1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(i + 1, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
for (int i = 0; i < 10; i++) {
ClientProducer prod = session.createProducer((String) null);
prod.send("address" + i, session.createMessage(false));
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
for (int i = 0; i < 10; i++) {
ClientProducer prod = session.createProducer((String) null);
prod.send("address2-" + i, session.createMessage(false));
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReattachTest method testAsyncFailureWhileReattaching.
// Test an async (e.g. pinger) failure coming in while a connection manager is already reconnecting
@Test
public void testAsyncFailureWhileReattaching() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 60;
final long asyncFailDelay = 200;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
ClientSession session2 = sf.createSession(false, true, true);
class MyFailureListener implements SessionFailureListener {
volatile boolean failed;
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver) {
failed = true;
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
@Override
public void beforeReconnect(final ActiveMQException exception) {
}
}
MyFailureListener listener = new MyFailureListener();
session2.addFailureListener(listener);
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);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.numberOfFailures = 10;
InVMConnector.failOnCreateConnection = true;
final RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
final RemotingConnection conn2 = ((ClientSessionInternal) session2).getConnection();
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(asyncFailDelay);
} catch (InterruptedException ignore) {
}
conn2.fail(new ActiveMQNotConnectedException("Did not receive pong from server"));
}
};
t.start();
conn.fail(new ActiveMQNotConnectedException());
Assert.assertTrue(listener.failed);
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getIntProperty("count").intValue());
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
session.close();
session2.close();
sf.close();
t.join();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReattachTest method testExponentialBackoffMaxRetryInterval.
@Test
public void testExponentialBackoffMaxRetryInterval() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 2d;
final int reconnectAttempts = 60;
final long maxRetryInterval = 100;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setMaxRetryInterval(maxRetryInterval).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);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
InVMConnector.numberOfFailures = 3;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
long start = System.currentTimeMillis();
conn.fail(new ActiveMQNotConnectedException());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getIntProperty("count").intValue());
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
long end = System.currentTimeMillis();
double wait = retryInterval + retryMultiplier * 2 * retryInterval + retryMultiplier;
Assert.assertTrue(end - start >= wait);
Assert.assertTrue(end - start < wait + 500);
session.close();
sf.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReattachTest method testCreateSessionFailAfterSendSeveralThreads.
@Test
public void testCreateSessionFailAfterSendSeveralThreads() throws Throwable {
Timer timer = new Timer();
ClientSession session = null;
try {
final long retryInterval = 100;
final double retryMultiplier = 1d;
final int reconnectAttempts = 300;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
final ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
session = sf.createSession();
final RemotingConnection connFailure = ((ClientSessionInternal) session).getConnection();
int numberOfThreads = 100;
final int numberOfSessionsToCreate = 10;
final CountDownLatch alignLatch = new CountDownLatch(numberOfThreads);
final CountDownLatch startFlag = new CountDownLatch(1);
class CreateSessionThread extends Thread {
Throwable failure;
@Override
public void run() {
try {
alignLatch.countDown();
startFlag.await();
for (int i = 0; i < numberOfSessionsToCreate; i++) {
Thread.yield();
ClientSession session = sf.createSession(false, true, true);
session.close();
}
} catch (Throwable e) {
e.printStackTrace();
failure = e;
}
}
}
CreateSessionThread[] threads = new CreateSessionThread[numberOfThreads];
for (int i = 0; i < numberOfThreads; i++) {
threads[i] = new CreateSessionThread();
threads[i].start();
}
waitForLatch(alignLatch);
timer.schedule(new TimerTask() {
@Override
public void run() {
try {
connFailure.fail(new ActiveMQNotConnectedException());
} catch (Exception e) {
ReattachTest.log.warn("Error on the timer " + e);
}
}
}, 10, 10);
startFlag.countDown();
Throwable failure = null;
for (CreateSessionThread thread : threads) {
thread.join();
if (thread.failure != null) {
System.out.println("Thread " + thread.getName() + " failed - " + thread.failure);
failure = thread.failure;
}
}
if (failure != null) {
throw failure;
}
sf.close();
} finally {
timer.cancel();
if (session != null) {
session.close();
}
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReattachTest method testExponentialBackoff.
@Test
public void testExponentialBackoff() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 2d;
final int reconnectAttempts = 60;
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);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
InVMConnector.failOnCreateConnection = true;
InVMConnector.numberOfFailures = 3;
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
long start = System.currentTimeMillis();
conn.fail(new ActiveMQNotConnectedException());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getObjectProperty(new SimpleString("count")));
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
long end = System.currentTimeMillis();
double wait = retryInterval + retryMultiplier * retryInterval + retryMultiplier * retryMultiplier * retryInterval;
Assert.assertTrue(end - start >= wait);
session.close();
sf.close();
}
Aggregations