use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testRollbackTest.
@Test
public void testRollbackTest() {
JMSContext ctx = addContext(cf.createContext(JMSContext.SESSION_TRANSACTED));
JMSProducer producer = ctx.createProducer();
JMSConsumer cons = ctx.createConsumer(queue1);
producer.send(queue1, context.createTextMessage("hello"));
ctx.rollback();
assertNull(cons.receiveNoWait());
producer.send(queue1, context.createTextMessage("hello"));
ctx.commit();
assertNotNull(cons.receiveNoWait());
ctx.commit();
ctx.rollback();
assertNull(cons.receiveNoWait());
cons.close();
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testExpire.
@Test
public void testExpire() throws Exception {
JMSProducer producer = context.createProducer();
producer.setTimeToLive(500);
String strRandom = newXID().toString();
producer.send(queue1, context.createTextMessage(strRandom));
Thread.sleep(700);
// Create consumer after message is expired, making it to expire at the server's
JMSConsumer consumer = context.createConsumer(queue1);
TextMessage msg = (TextMessage) consumer.receiveNoWait();
// Time to live kicked in, so it's supposed to return null
assertNull(msg);
strRandom = newXID().toString();
producer.send(queue1, context.createTextMessage(strRandom));
Thread.sleep(700);
// Receive second message, expiring on client
msg = (TextMessage) consumer.receiveNoWait();
assertNull(msg);
strRandom = newXID().toString();
producer.send(queue1, context.createTextMessage(strRandom));
// will receive a message that's not expired now
msg = (TextMessage) consumer.receiveNoWait();
assertNotNull(msg);
assertEquals(strRandom, msg.getText());
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testSendStreamMessage.
@Test
public void testSendStreamMessage() throws JMSException, InterruptedException {
JmsProducerCompletionListenerTest.CountingCompletionListener cl = new JmsProducerCompletionListenerTest.CountingCompletionListener(1);
JMSProducer producer = context.createProducer();
producer.setAsync(cl);
StreamMessage msg = context.createStreamMessage();
msg.setStringProperty("name", name.getMethodName());
String bprop = "booleanProp";
String iprop = "intProp";
msg.setBooleanProperty(bprop, true);
msg.setIntProperty(iprop, 42);
msg.writeBoolean(true);
msg.writeInt(67);
producer.send(queue1, msg);
JMSConsumer consumer = context.createConsumer(queue1);
Message msg2 = consumer.receive(100);
Assert.assertNotNull(msg2);
Assert.assertTrue(cl.completionLatch.await(1, TimeUnit.SECONDS));
StreamMessage sm = (StreamMessage) cl.lastMessage;
Assert.assertEquals(true, sm.getBooleanProperty(bprop));
Assert.assertEquals(42, sm.getIntProperty(iprop));
Assert.assertEquals(true, sm.readBoolean());
Assert.assertEquals(67, sm.readInt());
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testInvalidMessage.
@Test
public void testInvalidMessage() {
JMSProducer producer = context.createProducer();
try {
producer.send(queue1, (Message) null);
Assert.fail("null msg");
} catch (MessageFormatRuntimeException expected) {
// no-op
}
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testSetClientIdLate.
@Test
public void testSetClientIdLate() {
JMSProducer producer = context.createProducer();
Message msg = context.createMessage();
producer.send(queue1, msg);
try {
context.setClientID("id");
Assert.fail("expected exception");
} catch (IllegalStateRuntimeException e) {
// no op
}
}
Aggregations