use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class TransactionScopedJMSContextTestCase method sendAndReceiveWithContext.
@Test
public void sendAndReceiveWithContext() throws JMSException, InterruptedException {
int numThreads = 5;
int numMessages = 10;
launcher.start(numThreads, numMessages);
int receivedMessages = 0;
try (JMSContext context = factory.createContext()) {
JMSConsumer consumer = context.createConsumer(queue);
Message m;
do {
m = consumer.receive(1000);
if (m != null) {
receivedMessages++;
}
} while (m != null);
}
assertEquals(numThreads * numMessages, receivedMessages);
}
use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class InjectedJMSContextTestCase method sendAndReceiveWithContext.
@Test
public void sendAndReceiveWithContext() throws JMSException {
String text = UUID.randomUUID().toString();
try (JMSContext context = factory.createContext()) {
TemporaryQueue tempQueue = context.createTemporaryQueue();
context.createProducer().send(tempQueue, text);
assertMessageIsReceived(tempQueue, context, text, false);
}
}
use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class InjectedJMSContextTestCase method tearDown.
@After
public void tearDown() throws JMSException {
// drain the queue to remove any pending messages from it
try (JMSContext context = factory.createContext()) {
JMSConsumer consumer = context.createConsumer(queue);
Message m;
do {
m = consumer.receiveNoWait();
} while (m != null);
}
}
use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class InjectedJMSContextTestCase method sendAndReceiveFromMDB.
private void sendAndReceiveFromMDB(boolean rollback) throws JMSException {
String text = "sendAndReceiveFromMDB " + rollback;
try (JMSContext context = factory.createContext()) {
TemporaryQueue replyTo = context.createTemporaryQueue();
context.createProducer().setJMSReplyTo(replyTo).setProperty("rollback", rollback).send(queue, text);
assertMessageIsReceived(replyTo, context, text, rollback);
}
}
use of javax.jms.JMSContext in project eap-additional-testsuite by jboss-set.
the class AbstractSaslTestBase method sendAndReceiveMsg.
protected void sendAndReceiveMsg(int remotingPort, boolean expectedSaslFail, String username, String password) {
Context namingContext = null;
try {
// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
env.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
env.put(Context.PROVIDER_URL, "remote://" + HOST_FMT + ":" + remotingPort);
namingContext = new InitialContext(env);
// Perform the JNDI lookups
ConnectionFactory connectionFactory = null;
try {
connectionFactory = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
assertFalse("JNDI lookup should have failed.", expectedSaslFail);
} catch (NamingException e) {
if (expectedSaslFail) {
// only SASL failures are expected
assertTrue("Unexpected cause of lookup failure", e.getCause() instanceof SaslException);
return;
}
throw e;
}
Destination destination = (Destination) namingContext.lookup(NAME);
int count = 1;
try (JMSContext context = (username != null ? connectionFactory.createContext(username, password) : connectionFactory.createContext())) {
// Send the specified number of messages
for (int i = 0; i < count; i++) {
context.createProducer().send(destination, MESSAGE);
}
// Create the JMS consumer
JMSConsumer consumer = context.createConsumer(destination);
// Then receive the same number of messages that were sent
for (int i = 0; i < count; i++) {
String text = consumer.receiveBody(String.class, 5000);
Assert.assertEquals(MESSAGE, text);
}
}
} catch (NamingException e) {
LOGGER.error("Naming problem occured.", e);
throw new RuntimeException(e);
} finally {
if (namingContext != null) {
try {
namingContext.close();
} catch (NamingException e) {
LOGGER.error("Naming problem occured during closing context.", e);
}
}
}
}
Aggregations