use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class RedeployTest method testRedeploy.
@Test
public void testRedeploy() throws Exception {
Path brokerXML = getTestDirfile().toPath().resolve("broker.xml");
URL url1 = RedeployTest.class.getClassLoader().getResource("reload-test-jms.xml");
URL url2 = RedeployTest.class.getClassLoader().getResource("reload-test-updated-jms.xml");
Files.copy(url1.openStream(), brokerXML);
EmbeddedJMS embeddedJMS = new EmbeddedJMS();
embeddedJMS.setConfigResourcePath(brokerXML.toUri().toString());
embeddedJMS.start();
final ReusableLatch latch = new ReusableLatch(1);
Runnable tick = new Runnable() {
@Override
public void run() {
latch.countDown();
}
};
embeddedJMS.getActiveMQServer().getReloadManager().setTick(tick);
try {
latch.await(10, TimeUnit.SECONDS);
Assert.assertEquals("DLQ", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getDeadLetterAddress().toString());
Assert.assertEquals("ExpiryQueue", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getExpiryAddress().toString());
Assert.assertFalse(tryConsume());
Files.copy(url2.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING);
brokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000);
latch.setCount(1);
embeddedJMS.getActiveMQServer().getReloadManager().setTick(tick);
latch.await(10, TimeUnit.SECONDS);
Assert.assertTrue(tryConsume());
Assert.assertEquals("NewQueue", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getDeadLetterAddress().toString());
Assert.assertEquals("NewQueue", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getExpiryAddress().toString());
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
try (Connection connection = factory.createConnection()) {
Session session = connection.createSession();
Queue queue = session.createQueue("DivertQueue");
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("text"));
connection.start();
MessageConsumer consumer = session.createConsumer(session.createQueue("NewQueue"));
Assert.assertNotNull("Divert wasn't redeployed accordingly", consumer.receive(5000));
}
} finally {
embeddedJMS.stop();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ShutdownOnCriticalIOErrorMoveNextTest method testSimplyDownAfterError.
@Test
public void testSimplyDownAfterError() throws Exception {
deleteDirectory(new File("./target/server"));
ActiveMQServer server = createServer("./target/server");
try {
server.start();
ConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection();
Session session = connection.createSession();
MessageProducer producer = session.createProducer(session.createQueue("queue"));
try {
for (int i = 0; i < 500; i++) {
producer.send(session.createTextMessage("text"));
}
} catch (JMSException expected) {
}
Wait.waitFor(() -> !server.isStarted());
Assert.assertFalse(server.isStarted());
System.out.println("Sent messages");
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class AMQPToJMSCoreTest method testMessageDestination.
@Test
public void testMessageDestination() throws Exception {
System.out.println("foo");
AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
AmqpConnection amqpconnection = client.connect();
try {
AmqpSession session = amqpconnection.createSession();
AmqpSender sender = session.createSender(queueName);
AmqpMessage message = new AmqpMessage();
message.setMessageId("MessageID:" + 0);
// message.setApplicationProperty("_AMQ_ROUTING_TYPE", (byte) 1);
message.getWrappedMessage().setHeader(new Header());
message.getWrappedMessage().getHeader().setDeliveryCount(new UnsignedInteger(2));
sender.send(message);
} finally {
amqpconnection.close();
}
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection = null;
try {
connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queueName));
connection.start();
Message message = consumer.receive(2000);
Assert.assertNotNull(message);
ActiveMQDestination jmsDestination = (ActiveMQDestination) message.getJMSDestination();
Assert.assertEquals(queueName, jmsDestination.getAddress());
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class SessionMetadataAddExceptionTest method testInvalidClientIdSetFactory.
@Test(timeout = 5000, expected = JMSException.class)
public void testInvalidClientIdSetFactory() throws Exception {
ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) cf;
activeMQConnectionFactory.setClientID("invalid");
cf.createConnection();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class SessionTest method testIllegalStateException.
@Test
public void testIllegalStateException() throws Exception {
Connection defaultConn = null;
QueueConnection qConn = null;
Connection connClientID = null;
ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) cf;
try {
String clientID = "somethingElse" + name.getMethodName();
defaultConn = cf.createConnection();
qConn = activeMQConnectionFactory.createQueueConnection();
connClientID = cf.createConnection();
connClientID.setClientID(clientID);
Topic topic = createTopic("topic");
QueueSession qSess = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
try {
qSess.createDurableConsumer(topic, "mySub1");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
qSess.createDurableConsumer(topic, "mySub1", "TEST = 'test'", false);
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
qSess.createSharedConsumer(topic, "mySub1");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
qSess.createSharedConsumer(topic, "mySub1", "TEST = 'test'");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
qSess.createSharedDurableConsumer(topic, "mySub1");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
qSess.createSharedDurableConsumer(topic, "mySub1", "TEST = 'test'");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
Session defaultSess = defaultConn.createSession();
try {
defaultSess.createDurableSubscriber(topic, "mySub1");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
defaultSess.createDurableSubscriber(topic, "mySub1", "TEST = 'test'", true);
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
defaultSess.createDurableConsumer(topic, "mySub1");
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
try {
defaultSess.createDurableConsumer(topic, "mySub1", "TEST = 'test'", true);
fail("exception expected");
} catch (javax.jms.IllegalStateException ex) {
// ok expected.
}
} finally {
if (defaultConn != null) {
defaultConn.close();
}
if (qConn != null) {
qConn.close();
}
if (connClientID != null) {
connClientID.close();
}
}
}
Aggregations