use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testServerShutdownAndReconnect.
@Test
public void testServerShutdownAndReconnect() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
qResourceAdapter.setReconnectAttempts(-1);
qResourceAdapter.setCallTimeout(500L);
qResourceAdapter.setRetryInterval(500L);
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.start(ctx);
// This is just to register a listener
final CountDownLatch failedLatch = new CountDownLatch(1);
ClientSessionFactoryInternal factoryListener = (ClientSessionFactoryInternal) qResourceAdapter.getDefaultActiveMQConnectionFactory().getServerLocator().createSessionFactory();
factoryListener.addFailureListener(new SessionFailureListener() {
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(exception, failedOver);
}
@Override
public void beforeReconnect(ActiveMQException exception) {
failedLatch.countDown();
}
});
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
CountDownLatch latch = new CountDownLatch(1);
DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
qResourceAdapter.endpointActivation(endpointFactory, spec);
ClientSession session = locator.createSessionFactory().createSession();
ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("teststring");
clientProducer.send(message);
session.close();
latch.await(5, TimeUnit.SECONDS);
assertNotNull(endpoint.lastMessage);
assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
server.stop();
assertTrue(failedLatch.await(5, TimeUnit.SECONDS));
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class SharedNothingLiveActivation method isNodeIdUsed.
/**
* Determines whether there is another server already running with this server's nodeID.
* <p>
* This can happen in case of a successful fail-over followed by the live's restart
* (attempting a fail-back).
*
* @throws Exception
*/
private boolean isNodeIdUsed() throws Exception {
if (activeMQServer.getConfiguration().getClusterConfigurations().isEmpty())
return false;
SimpleString nodeId0;
try {
nodeId0 = activeMQServer.getNodeManager().readNodeId();
} catch (ActiveMQIllegalStateException e) {
nodeId0 = null;
}
ClusterConnectionConfiguration config = ConfigurationUtils.getReplicationClusterConfiguration(activeMQServer.getConfiguration(), replicatedPolicy.getClusterName());
NodeIdListener listener = new NodeIdListener(nodeId0, activeMQServer.getConfiguration().getClusterUser(), activeMQServer.getConfiguration().getClusterPassword());
try (ServerLocatorInternal locator = getLocator(config)) {
locator.addClusterTopologyListener(listener);
locator.setReconnectAttempts(0);
try (ClientSessionFactoryInternal factory = locator.connectNoWarnings()) {
// Just try connecting
listener.latch.await(5, TimeUnit.SECONDS);
} catch (Exception notConnected) {
return false;
}
return listener.isNodePresent;
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ActiveMQTestBase method waitForRemoteBackup.
public static final void waitForRemoteBackup(ClientSessionFactory sessionFactory, int seconds) {
ClientSessionFactoryInternal factoryInternal = (ClientSessionFactoryInternal) sessionFactory;
final long toWait = seconds * 1000;
final long time = System.currentTimeMillis();
while (true) {
if (factoryInternal.getBackupConnector() != null) {
break;
}
if (System.currentTimeMillis() > (time + toWait)) {
fail("Backup wasn't located");
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
}
Aggregations