use of org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException in project activemq-artemis by apache.
the class ProducerFlowControlTest method testClosingSessionUnblocksBlockedProducer.
@Test
public void testClosingSessionUnblocksBlockedProducer() throws Exception {
final SimpleString address = new SimpleString("testaddress");
server = createServer(false, isNetty());
AddressSettings addressSettings = new AddressSettings().setMaxSizeBytes(1024).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(address.toString(), addressSettings);
server.start();
waitForServerToStart(server);
locator.setProducerWindowSize(1024).setConsumerWindowSize(1024).setAckBatchSize(1024);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
final SimpleString queueName = new SimpleString("testqueue");
session.createQueue(address, queueName, null, false);
ClientProducer producer = session.createProducer(address);
byte[] bytes = new byte[2000];
ClientMessage message = session.createMessage(false);
message.getBodyBuffer().writeBytes(bytes);
final AtomicBoolean closed = new AtomicBoolean(false);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(500);
closed.set(true);
session.close();
} catch (Exception e) {
}
}
});
t.start();
try {
// This will block
for (int i = 0; i < 10; i++) {
producer.send(message);
}
} catch (ActiveMQObjectClosedException expected) {
}
Assert.assertTrue(closed.get());
t.join();
}
use of org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException 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();
}
use of org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException in project activemq-artemis by apache.
the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.
@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
ClientSession session = addClientSession(sf.createSession());
session.createQueue("fooaddress", RoutingType.ANYCAST, "fooqueue");
ClientProducer prod = session.createProducer("fooaddress");
ClientConsumer cons = session.createConsumer("fooqueue");
session.start();
prod.send(session.createMessage(false));
Assert.assertNotNull(cons.receive());
// Now fail the underlying connection
RemotingConnection connection = ((ClientSessionInternal) session).getConnection();
connection.fail(new ActiveMQNotConnectedException());
Assert.assertTrue(session.isClosed());
Assert.assertTrue(prod.isClosed());
Assert.assertTrue(cons.isClosed());
try {
prod.send(session.createMessage(false));
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
cons.receive();
Assert.fail("Should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException in project activemq-artemis by apache.
the class SlowConsumerTest method testSlowWildcardConsumer.
@Test
public void testSlowWildcardConsumer() throws Exception {
SimpleString addressAB = new SimpleString("a.b");
SimpleString addressAC = new SimpleString("a.c");
SimpleString address = new SimpleString("a.*");
SimpleString queueName1 = new SimpleString("Q1");
SimpleString queueName2 = new SimpleString("Q2");
SimpleString queueName = new SimpleString("Q");
AddressSettings addressSettings = new AddressSettings();
addressSettings.setSlowConsumerCheckPeriod(2);
addressSettings.setSlowConsumerThreshold(10);
addressSettings.setSlowConsumerPolicy(SlowConsumerPolicy.KILL);
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, true, true, false));
session.createQueue(addressAB, queueName1, null, false);
session.createQueue(addressAC, queueName2, null, false);
session.createQueue(address, queueName, null, false);
ClientProducer producer = session.createProducer(addressAB);
ClientProducer producer2 = session.createProducer(addressAC);
final int numMessages = 20;
for (int i = 0; i < numMessages; i++) {
producer.send(createTextMessage(session, "m1" + i));
producer2.send(createTextMessage(session, "m2" + i));
}
ClientConsumer consumer = addClientConsumer(session.createConsumer(queueName));
session.start();
Thread.sleep(3000);
try {
consumer.receiveImmediate();
fail();
} catch (ActiveMQObjectClosedException e) {
assertEquals(e.getType(), ActiveMQExceptionType.OBJECT_CLOSED);
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException in project activemq-artemis by apache.
the class ReceiveTest method testReceiveOnClosedException.
@Test
public void testReceiveOnClosedException() throws Exception {
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession session = cf.createSession(false, true, true);
session.createQueue(addressA, queueA, false);
ClientConsumer cc = session.createConsumer(queueA);
session.start();
session.close();
try {
cc.receive();
Assert.fail("should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
session.close();
}
Aggregations