newConnection.setClientID(getOutboundClientId());
newConnection.setClientID(getLocalClientId());
public Object call() throws JMSException { topicConnection = tcf.createTopicConnection(); topicConnection.setClientID(clientId); return topicConnection; } }
public Object call() throws JMSException { topicConnection = tcf.createTopicConnection(); topicConnection.setClientID(clientId); return topicConnection; } }
public Object call() throws JMSException { topicConnection = tcf.createTopicConnection(); topicConnection.setClientID(clientId); return topicConnection; } }
publisherTopic = (Topic) ctx.lookup(TOPIC_NAME); publisherConnection = publisherTCF.createTopicConnection(); publisherConnection.setClientID("publisherConnection"); publisherSession = publisherConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); publisher = publisherSession.createPublisher(publisherTopic); subscriberTopic = (Topic) ctx.lookup(TOPIC_NAME); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createSubscriber(subscriberTopic);
/** * Test that a durable subscriber effectively receives the messages sent to * its topic while it was inactive. */ public void testDurableSubscriber() { try { subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic"); subscriberConnection.close(); subscriberConnection = null; TextMessage message = publisherSession.createTextMessage(); message.setText("test"); publisher.publish(message); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic"); subscriberConnection.start(); TextMessage m = (TextMessage) subscriber.receive(TestConfig.TIMEOUT); Assert.assertTrue(m != null); Assert.assertEquals("test", m.getText()); } catch (JMSException e) { fail(e); } }
subscriberConnection.setClientID("testSetClientID_1"); assertEquals("testSetClientID_1", subscriberConnection.getClientID()); subscriberConnection.setClientID("another client ID"); fail("Should raise a javax.jms.IllegalStateException");
connection.setClientID(clientID);
outboundTopicConnection.setClientID(getOutboundClientId());
newConnection.setClientID(getOutboundClientId());
connection.setClientID(clientID);
localTopicConnection.setClientID(getLocalClientId());
publisherTopic = (Topic) ctx.lookup(PubSubTestCase.TOPIC_NAME); publisherConnection = publisherTCF.createTopicConnection(); publisherConnection.setClientID("publisherConnection"); publisherSession = publisherConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); publisher = publisherSession.createPublisher(publisherTopic); subscriberTopic = (Topic) ctx.lookup(PubSubTestCase.TOPIC_NAME); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createSubscriber(subscriberTopic);
subscriberConnection.setClientID("testSetClientID_2"); fail("Should throw a javax.jms.IllegalStateException");
@Test public void testInvalidSelectorOnSubscription() throws Exception { TopicConnection c = createTopicConnection(); c.setClientID("something"); TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); try { s.createSubscriber(ActiveMQServerTestCase.topic1, "=TEST 'test'", false); ProxyAssertSupport.fail("this should fail"); } catch (InvalidSelectorException e) { // OK } }
/** * Test introduced as a result of a TCK failure. */ @Test public void testNonDurableSubscriberInvalidUnsubscribe() throws Exception { TopicConnection conn = createTopicConnection(); conn.setClientID("clientIDxyz123"); TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); try { ts.unsubscribe("invalid-subscription-name"); ProxyAssertSupport.fail("this should fail"); } catch (javax.jms.InvalidDestinationException e) { // OK } }
/** * Test that a call to <code>setClientID</code> will throw an * <code>IllegalStateException</code> if a client ID has already been set * see JMS javadoc * http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String) */ @Test public void testSetClientID_1() { try { // we start from a clean state for the connection subscriberConnection.close(); subscriberConnection = null; subscriberConnection = subscriberTCF.createTopicConnection(); // if the JMS provider does not set a client ID, we do. if (subscriberConnection.getClientID() == null) { subscriberConnection.setClientID("testSetClientID_1"); Assert.assertEquals("testSetClientID_1", subscriberConnection.getClientID()); } // now the connection has a client ID (either "testSetClientID_1" or one set by the provider Assert.assertTrue(subscriberConnection.getClientID() != null); // an attempt to set a client ID should now throw an IllegalStateException subscriberConnection.setClientID("another client ID"); Assert.fail("Should raise a javax.jms.IllegalStateException"); } catch (javax.jms.IllegalStateException e) { } catch (JMSException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a " + e); } catch (java.lang.IllegalStateException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException"); } }
/** * Test that a call to <code>setClientID</code> can occur only after connection creation * and before any other action on the connection. * <em>This test is relevant only if the ID is set by the JMS client</em> * see JMS javadoc * http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String) */ @Test public void testSetClientID_2() { try { // we start from a clean state for the first connection subscriberConnection.close(); subscriberConnection = null; subscriberConnection = subscriberTCF.createTopicConnection(); // if the JMS provider has set a client ID, this test is not relevant if (subscriberConnection.getClientID() != null) { return; } // we start the connection subscriberConnection.start(); // an attempt to set the client ID now should throw an IllegalStateException subscriberConnection.setClientID("testSetClientID_2"); Assert.fail("Should throw a javax.jms.IllegalStateException"); } catch (javax.jms.IllegalStateException e) { } catch (JMSException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a " + e); } catch (java.lang.IllegalStateException e) { Assert.fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException"); } }
/** * Test that a durable subscriber effectively receives the messages sent to its * topic while it was inactive. */ @Test public void testDurableSubscriber() { try { subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic"); subscriberConnection.close(); subscriberConnection = null; TextMessage message = publisherSession.createTextMessage(); message.setText("test"); publisher.publish(message); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic"); subscriberConnection.start(); TextMessage m = (TextMessage) subscriber.receive(TestConfig.TIMEOUT); Assert.assertTrue(m != null); Assert.assertEquals("test", m.getText()); subscriber.close(); subscriberSession.unsubscribe("testTopic"); } catch (JMSException e) { fail(e); } }