use of javax.jms.XAConnectionFactory in project spring-boot by spring-projects.
the class PoolingConnectionFactoryBeanTests method setConnectionFactory.
@Test
public void setConnectionFactory() throws Exception {
XAConnectionFactory factory = mock(XAConnectionFactory.class);
this.bean.setConnectionFactory(factory);
this.bean.setBeanName("beanName");
this.bean.afterPropertiesSet();
this.bean.init();
this.bean.createPooledConnection(factory, this.bean);
verify(factory).createXAConnection();
}
use of javax.jms.XAConnectionFactory in project activemq-artemis by apache.
the class ConcurrentDeliveryCancelTest method testConcurrentCancels.
@Test
@BMRules(rules = { @BMRule(name = "enterCancel-holdThere", targetClass = "org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl", targetMethod = "close", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ConcurrentDeliveryCancelTest.enterCancel();") })
public void testConcurrentCancels() throws Exception {
System.out.println(server.getConfiguration().getJournalLocation().toString());
server.getAddressSettingsRepository().clear();
AddressSettings settings = new AddressSettings();
settings.setMaxDeliveryAttempts(-1);
server.getAddressSettingsRepository().addMatch("#", settings);
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("tcp://localhost:61616", "test");
cf.setReconnectAttempts(0);
cf.setRetryInterval(10);
System.out.println(".....");
for (ServerSession srvSess : server.getSessions()) {
System.out.println(srvSess);
}
String queueName = RandomUtil.randomString();
Queue queue = createQueue(queueName);
int numberOfMessages = 10000;
{
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < numberOfMessages; i++) {
TextMessage msg = session.createTextMessage("message " + i);
msg.setIntProperty("i", i);
producer.send(msg);
}
session.commit();
connection.close();
}
for (int i = 0; i < 100; i++) {
XAConnectionFactory xacf = ActiveMQJMSClient.createConnectionFactory("tcp://localhost:61616", "test");
final XAConnection connection = xacf.createXAConnection();
final XASession theSession = connection.createXASession();
((ActiveMQSession) theSession).getCoreSession().addMetaData("theSession", "true");
connection.start();
final MessageConsumer consumer = theSession.createConsumer(queue);
XidImpl xid = newXID();
theSession.getXAResource().start(xid, XAResource.TMNOFLAGS);
// I'm setting a small timeout just because I'm lazy to call end myself
theSession.getXAResource().setTransactionTimeout(1);
for (int msg = 0; msg < 11; msg++) {
Assert.assertNotNull(consumer.receiveNoWait());
}
System.out.println(".....");
final List<ServerSession> serverSessions = new LinkedList<>();
// We will force now the failure simultaneously from several places
for (ServerSession srvSess : server.getSessions()) {
if (srvSess.getMetaData("theSession") != null) {
System.out.println(srvSess);
serverSessions.add(srvSess);
}
}
// from Transactional reaper
resetLatches(2);
List<Thread> threads = new LinkedList<>();
threads.add(new Thread("ConsumerCloser") {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " closing consumer");
consumer.close();
System.out.println(Thread.currentThread().getName() + " closed consumer");
} catch (Exception e) {
e.printStackTrace();
}
}
});
threads.add(new Thread("SessionCloser") {
@Override
public void run() {
for (ServerSession sess : serverSessions) {
System.out.println("Thread " + Thread.currentThread().getName() + " starting");
try {
// A session.close could sneak in through failover or some other scenarios.
// a call to RemotingConnection.fail wasn't replicating the issue.
// I needed to call Session.close() directly to replicate what was happening in production
sess.close(true);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Thread " + Thread.currentThread().getName() + " done");
}
}
});
for (Thread t : threads) {
t.start();
}
Assert.assertTrue(latchEnter.await(10, TimeUnit.MINUTES));
latchFlag.countDown();
for (Thread t : threads) {
t.join(5000);
Assert.assertFalse(t.isAlive());
}
connection.close();
}
Connection connection = cf.createConnection();
try {
connection.setClientID("myID");
// I am too lazy to call end on all the transactions
Thread.sleep(5000);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue);
HashMap<Integer, AtomicInteger> mapCount = new HashMap<>();
while (true) {
TextMessage message = (TextMessage) consumer.receiveNoWait();
if (message == null) {
break;
}
Integer value = message.getIntProperty("i");
AtomicInteger count = mapCount.get(value);
if (count == null) {
count = new AtomicInteger(0);
mapCount.put(message.getIntProperty("i"), count);
}
count.incrementAndGet();
}
boolean failed = false;
for (int i = 0; i < numberOfMessages; i++) {
AtomicInteger count = mapCount.get(i);
if (count == null) {
System.out.println("Message " + i + " not received");
failed = true;
} else if (count.get() > 1) {
System.out.println("Message " + i + " received " + count.get() + " times");
failed = true;
}
}
Assert.assertFalse("test failed, look at the system.out of the test for more information", failed);
} finally {
connection.close();
}
}
use of javax.jms.XAConnectionFactory in project activemq-artemis by apache.
the class BridgeTestBase method setUpAdministeredObjects.
protected void setUpAdministeredObjects() throws Exception {
cff0LowProducerWindow = new ConnectionFactoryFactory() {
@Override
public ConnectionFactory createConnectionFactory() throws Exception {
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
// Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
cf.setReconnectAttempts(0);
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setCacheLargeMessagesClient(true);
cf.setProducerWindowSize(100);
return cf;
}
};
cff0 = new ConnectionFactoryFactory() {
@Override
public ConnectionFactory createConnectionFactory() throws Exception {
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
// Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
cf.setReconnectAttempts(0);
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setCacheLargeMessagesClient(true);
return cf;
}
};
cff0xa = new ConnectionFactoryFactory() {
@Override
public Object createConnectionFactory() throws Exception {
ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
// Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
cf.setReconnectAttempts(0);
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setCacheLargeMessagesClient(true);
return cf;
}
};
cf0 = (ConnectionFactory) cff0.createConnectionFactory();
cf0xa = (XAConnectionFactory) cff0xa.createConnectionFactory();
cff1 = new ConnectionFactoryFactory() {
@Override
public ConnectionFactory createConnectionFactory() throws Exception {
ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
// Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
cf.setReconnectAttempts(0);
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setCacheLargeMessagesClient(true);
return cf;
}
};
cff1xa = new ConnectionFactoryFactory() {
@Override
public XAConnectionFactory createConnectionFactory() throws Exception {
ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
// Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
cf.setReconnectAttempts(0);
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setCacheLargeMessagesClient(true);
return cf;
}
};
cf1 = (ConnectionFactory) cff1.createConnectionFactory();
cf1xa = (XAConnectionFactory) cff1xa.createConnectionFactory();
sourceQueueFactory = new DestinationFactory() {
@Override
public Destination createDestination() throws Exception {
return (Destination) context0.lookup("/queue/sourceQueue");
}
};
sourceQueue = (Queue) sourceQueueFactory.createDestination();
targetQueueFactory = new DestinationFactory() {
@Override
public Destination createDestination() throws Exception {
return (Destination) context1.lookup("/queue/targetQueue");
}
};
targetQueue = (Queue) targetQueueFactory.createDestination();
sourceTopicFactory = new DestinationFactory() {
@Override
public Destination createDestination() throws Exception {
return (Destination) context0.lookup("/topic/sourceTopic");
}
};
sourceTopic = (Topic) sourceTopicFactory.createDestination();
localTargetQueueFactory = new DestinationFactory() {
@Override
public Destination createDestination() throws Exception {
return (Destination) context0.lookup("/queue/localTargetQueue");
}
};
localTargetQueue = (Queue) localTargetQueueFactory.createDestination();
}
use of javax.jms.XAConnectionFactory in project activemq-artemis by apache.
the class ConnectionFactoryTest method testFactoryTypes.
@Test
public void testFactoryTypes() throws Exception {
deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE_XA_FALSE", "/CF_QUEUE_XA_FALSE");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.CF, "CF_XA_FALSE", "/CF_XA_FALSE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC", "/CF_GENERIC");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_GENERIC_XA_TRUE", "/CF_GENERIC_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC_XA_FALSE", "/CF_GENERIC_XA_FALSE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC_XA_FALSE", "/CF_TOPIC_XA_FALSE");
ActiveMQConnectionFactory factory = null;
factory = (ActiveMQConnectionFactory) ic.lookup("/ConnectionFactory");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_TRUE");
Assert.assertTrue(factory instanceof XAConnectionFactory);
assertNTypes(factory, 6);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_FALSE");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_TRUE");
Assert.assertTrue(factory instanceof XAConnectionFactory);
assertNTypes(factory, 6);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_FALSE");
Assert.assertTrue(factory instanceof ConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE");
Assert.assertTrue(factory instanceof QueueConnectionFactory);
assertNTypes(factory, 3);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
Assert.assertTrue(factory instanceof XAQueueConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_FALSE");
Assert.assertTrue(factory instanceof QueueConnectionFactory);
assertNTypes(factory, 3);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC");
Assert.assertTrue(factory instanceof TopicConnectionFactory);
assertNTypes(factory, 3);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
Assert.assertTrue(factory instanceof XATopicConnectionFactory);
assertNTypes(factory, 4);
factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_FALSE");
Assert.assertTrue(factory instanceof TopicConnectionFactory);
assertNTypes(factory, 3);
undeployConnectionFactory("ConnectionFactory");
undeployConnectionFactory("CF_QUEUE_XA_TRUE");
undeployConnectionFactory("CF_QUEUE_XA_FALSE");
undeployConnectionFactory("CF_XA_TRUE");
undeployConnectionFactory("CF_XA_FALSE");
undeployConnectionFactory("CF_QUEUE");
undeployConnectionFactory("CF_TOPIC");
undeployConnectionFactory("CF_TOPIC_XA_TRUE");
undeployConnectionFactory("CF_GENERIC");
undeployConnectionFactory("CF_GENERIC_XA_TRUE");
undeployConnectionFactory("CF_GENERIC_XA_FALSE");
undeployConnectionFactory("CF_TOPIC_XA_FALSE");
}
use of javax.jms.XAConnectionFactory in project activemq-artemis by apache.
the class ConnectionFactoryTest method testConnectionTypes.
@Test
public void testConnectionTypes() throws Exception {
deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
Connection genericConnection = null;
XAConnection xaConnection = null;
QueueConnection queueConnection = null;
TopicConnection topicConnection = null;
XAQueueConnection xaQueueConnection = null;
XATopicConnection xaTopicConnection = null;
ConnectionFactory genericFactory = (ConnectionFactory) ic.lookup("/ConnectionFactory");
genericConnection = genericFactory.createConnection();
assertConnectionType(genericConnection, "generic");
XAConnectionFactory xaFactory = (XAConnectionFactory) ic.lookup("/CF_XA_TRUE");
xaConnection = xaFactory.createXAConnection();
assertConnectionType(xaConnection, "xa");
QueueConnectionFactory queueCF = (QueueConnectionFactory) ic.lookup("/CF_QUEUE");
queueConnection = queueCF.createQueueConnection();
assertConnectionType(queueConnection, "queue");
TopicConnectionFactory topicCF = (TopicConnectionFactory) ic.lookup("/CF_TOPIC");
topicConnection = topicCF.createTopicConnection();
assertConnectionType(topicConnection, "topic");
XAQueueConnectionFactory xaQueueCF = (XAQueueConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
xaQueueConnection = xaQueueCF.createXAQueueConnection();
assertConnectionType(xaQueueConnection, "xa-queue");
XATopicConnectionFactory xaTopicCF = (XATopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
xaTopicConnection = xaTopicCF.createXATopicConnection();
assertConnectionType(xaTopicConnection, "xa-topic");
genericConnection.close();
xaConnection.close();
queueConnection.close();
topicConnection.close();
xaQueueConnection.close();
xaTopicConnection.close();
undeployConnectionFactory("ConnectionFactory");
undeployConnectionFactory("CF_QUEUE_XA_TRUE");
undeployConnectionFactory("CF_XA_TRUE");
undeployConnectionFactory("CF_QUEUE");
undeployConnectionFactory("CF_TOPIC");
undeployConnectionFactory("CF_TOPIC_XA_TRUE");
}
Aggregations