Beispiel #1
0
  @Test
  public void testSecurityOnJMSContext() throws Exception {

    server.getSecurityManager().addUser("IDo", "Exist");
    try {
      JMSContext ctx = cf.createContext("Idont", "exist");
      ctx.close();
    } catch (JMSSecurityRuntimeException e) {
      // expected
    }
    JMSContext ctx = cf.createContext("IDo", "Exist");
    ctx.close();
    ;
  }
Beispiel #2
0
  @Test
  public void testContextStopAndCloseFromMessageListeners() throws Exception {
    final JMSContext context1 = context.createContext(Session.AUTO_ACKNOWLEDGE);
    JMSConsumer consumer1 = context1.createConsumer(queue1);

    final CountDownLatch latch1 = new CountDownLatch(1);

    InvalidMessageListener listener1 = new InvalidMessageListener(context1, latch1, 1);

    consumer1.setMessageListener(listener1);

    JMSProducer producer = context1.createProducer();
    Message msg = context1.createTextMessage("first message");
    producer.send(queue1, msg);

    latch1.await();

    Throwable error1 = listener1.getError();

    assertNotNull(error1);

    assertTrue(error1 instanceof IllegalStateRuntimeException);

    context1.close();

    final JMSContext context2 = context.createContext(Session.AUTO_ACKNOWLEDGE);
    JMSConsumer consumer2 = context2.createConsumer(queue1);

    final CountDownLatch latch2 = new CountDownLatch(1);

    InvalidMessageListener listener2 = new InvalidMessageListener(context2, latch2, 2);

    consumer2.setMessageListener(listener2);

    JMSProducer producer2 = context2.createProducer();
    Message msg2 = context2.createTextMessage("second message");
    producer2.send(queue1, msg2);

    latch2.await();

    Throwable error2 = listener2.getError();

    assertNotNull(error2);

    assertTrue(error2 instanceof IllegalStateRuntimeException);

    context2.close();
  }
Beispiel #3
0
 private void closeContext() {
   try {
     context.close();
   } catch (Throwable t) {
     error = t;
   }
 }
  @Override
  @After
  public void tearDown() throws Exception {
    try {
      for (JMSContext jmsContext : contextSet) {
        jmsContext.close();
      }
    } catch (RuntimeException ignored) {
      // no-op
    } finally {
      contextSet.clear();
    }
    try {
      if (conn != null) conn.close();
    } catch (Exception e) {
      // no-op
    }

    namingContext.close();
    jmsServer.stop();
    server = null;
    cf = null;
    jmsServer = null;

    namingContext = null;

    MBeanServerFactory.releaseMBeanServer(mbeanServer);

    mbeanServer = null;

    ServiceUtils.setTransactionManager(null);

    super.tearDown();
  }
Beispiel #5
0
  @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());
  }
 @PreDestroy
 void shutdown() {
   closeQuietly(gaugesConsumer);
   closeQuietly(countersConsumer);
   closeQuietly(availabilityConsumer);
   if (context != null) {
     try {
       context.close();
     } catch (JMSRuntimeException ignored) {
     }
   }
 }
Beispiel #7
0
  @Test
  public void testCreateQueueConnection() throws Exception {

    server.getSecurityManager().addUser("IDo", "Exist");
    try {
      QueueConnection queueC =
          ((QueueConnectionFactory) cf).createQueueConnection("IDont", "Exist");
      fail("supposed to throw exception");
      queueC.close();
    } catch (JMSSecurityException e) {
      // expected
    }
    JMSContext ctx = cf.createContext("IDo", "Exist");
    ctx.close();
    ;
  }
Beispiel #8
0
 @Test
 public void testGetAnotherContextFromIt() {
   JMSContext c2 = context.createContext(Session.DUPS_OK_ACKNOWLEDGE);
   Assert.assertNotNull(c2);
   Assert.assertEquals(Session.DUPS_OK_ACKNOWLEDGE, c2.getSessionMode());
   Message m2 = c2.createMessage();
   Assert.assertNotNull(m2);
   c2.close(); // should close its session, but not its (shared) connection
   try {
     c2.createMessage();
     Assert.fail("session should be closed...");
   } catch (JMSRuntimeException expected) {
     // expected
   }
   Message m1 = context.createMessage();
   Assert.assertNotNull("connection must be open", m1);
 }
Beispiel #9
0
 @Test
 public void bytesMessage() throws Exception {
   context = cf.createContext();
   try {
     JMSProducer producer = context.createProducer();
     BytesMessage bMsg = context.createBytesMessage();
     bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
     bMsg.writeByte((byte) 1);
     bMsg.writeInt((int) 22);
     CountDownLatch latch = new CountDownLatch(1);
     SimpleCompletionListener listener = new SimpleCompletionListener(latch);
     producer.setAsync(listener);
     producer.send(queue1, bMsg);
     assertTrue(latch.await(5, TimeUnit.SECONDS));
     assertEquals(listener.message.readByte(), (byte) 1);
     assertEquals(listener.message.readInt(), (int) 22);
   } finally {
     context.close();
   }
 }
Beispiel #10
0
  @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);
      }
      // 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.
      catch (javax.jms.IllegalStateException expected) {
        Assert.assertEquals("we only close the connection on pass " + pass, pass, idx);
      }
    }
  }