Java Code Examples for javax.jms.JMSContext#setClientID()

The following examples show how to use javax.jms.JMSContext#setClientID() . 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 vote down vote up
@Test(timeout = 60000)
public void testSetClientIDTwiceWithSameID() throws Exception {
    JMSContext context = cf.createContext();

    // test: call setClientID("newID") twice
    // this should be tolerated and not result in an exception
    context.setClientID("newID");

    try {
        context.setClientID("newID");
        context.start();
        context.close();
    } catch (IllegalStateRuntimeException ise) {
        LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
        fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
    } finally {
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
Example 2
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: IntegrationTestFixture.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
JMSContext createJMSContext(TestAmqpPeer testPeer, boolean ssl, String optionsString, Symbol[] serverCapabilities, Map<Symbol, Object> serverProperties, boolean setClientId, int sessionMode) throws JMSException {
    testPeer.expectSaslPlain("guest", "guest");
    testPeer.expectOpen(serverProperties, serverCapabilities);

    // Each connection creates a session for managing temporary destinations etc
    testPeer.expectBegin();

    String remoteURI = buildURI(testPeer, ssl, optionsString);

    ConnectionFactory factory = new JmsConnectionFactory(remoteURI);
    JMSContext context = factory.createContext("guest", "guest", sessionMode);

    if (setClientId) {
        // Set a clientId to provoke the actual AMQP connection process to occur.
        context.setClientID("clientName");
    }

    assertNull(testPeer.getThrowable());

    return context;
}
 
Example 5
Source File: JmsContextTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetGetClientIdNewContext() {
   final String id = "123";
   JMSContext c = context;// createContext();
   c.setClientID(id);
   JMSContext c2 = addContext(c.createContext(Session.CLIENT_ACKNOWLEDGE));
   Assert.assertEquals(id, c2.getClientID());
}
 
Example 6
Source File: JMSContextIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testCreateContextAndSetClientID() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JMSContext context = testFixture.createJMSContext(testPeer, false, null, null, null, false);
        context.setClientID(UUID.randomUUID().toString());
        testPeer.expectClose();
        context.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}