use of javax.jms.JMSContext in project activemq-artemis by apache.
the class NonExistentQueueTest method sendToNonExistentDestination.
@Test
public void sendToNonExistentDestination() throws Exception {
server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false));
server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false));
Destination destination = ActiveMQJMSClient.createTopic("DoesNotExist");
TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.class.getName());
ConnectionFactory localConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
// Using JMS 1 API
Connection connection = localConnectionFactory.createConnection();
Session session = connection.createSession();
try {
MessageProducer messageProducer = session.createProducer(null);
messageProducer.send(destination, session.createMessage());
Assert.fail("Succeeded in sending message to a non-existent destination using JMS 1 API!");
} catch (JMSException e) {
// Expected }
}
// Using JMS 2 API
JMSContext context = localConnectionFactory.createContext();
JMSProducer jmsProducer = context.createProducer().setDeliveryMode(DeliveryMode.PERSISTENT);
try {
jmsProducer.send(destination, context.createMessage());
Assert.fail("Succeeded in sending message to a non-existent destination using JMS 2 API!");
} catch (JMSRuntimeException e) {
// Expected }
}
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class JMSSecurityTest method testSecurityOnJMSContext.
@Test
public void testSecurityOnJMSContext() throws Exception {
ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
securityManager.getConfiguration().addUser("IDo", "Exist");
try {
JMSContext ctx = cf.createContext("Idont", "exist");
ctx.close();
} catch (JMSSecurityRuntimeException e) {
// expected
}
JMSContext ctx = cf.createContext("IDo", "Exist");
ctx.close();
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class JMSSecurityTest method testCreateQueueConnection.
@Test
public void testCreateQueueConnection() throws Exception {
ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
securityManager.getConfiguration().addUser("IDo", "Exist");
try {
QueueConnection queueC = ((QueueConnectionFactory) cf).createQueueConnection("IDont", "Exist");
fail("supposed to throw exception");
queueC.close();
} catch (JMSSecurityException e) {
// expected
}
JMSContext ctx = cf.createContext("IDo", "Exist");
ctx.close();
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class ConnectionTest method testThroughNewConnectionFactory.
private void testThroughNewConnectionFactory(ActiveMQConnectionFactory factory) throws Exception {
Connection conn = factory.createConnection();
conn.close();
try (JMSContext ctx = factory.createContext()) {
ctx.createProducer().send(ctx.createQueue("queue"), "Test");
}
try (JMSContext ctx = factory.createContext()) {
Assert.assertNotNull(ctx.createConsumer(ctx.createQueue("queue")).receiveNoWait());
Assert.assertNull(ctx.createConsumer(ctx.createQueue("queue")).receiveNoWait());
}
factory.close();
}
use of javax.jms.JMSContext in project activemq-artemis by apache.
the class GroupingTest method testGroupingWithJMS2Producer.
@Test
public void testGroupingWithJMS2Producer() throws Exception {
ConnectionFactory fact = getCF();
Assume.assumeFalse("only makes sense withOUT auto-group", ((ActiveMQConnectionFactory) fact).isAutoGroup());
Assume.assumeTrue("only makes sense withOUT explicit group-id", ((ActiveMQConnectionFactory) fact).getGroupID() == null);
final String groupID = UUID.randomUUID().toString();
JMSContext ctx = addContext(getCF().createContext(JMSContext.SESSION_TRANSACTED));
JMSProducer producer = ctx.createProducer().setProperty("JMSXGroupID", groupID);
JMSConsumer consumer1 = ctx.createConsumer(queue);
JMSConsumer consumer2 = ctx.createConsumer(queue);
JMSConsumer consumer3 = ctx.createConsumer(queue);
ctx.start();
for (int j = 0; j < 100; j++) {
TextMessage message = ctx.createTextMessage("Message" + j);
producer.send(queue, message);
String prop = message.getStringProperty("JMSXGroupID");
assertNotNull(prop);
assertEquals(groupID, prop);
}
ctx.commit();
// All msgs should go to the first consumer
for (int j = 0; j < 100; j++) {
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
tm.acknowledge();
assertEquals("Message" + j, tm.getText());
assertEquals(tm.getStringProperty("JMSXGroupID"), groupID);
tm = (TextMessage) consumer2.receiveNoWait();
assertNull(tm);
tm = (TextMessage) consumer3.receiveNoWait();
assertNull(tm);
}
ctx.commit();
ctx.close();
}
Aggregations