use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class FailoverOnFlowControlTest method testOverflowSend.
@Test
public void testOverflowSend() throws Exception {
ServerLocator locator = getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(300).setProducerWindowSize(1000).setRetryInterval(100);
final ArrayList<ClientSession> sessionList = new ArrayList<>();
Interceptor interceptorClient = new Interceptor() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
log.debug("Intercept..." + packet.getClass().getName());
if (packet instanceof SessionProducerCreditsMessage) {
SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
log.debug("Credits: " + credit.getCredits());
if (count.incrementAndGet() == 2) {
log.debug("### crashing server");
try {
InVMConnection.setFlushEnabled(false);
crash(false, sessionList.get(0));
} catch (Exception e) {
e.printStackTrace();
} finally {
InVMConnection.setFlushEnabled(true);
}
return false;
}
}
return true;
}
};
locator.addIncomingInterceptor(interceptorClient);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
ClientSession session = sf.createSession(true, true);
sessionList.add(session);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[5000]);
message.putIntProperty("counter", i);
producer.send(message);
}
session.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailoverConsume.
// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverConsume() throws Exception {
locator.setCallTimeout(5000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setBlockOnAcknowledge(true).setReconnectAttempts(300).setRetryInterval(100).setAckBatchSize(0);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 5000L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, true, true);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
producer.send(message);
}
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(1);
final ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
final Map<Integer, ClientMessage> received = new HashMap<>();
consumer.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(ClientMessage message) {
Integer counter = message.getIntProperty("counter");
received.put(counter, message);
try {
log.debug("acking message = id = " + message.getMessageID() + ", counter = " + message.getIntProperty("counter"));
message.acknowledge();
} catch (ActiveMQException e) {
e.printStackTrace();
return;
}
log.debug("Acked counter = " + counter);
if (counter.equals(10)) {
latch.countDown();
}
if (received.size() == 500) {
endLatch.countDown();
}
}
});
latch.await(10, TimeUnit.SECONDS);
log.info("crashing session");
crash(session);
endLatch.await(60, TimeUnit.SECONDS);
Assert.assertTrue("received only " + received.size(), received.size() == 500);
session.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class MultipleBackupsFailoverTestBase method createSessionFactoryAndWaitForTopology.
protected ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator, int topologyMembers, ActiveMQServer server) throws Exception {
ClientSessionFactoryInternal sf;
CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);
FailoverTestBase.LatchClusterTopologyListener topListener = new FailoverTestBase.LatchClusterTopologyListener(countDownLatch);
locator.addClusterTopologyListener(topListener);
sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
addSessionFactory(sf);
boolean ok = countDownLatch.await(5, TimeUnit.SECONDS);
locator.removeClusterTopologyListener(topListener);
if (!ok) {
if (server != null) {
log.info("failed topology, Topology on server = " + server.getClusterManager().describe());
}
}
Assert.assertTrue("expected " + topologyMembers + " members", ok);
return sf;
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class ActiveMQTestBase method waitForRemoteBackup.
/**
* @param sessionFactoryP
* @param seconds
* @param waitForSync
* @param backup
*/
public static final void waitForRemoteBackup(ClientSessionFactory sessionFactoryP, int seconds, boolean waitForSync, final ActiveMQServer backup) {
ClientSessionFactoryInternal sessionFactory = (ClientSessionFactoryInternal) sessionFactoryP;
final ActiveMQServerImpl actualServer = (ActiveMQServerImpl) backup;
final long toWait = seconds * 1000;
final long time = System.currentTimeMillis();
int loop = 0;
while (true) {
Activation activation = actualServer.getActivation();
boolean isReplicated = !backup.getHAPolicy().isSharedStore();
boolean isRemoteUpToDate = true;
if (isReplicated) {
if (activation instanceof SharedNothingBackupActivation) {
isRemoteUpToDate = backup.isReplicaSync();
} else {
// we may have already failed over and changed the Activation
if (actualServer.isStarted()) {
// let it fail a few time to have time to start stopping in the case of waiting to failback
isRemoteUpToDate = loop++ > 10;
} else {
// we could be waiting to failback or restart if the server is stopping
isRemoteUpToDate = false;
}
}
}
if ((sessionFactory == null || sessionFactory.getBackupConnector() != null) && (isRemoteUpToDate || !waitForSync) && (!waitForSync || actualServer.getBackupManager() != null && actualServer.getBackupManager().isBackupAnnounced())) {
break;
}
if (System.currentTimeMillis() > (time + toWait)) {
fail("backup started? (" + actualServer.isStarted() + "). Finished synchronizing (" + (activation) + "). SessionFactory!=null ? " + (sessionFactory != null) + " || sessionFactory.getBackupConnector()==" + (sessionFactory != null ? sessionFactory.getBackupConnector() : "not-applicable"));
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.
the class LiveOnlyActivation method connectToScaleDownTarget.
public void connectToScaleDownTarget(ScaleDownPolicy scaleDownPolicy) {
try {
scaleDownServerLocator = ScaleDownPolicy.getScaleDownConnector(scaleDownPolicy, activeMQServer);
// use a Node Locator to connect to the cluster
scaleDownServerLocator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(scaleDownServerLocator));
LiveNodeLocator nodeLocator = scaleDownPolicy.getGroupName() == null ? new AnyLiveNodeLocatorForScaleDown(activeMQServer) : new NamedLiveNodeLocatorForScaleDown(scaleDownPolicy.getGroupName(), activeMQServer);
scaleDownServerLocator.addClusterTopologyListener(nodeLocator);
nodeLocator.connectToCluster(scaleDownServerLocator);
// a timeout is necessary here in case we use a NamedLiveNodeLocatorForScaleDown and there's no matching node in the cluster
// should the timeout be configurable?
nodeLocator.locateNode(ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT);
ClientSessionFactoryInternal clientSessionFactory = null;
while (clientSessionFactory == null) {
Pair<TransportConfiguration, TransportConfiguration> possibleLive = null;
try {
possibleLive = nodeLocator.getLiveConfiguration();
if (// we've tried every connector
possibleLive == null)
break;
clientSessionFactory = (ClientSessionFactoryInternal) scaleDownServerLocator.createSessionFactory(possibleLive.getA(), 0, false);
} catch (Exception e) {
logger.trace("Failed to connect to " + possibleLive.getA());
nodeLocator.notifyRegistrationFailed(false);
if (clientSessionFactory != null) {
clientSessionFactory.close();
}
clientSessionFactory = null;
// should I try the backup (i.e. getB()) from possibleLive?
}
}
if (clientSessionFactory != null) {
scaleDownClientSessionFactory = clientSessionFactory;
} else {
throw new ActiveMQException("Unable to connect to server for scale-down");
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToScaleDown(e);
}
}
Aggregations