use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class XATest method testMultipleSessionsOneTxCommitSend.
@Test
public void testMultipleSessionsOneTxCommitSend() throws Exception {
// Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
try {
conn = xacf.createXAConnection();
conn.start();
tm.begin();
// Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource();
XASession sess2 = conn.createXASession();
ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource();
res1.setForceNotSameRM(true);
res2.setForceNotSameRM(true);
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
// Send 2 messages - one from each session
MessageProducer prod1 = sess1.createProducer(queue1);
MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
// commit
tm.commit();
// Messages should be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r1);
Assert.assertEquals("echidna1", r1.getText());
TextMessage r2 = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r2);
Assert.assertEquals("echidna2", r2.getText());
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ReconnectTest method internalTestReconnect.
public void internalTestReconnect(final boolean isNetty) throws Exception {
final int pingPeriod = 1000;
ActiveMQServer server = createServer(false, isNetty);
server.start();
ClientSessionInternal session = null;
try {
ServerLocator locator = createFactory(isNetty).setClientFailureCheckPeriod(pingPeriod).setRetryInterval(500).setRetryIntervalMultiplier(1d).setReconnectAttempts(-1).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactory factory = createSessionFactory(locator);
session = (ClientSessionInternal) factory.createSession();
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(1);
session.addFailureListener(new SessionFailureListener() {
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver) {
count.incrementAndGet();
latch.countDown();
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
@Override
public void beforeReconnect(final ActiveMQException exception) {
}
});
server.stop();
Thread.sleep((pingPeriod * 2));
server.start();
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
// Some time to let possible loops to occur
Thread.sleep(500);
Assert.assertEquals(1, count.get());
locator.close();
} finally {
try {
session.close();
} catch (Throwable e) {
}
server.stop();
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal 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.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class HQClientProtocolManagerTest method testNoCheckFailoverMessage.
@Test
public void testNoCheckFailoverMessage() throws Exception {
final int pingPeriod = 1000;
ActiveMQServer server = createServer(false, true);
server.start();
ClientSessionInternal session = null;
try {
ServerLocator locator = createFactory(true).setClientFailureCheckPeriod(pingPeriod).setRetryInterval(500).setRetryIntervalMultiplier(1d).setReconnectAttempts(-1).setConfirmationWindowSize(1024 * 1024);
locator.setProtocolManagerFactory(new HornetQClientProtocolManagerFactory());
ClientSessionFactory factory = createSessionFactory(locator);
session = (ClientSessionInternal) factory.createSession();
server.stop();
Thread.sleep((pingPeriod * 2));
List<String> incomings = server.getConfiguration().getIncomingInterceptorClassNames();
incomings.add(UnsupportedPacketInterceptor.class.getName());
server.start();
// issue a query to make sure session is reconnected.
ClientSession.QueueQuery query = session.queueQuery(new SimpleString("anyvalue"));
assertFalse(query.isExists());
locator.close();
UnsupportedPacketInterceptor.checkReceivedTypes();
} finally {
try {
session.close();
} catch (Throwable e) {
}
server.stop();
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class XATest method testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization.
@Test
public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception {
XAConnection conn = null;
Connection conn2 = null;
try {
// First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish3");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish4");
prod.send(m);
conn = xacf.createXAConnection();
conn.start();
tm.begin();
// Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
ClientSessionInternal res1 = (ClientSessionInternal) sess1.getXAResource();
XASession sess2 = conn.createXASession();
ClientSessionInternal res2 = (ClientSessionInternal) sess2.getXAResource();
Transaction tx = tm.getTransaction();
tx.enlistResource(res1);
tx.enlistResource(res2);
// Receive the messages, two on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage) cons1.receive(5000);
Assert.assertNotNull(r1);
Assert.assertEquals("jellyfish1", r1.getText());
r1 = (TextMessage) cons1.receive(5000);
Assert.assertNotNull(r1);
Assert.assertEquals("jellyfish2", r1.getText());
cons1.close();
MessageConsumer cons2 = sess2.createConsumer(queue1);
TextMessage r2 = (TextMessage) cons2.receive(5000);
Assert.assertNotNull(r2);
Assert.assertEquals("jellyfish3", r2.getText());
r2 = (TextMessage) cons2.receive(5000);
Assert.assertNotNull(r2);
Assert.assertEquals("jellyfish4", r2.getText());
cons2.close();
// rollback
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.rollback();
// Rollback causes cancel which is asynch
Thread.sleep(1000);
// We cannot assume anything about the order in which the transaction manager rollsback
// the sessions - this is implementation dependent
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
boolean session1First = false;
if (r.getText().equals("jellyfish1")) {
session1First = true;
} else if (r.getText().equals("jellyfish3")) {
session1First = false;
} else {
Assert.fail("Unexpected message");
}
if (session1First) {
r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
Assert.assertEquals("jellyfish2", r.getText());
r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
Assert.assertEquals("jellyfish3", r.getText());
r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
Assert.assertEquals("jellyfish4", r.getText());
} else {
r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
Assert.assertEquals("jellyfish4", r.getText());
r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
Assert.assertEquals("jellyfish1", r.getText());
r = (TextMessage) cons.receive(5000);
Assert.assertNotNull(r);
Assert.assertEquals("jellyfish2", r.getText());
}
r = (TextMessage) cons.receive(100);
Assert.assertNull(r);
} finally {
if (conn != null) {
conn.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
Aggregations