Java Code Examples for javax.jms.JMSContext#close()
The following examples show how to use
javax.jms.JMSContext#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDTwiceWithDifferentID() throws Exception { JMSContext context = cf.createContext(); // test: call setClientID() twice with different IDs // this should result in an IllegalStateException context.setClientID("newID1"); try { context.setClientID("newID2"); fail("calling Connection.setClientID() twice with different clientID must raise an IllegalStateException"); } catch (IllegalStateRuntimeException ise) { LOG.debug("Correctly received " + ise); } finally { context.close(); cf.stop(); } LOG.debug("Test finished."); }
Example 2
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDAfterConnectionStart() throws Exception { JMSContext context = cf.createContext(); // test: try to call setClientID() after start() // should result in an exception try { context.start(); context.setClientID("newID3"); fail("Calling setClientID() after start() mut raise a JMSException."); } catch (IllegalStateRuntimeException ise) { LOG.debug("Correctly received " + ise); } finally { context.close(); cf.stop(); } LOG.debug("Test finished."); }
Example 3
Source File: JmsContextTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testDupsOK() { JMSContext ctx = addContext(cf.createContext(JMSContext.DUPS_OK_ACKNOWLEDGE)); assertEquals(JMSContext.DUPS_OK_ACKNOWLEDGE, ctx.getSessionMode()); ctx.close(); ctx = addContext(cf.createContext(JMSContext.SESSION_TRANSACTED)); assertEquals(JMSContext.SESSION_TRANSACTED, ctx.getSessionMode()); ctx.close(); ctx = addContext(cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE)); assertEquals(JMSContext.CLIENT_ACKNOWLEDGE, ctx.getSessionMode()); ctx.close(); ctx = addContext(cf.createContext(JMSContext.AUTO_ACKNOWLEDGE)); assertEquals(JMSContext.AUTO_ACKNOWLEDGE, ctx.getSessionMode()); }
Example 4
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateConsumerWithSelectorAndNoLocal() { JMSContext context = cf.createContext(); Queue queue = context.createQueue(getTestName()); assertNotNull(context.createConsumer(queue, "color = red", false)); context.close(); try { context.createConsumer(queue, "color = blue", true); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 5
Source File: JmsContextTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCloseSecondContextConnectionRemainsOpen() throws JMSException { JMSContext localContext = context.createContext(JMSContext.CLIENT_ACKNOWLEDGE); Assert.assertEquals("client_ack", JMSContext.CLIENT_ACKNOWLEDGE, localContext.getSessionMode()); JMSProducer producer = localContext.createProducer(); JMSConsumer consumer = localContext.createConsumer(queue1); final int pass = 1; for (int idx = 0; idx < 2; idx++) { Message m = localContext.createMessage(); int intProperty = random.nextInt(); m.setIntProperty("random", intProperty); Assert.assertNotNull(m); producer.send(queue1, m); m = null; Message msg = consumer.receive(100); Assert.assertNotNull("must have a msg", msg); Assert.assertEquals(intProperty, msg.getIntProperty("random")); /* In the second pass we close the connection before ack'ing */ if (idx == pass) { localContext.close(); } /** * From {@code JMSContext.close()}'s javadoc:<br/> * Invoking the {@code acknowledge} method of a received message from a closed connection's * session must throw an {@code IllegalStateRuntimeException}. Closing a closed connection * must NOT throw an exception. */ try { msg.acknowledge(); Assert.assertEquals("connection should be open on pass 0. It is " + pass, 0, idx); } catch (javax.jms.IllegalStateException expected) { // HORNETQ-1209 "JMS 2.0" XXX JMSContext javadoc says we must expect a // IllegalStateRuntimeException here. But Message.ack...() says it must throws the // non-runtime variant. Assert.assertEquals("we only close the connection on pass " + pass, pass, idx); } } }
Example 6
Source File: JMSConsumerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testReceiveBodyBytesMessage() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer); testPeer.expectBegin(); Queue queue = context.createQueue("myQueue"); PropertiesDescribedType properties = new PropertiesDescribedType(); properties.setContentType(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE); MessageAnnotationsDescribedType msgAnnotations = null; msgAnnotations = new MessageAnnotationsDescribedType(); msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_MSG_TYPE.toString(), AmqpMessageSupport.JMS_BYTES_MESSAGE); final byte[] expectedContent = "expectedContent".getBytes(); DescribedType dataContent = new DataDescribedType(new Binary(expectedContent)); testPeer.expectReceiverAttach(); testPeer.expectLinkFlowRespondWithTransfer(null, msgAnnotations, properties, null, dataContent); testPeer.expectDispositionThatIsAcceptedAndSettled(); JMSConsumer messageConsumer = context.createConsumer(queue); byte[] received = messageConsumer.receiveBody(byte[].class, 3000); testPeer.waitForAllHandlersToComplete(3000); assertNotNull(received); assertTrue(Arrays.equals(expectedContent, received)); testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(3000); } }
Example 7
Source File: JmsConnectionFactoryTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testCreateContextWithUserAndPassword() { JmsConnectionFactory factory = new JmsConnectionFactory("mock://127.0.0.1:5672"); JMSContext context = factory.createContext(USER, PASSWORD); assertNotNull(context); assertEquals(JMSContext.AUTO_ACKNOWLEDGE, context.getSessionMode()); context.close(); }
Example 8
Source File: JmsConnectionFactoryTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testCreateContext() { JmsConnectionFactory factory = new JmsConnectionFactory("mock://127.0.0.1:5672"); JMSContext context = factory.createContext(); assertNotNull(context); assertEquals(JMSContext.AUTO_ACKNOWLEDGE, context.getSessionMode()); context.close(); }
Example 9
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateTextMessageWithPayload() { JMSContext context = cf.createContext(); assertNotNull(context.createTextMessage("body")); context.close(); try { context.createTextMessage("body"); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 10
Source File: JmsConnectionFactoryTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testCreateContextWithSessionMode() { JmsConnectionFactory factory = new JmsConnectionFactory("mock://127.0.0.1:5672"); JMSContext context = factory.createContext(JMSContext.CLIENT_ACKNOWLEDGE); assertNotNull(context); assertEquals(JMSContext.CLIENT_ACKNOWLEDGE, context.getSessionMode()); context.close(); }
Example 11
Source File: JMSContextIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testCreateContextWithClientId() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer, false, null, null, null, true); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 12
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateObjectMessageWithPayload() { JMSContext context = cf.createContext(); assertNotNull(context.createObjectMessage("body")); context.close(); try { context.createObjectMessage("body"); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 13
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateObjectMessage() { JMSContext context = cf.createContext(); assertNotNull(context.createObjectMessage()); context.close(); try { context.createObjectMessage(); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 14
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateMapMessage() { JMSContext context = cf.createContext(); assertNotNull(context.createMapMessage()); context.close(); try { context.createMapMessage(); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 15
Source File: JMSContextIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testCreateContextFromContextWithSessionsActive() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer); assertEquals(JMSContext.AUTO_ACKNOWLEDGE, context.getSessionMode()); testPeer.expectBegin(); context.createTopic("TopicName"); // Create a second should not create a new session yet, once a new connection is // create on demand then close of the second context should only close the session JMSContext other = context.createContext(JMSContext.CLIENT_ACKNOWLEDGE); assertEquals(JMSContext.CLIENT_ACKNOWLEDGE, other.getSessionMode()); testPeer.expectBegin(); testPeer.expectEnd(); other.createTopic("TopicName"); other.close(); testPeer.waitForAllHandlersToComplete(1000); // Now the connection should close down. testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 16
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateMessage() { JMSContext context = cf.createContext(); assertNotNull(context.createMessage()); context.close(); try { context.createMessage(); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 17
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateTemporaryTopic() { JMSContext context = cf.createContext(); assertNotNull(context.createTemporaryTopic()); context.close(); try { context.createTemporaryTopic(); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 18
Source File: JmsConnectionFactoryTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testCreateContextWithUserAndPasswordAndSessionMode() { JmsConnectionFactory factory = new JmsConnectionFactory("mock://127.0.0.1:5672"); JMSContext context = factory.createContext(USER, PASSWORD, JMSContext.CLIENT_ACKNOWLEDGE); assertNotNull(context); assertEquals(JMSContext.CLIENT_ACKNOWLEDGE, context.getSessionMode()); context.close(); }
Example 19
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateTemporaryQueue() { JMSContext context = cf.createContext(); assertNotNull(context.createTemporaryQueue()); context.close(); try { context.createTemporaryQueue(); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 20
Source File: JMSConsumerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testReceiveBodyTextMessage() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer); testPeer.expectBegin(); final String content = "Message-Content"; Queue queue = context.createQueue("myQueue"); DescribedType amqpValueContent = new AmqpValueDescribedType(content); testPeer.expectReceiverAttach(); testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueContent); testPeer.expectDispositionThatIsAcceptedAndSettled(); testPeer.expectEnd(); testPeer.expectClose(); JMSConsumer messageConsumer = context.createConsumer(queue); String received = messageConsumer.receiveBody(String.class, 3000); assertNotNull(received); assertEquals(content, received); context.close(); testPeer.waitForAllHandlersToComplete(3000); } }