use of org.apache.activemq.artemis.api.core.client.FailoverEventListener in project activemq-artemis by apache.
the class RaceOnSyncLargeMessageOverReplication2Test method testSendLargeMessage.
@Test
@BMRules(rules = { @BMRule(name = "InterruptSending", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "sendLargeMessageChunk", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.RaceOnSyncLargeMessageOverReplication2Test.messageChunkSent();"), @BMRule(name = "InterruptSync", targetClass = "org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager", targetMethod = "sendLargeMessageFiles", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.RaceOnSyncLargeMessageOverReplication2Test.syncLargeMessage();") })
public void testSendLargeMessage() throws Exception {
final CountDownLatch failedOver = new CountDownLatch(1);
connection.setFailoverListener(new FailoverEventListener() {
@Override
public void failoverEvent(FailoverEventType eventType) {
failedOver.countDown();
}
});
Thread t;
{
final MapMessage message = createLargeMessage();
t = new Thread() {
@Override
public void run() {
try {
producer.send(message);
session.commit();
} catch (JMSException expected) {
expected.printStackTrace();
}
}
};
}
t.start();
// I'm trying to simulate the following race here:
// The message is syncing while the client is already sending the body of the message
Assert.assertTrue(flagChunkEntered.await(10, TimeUnit.SECONDS));
startBackup();
Assert.assertTrue(flagSyncEntered.await(10, TimeUnit.SECONDS));
flagChunkWait.countDown();
t.join(5000);
System.out.println("Thread joined");
Assert.assertFalse(t.isAlive());
flagSyncWait.countDown();
Assert.assertTrue(((SharedNothingBackupActivation) backupServer.getActivation()).waitForBackupSync(10, TimeUnit.SECONDS));
waitForRemoteBackup(connection.getSessionFactory(), 30);
liveServer.fail(true);
Assert.assertTrue(failedOver.await(10, TimeUnit.SECONDS));
{
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
MapMessage message = (MapMessage) consumer.receive(5000);
Assert.assertNotNull(message);
for (int i = 0; i < 10; i++) {
Assert.assertEquals(1024 * 1024, message.getBytes("test" + i).length);
}
session.commit();
}
}
use of org.apache.activemq.artemis.api.core.client.FailoverEventListener in project activemq-artemis by apache.
the class RaceOnSyncLargeMessageOverReplicationTest method testSendLargeMessage.
/*
* simple test to induce a potential race condition where the server's acceptors are active, but the server's
* state != STARTED
*/
@Test
@BMRules(rules = { @BMRule(name = "InterruptSync", targetClass = "org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager", targetMethod = "createLargeMessage(long,org.apache.activemq.artemis.core.message.impl.MessageInternal)", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.RaceOnSyncLargeMessageOverReplicationTest.syncLargeMessage();") })
public void testSendLargeMessage() throws Exception {
final CountDownLatch failedOver = new CountDownLatch(1);
connection.setFailoverListener(new FailoverEventListener() {
@Override
public void failoverEvent(FailoverEventType eventType) {
failedOver.countDown();
}
});
Thread t;
{
final MapMessage message = createLargeMessage();
t = new Thread() {
@Override
public void run() {
try {
producer.send(message);
session.commit();
} catch (JMSException expected) {
expected.printStackTrace();
}
}
};
}
t.start();
// I'm trying to simulate the following race here:
// The message is syncing while the client is already sending the body of the message
Assert.assertTrue(flagArrived.await(10, TimeUnit.SECONDS));
startBackup();
waitForRemoteBackup(connection.getSessionFactory(), 30);
flagWait.countDown();
t.join(5000);
System.out.println("Thread joined");
Assert.assertFalse(t.isAlive());
liveServer.fail(true);
Assert.assertTrue(failedOver.await(10, TimeUnit.SECONDS));
{
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
MapMessage message = (MapMessage) consumer.receive(5000);
Assert.assertNotNull(message);
for (int i = 0; i < 10; i++) {
Assert.assertEquals(1024 * 1024, message.getBytes("test" + i).length);
}
session.commit();
}
}
use of org.apache.activemq.artemis.api.core.client.FailoverEventListener in project activemq-artemis by apache.
the class ReconnectTest method internalMetadataAfterRetry.
public void internalMetadataAfterRetry(final boolean isNetty) throws Exception {
final int pingPeriod = 1000;
ActiveMQServer server = createServer(false, isNetty);
server.start();
ClientSessionInternal session = null;
try {
for (int i = 0; i < 100; i++) {
ServerLocator locator = createFactory(isNetty);
locator.setClientFailureCheckPeriod(pingPeriod);
locator.setRetryInterval(1);
locator.setRetryIntervalMultiplier(1d);
locator.setReconnectAttempts(-1);
locator.setConfirmationWindowSize(-1);
ClientSessionFactory factory = createSessionFactory(locator);
session = (ClientSessionInternal) factory.createSession();
session.addMetaData("meta1", "meta1");
ServerSession[] sessions = countMetadata(server, "meta1", 1);
Assert.assertEquals(1, sessions.length);
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(1);
session.addFailoverListener(new FailoverEventListener() {
@Override
public void failoverEvent(FailoverEventType eventType) {
if (eventType == FailoverEventType.FAILOVER_COMPLETED) {
latch.countDown();
}
}
});
sessions[0].getRemotingConnection().fail(new ActiveMQException("failure!"));
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
sessions = countMetadata(server, "meta1", 1);
Assert.assertEquals(1, sessions.length);
locator.close();
}
} finally {
try {
session.close();
} catch (Throwable e) {
}
server.stop();
}
}
use of org.apache.activemq.artemis.api.core.client.FailoverEventListener in project activemq-artemis by apache.
the class ReplicationWithDivertTest method testSendLargeMessage.
@Test
public void testSendLargeMessage() throws Exception {
final CountDownLatch failedOver = new CountDownLatch(1);
connection.setFailoverListener(new FailoverEventListener() {
@Override
public void failoverEvent(FailoverEventType eventType) {
failedOver.countDown();
}
});
Thread t;
final int numberOfMessage = 5;
{
final MapMessage message = createLargeMessage();
t = new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < numberOfMessage; i++) {
producer.send(message);
session.commit();
}
} catch (JMSException expected) {
expected.printStackTrace();
}
}
};
}
t.start();
t.join(10000);
{
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
for (int msgi = 0; msgi < numberOfMessage; msgi++) {
MapMessage message = (MapMessage) consumer.receive(5000);
Assert.assertNotNull(message);
for (int i = 0; i < 10; i++) {
Assert.assertEquals(200 * 1024, message.getBytes("test" + i).length);
}
session.commit();
}
consumer.close();
}
Assert.assertFalse(t.isAlive());
liveServer.fail(true);
Assert.assertTrue(failedOver.await(10, TimeUnit.SECONDS));
{
MessageConsumer consumer = session.createConsumer(targetQueue);
connection.start();
for (int msgi = 0; msgi < numberOfMessage; msgi++) {
MapMessage message = (MapMessage) consumer.receive(5000);
Assert.assertNotNull(message);
for (int i = 0; i < 10; i++) {
Assert.assertEquals(200 * 1024, message.getBytes("test" + i).length);
}
session.commit();
}
consumer.close();
}
}
Aggregations