use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ServerLocatorConnectTest method testMultipleConnectorSingleServerNoConnect.
@Test
public void testMultipleConnectorSingleServerNoConnect() throws Exception {
ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(5, isNetty())));
ClientSessionFactoryInternal csf = null;
try {
csf = locator.connect();
} catch (ActiveMQNotConnectedException nce) {
// ok
} catch (Exception e) {
assertTrue(e instanceof ActiveMQException);
fail("Invalid Exception type:" + ((ActiveMQException) e).getType());
}
assertNull(csf);
locator.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailoverTransactionCommit.
// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionCommit() throws Exception {
locator.setCallTimeout(5000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(100);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 5000L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, true, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final CountDownLatch connectionFailed = new CountDownLatch(1);
session.addFailureListener(new SessionFailureListener() {
@Override
public void beforeReconnect(ActiveMQException exception) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed.countDown();
}
});
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
session.start(xid, XAResource.TMNOFLAGS);
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
producer.send(message);
}
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
crash(true, session);
try {
session.commit(xid, false);
} catch (XAException e) {
// there is still an edge condition that we must deal with
Assert.assertTrue(connectionFailed.await(10, TimeUnit.SECONDS));
session.commit(xid, false);
}
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < 500; i++) {
ClientMessage m = consumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(i, m.getIntProperty("counter").intValue());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class LiveToLiveFailoverTest method createSessionFactoryAndWaitForTopology.
protected final ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator, TransportConfiguration transportConfiguration, int topologyMembers) throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(topologyMembers * 2);
locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory(transportConfiguration);
addSessionFactory(sf);
assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
closeSessionFactory(sf);
sf = (ClientSessionFactoryInternal) locator.createSessionFactory(liveServer.getServer().getNodeID().toString());
addSessionFactory(sf);
if (sf2 == null) {
sf2 = (ClientSessionFactoryInternal) locator.createSessionFactory(backupServer.getServer().getNodeID().toString());
ClientSession session2 = createSession(sf2, false, false);
session2.createQueue(ADDRESS, ADDRESS, null, true);
addSessionFactory(sf2);
}
return sf;
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class LiveToLiveFailoverTest method createSessionFactoryAndWaitForTopology.
@Override
protected final ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator, int topologyMembers) throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(topologyMembers * 2);
locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
addSessionFactory(sf);
assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
closeSessionFactory(sf);
sf = (ClientSessionFactoryInternal) locator.createSessionFactory(liveServer.getServer().getNodeID().toString());
addSessionFactory(sf);
if (sf2 == null) {
sf2 = (ClientSessionFactoryInternal) locator.createSessionFactory(backupServer.getServer().getNodeID().toString());
ClientSession session2 = createSession(sf2, false, false);
session2.createQueue(ADDRESS, ADDRESS, null, true);
addSessionFactory(sf2);
}
return sf;
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class MultiThreadReattachSupportTestBase method runMultipleThreadsFailoverTest.
protected void runMultipleThreadsFailoverTest(final RunnableT runnable, final int numThreads, final int numIts, final boolean failOnCreateConnection, final long failDelay) throws Exception {
for (int its = 0; its < numIts; its++) {
log.info("Beginning iteration " + its);
start();
final ServerLocator locator = createLocator();
final ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = addClientSession(sf.createSession(false, true, true));
Failer failer = startFailer(failDelay, session, failOnCreateConnection);
class Runner extends Thread {
private volatile Throwable throwable;
private final RunnableT test;
private final int threadNum;
Runner(final RunnableT test, final int threadNum) {
this.test = test;
this.threadNum = threadNum;
}
@Override
public void run() {
try {
test.run(sf, threadNum);
} catch (Throwable t) {
throwable = t;
log.error("Failed to run test", t);
// Case a failure happened here, it should print the Thread dump
// Sending it to System.out, as it would show on the Tests report
System.out.println(ActiveMQTestBase.threadDump(" - fired by MultiThreadRandomReattachTestBase::runTestMultipleThreads (" + t.getLocalizedMessage() + ")"));
}
}
}
do {
List<Runner> threads = new ArrayList<>();
for (int i = 0; i < numThreads; i++) {
Runner runner = new Runner(runnable, i);
threads.add(runner);
runner.start();
}
for (Runner thread : threads) {
thread.join();
if (thread.throwable != null) {
throw new Exception("Exception on thread " + thread, thread.throwable);
}
}
runnable.checkFail();
} while (!failer.isExecuted());
InVMConnector.resetFailures();
session.close();
locator.close();
Assert.assertEquals(0, sf.numSessions());
Assert.assertEquals(0, sf.numConnections());
sf.close();
stop();
}
}
Aggregations