コード例 #1
0
  private void setupServer(final JournalType journalType) throws Exception {
    Configuration config =
        createDefaultNettyConfig()
            .setJournalType(journalType)
            .setJournalFileSize(ActiveMQDefaultConfiguration.getDefaultJournalFileSize())
            .setJournalMinFiles(ActiveMQDefaultConfiguration.getDefaultJournalMinFiles())
            .setJournalCompactMinFiles(2)
            .setJournalCompactPercentage(50);

    server = createServer(true, config);

    server.start();

    ServerLocator locator =
        createNettyNonHALocator()
            .setBlockOnDurableSend(false)
            .setBlockOnNonDurableSend(false)
            .setBlockOnAcknowledge(false);

    sf = createSessionFactory(locator);

    ClientSession sess = sf.createSession();

    try {
      sess.createQueue(ADDRESS, QUEUE, true);
    } catch (Exception ignored) {
    }

    sess.close();
    locator.close();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
  }
コード例 #2
0
  @Test
  public void testBody2() throws Exception {
    final String QUEUE_NAME = "A1";
    ActiveMQServer server = createServer(true);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);

    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);

    ClientProducer producer = session.createProducer(QUEUE_NAME);

    ClientMessage msg = session.createMessage(true);
    byte[] bodyTst = new byte[10];
    for (int i = 0; i < 10; i++) {
      bodyTst[i] = (byte) (i + 1);
    }
    msg.getBodyBuffer().writeBytes(bodyTst);
    assertEquals(bodyTst.length, msg.getBodySize());
    producer.send(msg);

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, false, true);
    ClientSession managementSession = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session, managementSession);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();

    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    assertEquals(msg.getBodySize(), bodyTst.length);
    byte[] bodyRead = new byte[bodyTst.length];
    msg.getBodyBuffer().readBytes(bodyRead);
    assertEqualsByteArrays(bodyTst, bodyRead);

    session.close();
    locator.close();
    server.stop();
  }
コード例 #3
0
  public synchronized void handleLargeMessage(
      final ClientLargeMessageInternal clientLargeMessage, long largeMessageSize) throws Exception {
    if (closing) {
      // This is ok - we just ignore the message
      return;
    }

    // Flow control for the first packet, we will have others
    File largeMessageCache = null;

    if (session.isCacheLargeMessageClient()) {
      largeMessageCache =
          File.createTempFile(
              "tmp-large-message-" + clientLargeMessage.getMessageID() + "-", ".tmp");
      largeMessageCache.deleteOnExit();
    }

    ClientSessionFactory sf = session.getSessionFactory();
    ServerLocator locator = sf.getServerLocator();
    long callTimeout = locator.getCallTimeout();

    currentLargeMessageController =
        new LargeMessageControllerImpl(this, largeMessageSize, callTimeout, largeMessageCache);

    if (clientLargeMessage.isCompressed()) {
      clientLargeMessage.setLargeMessageController(
          new CompressedLargeMessageControllerImpl(currentLargeMessageController));
    } else {
      clientLargeMessage.setLargeMessageController(currentLargeMessageController);
    }

    handleRegularMessage(clientLargeMessage);
  }
コード例 #4
0
  /**
   * This method deals with messages arrived as regular message but its contents are compressed.
   * Such messages come from message senders who are configured to compress large messages, and if
   * some of the messages are compressed below the min-large-message-size limit, they are sent as
   * regular messages. <br>
   * However when decompressing the message, we are not sure how large the message could be.. for
   * that reason we fake a large message controller that will deal with the message as it was a
   * large message <br>
   * Say that you sent a 1G message full of spaces. That could be just bellow 100K compressed but
   * you wouldn't have enough memory to decompress it
   */
  private void handleCompressedMessage(final ClientMessageInternal clMessage) throws Exception {
    ClientLargeMessageImpl largeMessage = new ClientLargeMessageImpl();
    largeMessage.retrieveExistingData(clMessage);

    File largeMessageCache = null;

    if (session.isCacheLargeMessageClient()) {
      largeMessageCache =
          File.createTempFile("tmp-large-message-" + largeMessage.getMessageID() + "-", ".tmp");
      largeMessageCache.deleteOnExit();
    }

    ClientSessionFactory sf = session.getSessionFactory();
    ServerLocator locator = sf.getServerLocator();
    long callTimeout = locator.getCallTimeout();

    currentLargeMessageController =
        new LargeMessageControllerImpl(
            this, largeMessage.getLargeMessageSize(), callTimeout, largeMessageCache);
    currentLargeMessageController.setLocal(true);

    // sets the packet
    ActiveMQBuffer qbuff = clMessage.getBodyBuffer();
    int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
    final byte[] body = qbuff.readBytes(bytesToRead).toByteBuffer().array();

    largeMessage.setLargeMessageController(
        new CompressedLargeMessageControllerImpl(currentLargeMessageController));
    currentLargeMessageController.addPacket(body, body.length, false);

    handleRegularMessage(largeMessage);
  }
コード例 #5
0
  @Test
  public void testLinkedListOrder() throws Exception {
    ServerLocator locator = createInVMNonHALocator();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createSession();

    session.start();

    ClientProducer producer = session.createProducer("foo");

    ClientConsumer redConsumer = session.createConsumer("foo", "color='red'");

    ClientConsumer anyConsumer = session.createConsumer("foo");

    sendMessage(session, producer, "any", "msg1");

    sendMessage(session, producer, "any", "msg2");

    sendMessage(session, producer, "any", "msg3");

    sendMessage(session, producer, "red", "msgRed4");

    sendMessage(session, producer, "red", "msgRed5");

    readConsumer("anyConsumer", anyConsumer);

    readConsumer("anyConsumer", anyConsumer);

    log.info("### closing consumer ###");

    anyConsumer.close();

    readConsumer("redConsumer", redConsumer);

    readConsumer("redConsumer", redConsumer);

    log.info("### recreating consumer ###");

    anyConsumer = session.createConsumer("foo");

    session.start();

    readConsumer("anyConsumer", anyConsumer);

    session.close();

    sf.close();

    locator.close();
  }
コード例 #6
0
  private void dotestMultipleGroupingXACommit() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession clientSession = sessionFactory.createSession(true, false, false);
    ClientProducer clientProducer = this.clientSession.createProducer(qName);
    ClientConsumer consumer = clientSession.createConsumer(qName);
    ClientConsumer consumer2 = clientSession.createConsumer(qName);
    clientSession.start();

    Xid xid = new XidImpl("bq".getBytes(), 4, "gtid".getBytes());
    clientSession.start(xid, XAResource.TMNOFLAGS);

    SimpleString groupId = new SimpleString("grp1");
    SimpleString groupId2 = new SimpleString("grp2");
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(clientSession, "m" + i);
      if (i % 2 == 0 || i == 0) {
        message.putStringProperty(Message.HDR_GROUP_ID, groupId);
      } else {
        message.putStringProperty(Message.HDR_GROUP_ID, groupId2);
      }
      clientProducer.send(message);
    }
    CountDownLatch latch = new CountDownLatch(numMessages);
    DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
    consumer.setMessageHandler(dummyMessageHandler);
    DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
    consumer2.setMessageHandler(dummyMessageHandler2);
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    clientSession.commit(xid, false);
    Assert.assertEquals(dummyMessageHandler.list.size(), 50);
    int i = 0;
    for (ClientMessage message : dummyMessageHandler.list) {
      Assert.assertEquals(message.getBodyBuffer().readString(), "m" + i);
      i += 2;
    }
    Assert.assertEquals(dummyMessageHandler2.list.size(), 50);
    i = 1;
    for (ClientMessage message : dummyMessageHandler2.list) {
      Assert.assertEquals(message.getBodyBuffer().readString(), "m" + i);
      i += 2;
    }
    consumer.close();
    consumer2.close();
    consumer = this.clientSession.createConsumer(qName);
    Assert.assertNull(consumer.receiveImmediate());
    clientSession.close();
    locator.close();
  }
コード例 #7
0
  @Test
  public void testBody() throws Exception {
    final String QUEUE_NAME = "A1";
    ActiveMQServer server = createServer(true);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);

    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);

    ClientProducer producer = session.createProducer(QUEUE_NAME);

    ClientMessage msg = session.createMessage(Message.TEXT_TYPE, true);
    msg.getBodyBuffer().writeString("bob123");
    producer.send(msg);

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, false, true);
    ClientSession managementSession = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session, managementSession);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();

    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    assertEquals("bob123", msg.getBodyBuffer().readString());

    session.close();
    locator.close();
    server.stop();
  }
コード例 #8
0
  private void doTestMultipleGroupingTXCommit() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession clientSession = sessionFactory.createSession(false, false, false);
    ClientProducer clientProducer = this.clientSession.createProducer(qName);
    clientSession.start();

    ClientConsumer consumer = clientSession.createConsumer(qName);
    ClientConsumer consumer2 = clientSession.createConsumer(qName);

    // Wait a bit otherwise consumers might be busy
    Thread.sleep(200);

    SimpleString groupId = new SimpleString("grp1");
    SimpleString groupId2 = new SimpleString("grp2");
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(clientSession, "m" + i);
      if (i % 2 == 0 || i == 0) {
        message.putStringProperty(Message.HDR_GROUP_ID, groupId);
      } else {
        message.putStringProperty(Message.HDR_GROUP_ID, groupId2);
      }
      clientProducer.send(message);
    }

    CountDownLatch latch = new CountDownLatch(numMessages);
    DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
    consumer.setMessageHandler(dummyMessageHandler);
    DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
    consumer2.setMessageHandler(dummyMessageHandler2);
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    clientSession.commit();
    Assert.assertEquals(dummyMessageHandler.list.size(), 50);
    int i = 0;
    for (ClientMessage message : dummyMessageHandler.list) {
      Assert.assertEquals(message.getBodyBuffer().readString(), "m" + i);
      i += 2;
    }
    Assert.assertEquals(dummyMessageHandler2.list.size(), 50);
    i = 1;
    for (ClientMessage message : dummyMessageHandler2.list) {
      Assert.assertEquals(message.getBodyBuffer().readString(), "m" + i);
      i += 2;
    }
    consumer.close();
    consumer2.close();
    consumer = this.clientSession.createConsumer(qName);
    Assert.assertNull(consumer.receiveImmediate());
    clientSession.close();
    locator.close();
  }
コード例 #9
0
  protected ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(
      ServerLocator locator, int topologyMembers) throws Exception {
    CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);

    locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));

    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
    addSessionFactory(sf);

    Assert.assertTrue(
        "topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
    return sf;
  }
コード例 #10
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    server = internalCreateServer();

    server.createAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    Queue queue = server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
    queue.getPageSubscription().getPagingStore().startPaging();

    for (int i = 0; i < 10; i++) {
      queue.getPageSubscription().getPagingStore().forceAnotherPage();
    }

    final ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
    ClientProducer prod = session.createProducer(ADDRESS);

    for (int i = 0; i < 500; i++) {
      ClientMessage msg = session.createMessage(true);
      msg.putIntProperty("key", i);
      prod.send(msg);
      if (i > 0 && i % 10 == 0) {
        session.commit();
      }
    }

    session.close();
    locator.close();

    server.stop();

    internalCreateServer();
  }
コード例 #11
0
  @Test
  public void testReceiveImmediate() throws Exception {

    // forces perfect round robin
    locator.setConsumerWindowSize(1);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    ClientProducer cp = sendSession.createProducer(addressA);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueA);
    session.start();
    cp.send(sendSession.createMessage(false));
    cp.send(sendSession.createMessage(false));
    cp.send(sendSession.createMessage(false));
    sendSession.commit();

    Assert.assertNotNull(cc2.receive(5000));
    Assert.assertNotNull(cc.receive(5000));
    if (cc.receiveImmediate() == null) {
      Assert.assertNotNull(cc2.receiveImmediate());
    }
    session.close();
    sendSession.close();
  }
コード例 #12
0
  @Test
  public void testJmsDestination() throws Exception {
    ClientSession session = basicSetUp();

    jmsServer.createQueue(
        true, "myQueue", null, true, "myQueueJndiBinding1", "myQueueJndiBinding2");
    jmsServer.createTopic(true, "myTopic", "myTopicJndiBinding1", "myTopicJndiBinding2");

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);

    assertNotNull(namingContext.lookup("myQueueJndiBinding1"));
    assertNotNull(namingContext.lookup("myQueueJndiBinding2"));
    assertNotNull(namingContext.lookup("myTopicJndiBinding1"));
    assertNotNull(namingContext.lookup("myTopicJndiBinding2"));

    jmsServer.createConnectionFactory(
        "test-cf", false, JMSFactoryType.CF, Arrays.asList("in-vm1"), "test-cf");

    ConnectionFactory cf = (ConnectionFactory) namingContext.lookup("test-cf");
    Connection connection = cf.createConnection();
    Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer =
        jmsSession.createProducer((Destination) namingContext.lookup("myQueueJndiBinding1"));
    producer.send(jmsSession.createTextMessage());
    MessageConsumer consumer =
        jmsSession.createConsumer((Destination) namingContext.lookup("myQueueJndiBinding2"));
    connection.start();
    assertNotNull(consumer.receive(3000));

    consumer = jmsSession.createConsumer((Destination) namingContext.lookup("myTopicJndiBinding1"));
    producer = jmsSession.createProducer((Destination) namingContext.lookup("myTopicJndiBinding2"));
    producer.send(jmsSession.createTextMessage());
    assertNotNull(consumer.receive(3000));

    connection.close();
  }
コード例 #13
0
    public void start() throws Exception {
      liveNode.start();
      waitForServerToStart(liveNode.getActiveMQServer());
      backupNode.start();
      waitForRemoteBackupSynchronization(backupNode.getActiveMQServer());

      locator = ActiveMQClient.createServerLocatorWithHA(liveConnector).setReconnectAttempts(-1);
      sessionFactory = locator.createSessionFactory();
    }
コード例 #14
0
  protected void stopServer() throws Exception {
    locator.close();
    closeSessionFactory(factory);

    factory = null;

    stopComponent(server);

    server = null;
  }
コード例 #15
0
 @Override
 @Before
 public void setUp() throws Exception {
   super.setUp();
   server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), true));
   server.start();
   // then we create a client as normal
   locator = createInVMNonHALocator();
   locator.setMinLargeMessageSize(1024);
   ClientSessionFactory sessionFactory = createSessionFactory(locator);
   clientSession = addClientSession(sessionFactory.createSession(false, true, false));
 }
  public void testDuplicate() throws Exception {
    ActiveMQDestination queue = (ActiveMQDestination) session.createQueue("TEST,TEST");
    for (int i = 0; i < data.length; i++) {
      Message message = createMessage(i);
      configureMessage(message);
      if (verbose) {
        LOG.info("About to send a message: " + message + " with text: " + data[i]);
      }
      producer.send(queue, message);
    }

    Thread.sleep(200); // wait for messages to be queue;

    try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
        ClientSessionFactory factory = locator.createSessionFactory();
        ClientSession session = factory.createSession()) {
      ClientSession.QueueQuery query = session.queueQuery(new SimpleString("jms.queue.TEST"));
      assertNotNull(query);
      assertEquals(data.length, query.getMessageCount());
    }
  }
コード例 #17
0
  @Test
  public void testStopStartMultipleConsumers() throws Exception {
    locator.setConsumerWindowSize(getMessageEncodeSize(QUEUE) * 33);
    ClientSessionFactory sf = createSessionFactory(locator);

    final ClientSession session = sf.createSession(false, true, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(session, "m" + i);
      message.putIntProperty(new SimpleString("i"), i);
      producer.send(message);
    }

    ClientConsumer consumer = session.createConsumer(QUEUE);
    ClientConsumer consumer2 = session.createConsumer(QUEUE);
    ClientConsumer consumer3 = session.createConsumer(QUEUE);

    session.start();

    ClientMessage cm = consumer.receive(5000);
    Assert.assertNotNull(cm);
    cm.acknowledge();
    cm = consumer2.receive(5000);
    Assert.assertNotNull(cm);
    cm.acknowledge();
    cm = consumer3.receive(5000);
    Assert.assertNotNull(cm);
    cm.acknowledge();

    session.stop();
    cm = consumer.receiveImmediate();
    Assert.assertNull(cm);
    cm = consumer2.receiveImmediate();
    Assert.assertNull(cm);
    cm = consumer3.receiveImmediate();
    Assert.assertNull(cm);

    session.start();
    cm = consumer.receive(5000);
    Assert.assertNotNull(cm);
    cm = consumer2.receive(5000);
    Assert.assertNotNull(cm);
    cm = consumer3.receive(5000);
    Assert.assertNotNull(cm);
    session.close();
  }
コード例 #18
0
  @Test
  public void testPartialQueue() throws Exception {
    ClientSession session = basicSetUp();

    session.createQueue("myAddress", "myQueue1", true);
    session.createQueue("myAddress", "myQueue2", true);

    ClientProducer producer = session.createProducer("myAddress");

    ClientMessage msg = session.createMessage(true);
    producer.send(msg);

    ClientConsumer consumer = session.createConsumer("myQueue1");
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    msg.acknowledge();
    consumer.close();

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);
    consumer = session.createConsumer("myQueue1");
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNull(msg);
    consumer.close();

    consumer = session.createConsumer("myQueue2");
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
  }
コード例 #19
0
  @Test
  public void testMessageAttributes() throws Exception {

    ClientSession session = basicSetUp();

    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);

    ClientProducer producer = session.createProducer(QUEUE_NAME);

    ClientMessage msg = session.createMessage(Message.BYTES_TYPE, true);
    msg.setExpiration(Long.MAX_VALUE);
    msg.setPriority((byte) 0);
    msg.setTimestamp(Long.MAX_VALUE - 1);
    msg.setUserID(UUIDGenerator.getInstance().generateUUID());
    producer.send(msg);

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();

    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Long.MAX_VALUE, msg.getExpiration());
    assertEquals((byte) 0, msg.getPriority());
    assertEquals(Long.MAX_VALUE - 1, msg.getTimestamp());
    assertNotNull(msg.getUserID());
  }
コード例 #20
0
 @Override
 protected URI internalNewURI(ServerLocator bean) throws Exception {
   DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration();
   UDPBroadcastEndpointFactory endpoint =
       (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory();
   dgc.setBroadcastEndpointFactory(endpoint);
   String query = getData(IGNORED, bean, dgc, endpoint);
   return new URI(
       SchemaConstants.UDP,
       null,
       endpoint.getGroupAddress(),
       endpoint.getGroupPort(),
       null,
       query,
       null);
 }
コード例 #21
0
  @Test
  public void testBindingAttributes() throws Exception {
    ClientSession session = basicSetUp();

    session.createQueue("addressName1", "queueName1", true);
    session.createQueue("addressName1", "queueName2", "bob", true);

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);

    ClientSession.QueueQuery queueQuery = session.queueQuery(new SimpleString("queueName1"));

    assertEquals("addressName1", queueQuery.getAddress().toString());
    assertNull(queueQuery.getFilterString());

    queueQuery = session.queueQuery(new SimpleString("queueName2"));

    assertEquals("addressName1", queueQuery.getAddress().toString());
    assertEquals("bob", queueQuery.getFilterString().toString());
    assertEquals(true, queueQuery.isDurable());
  }
コード例 #22
0
  @Test
  public void testBrowseWithZeroConsumerWindowSize() throws Exception {
    locator.setConsumerWindowSize(0);

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createSession(false, true, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    byte[] bytes = new byte[240];

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = session.createMessage(false);

      message.getBodyBuffer().writeBytes(bytes);

      message.putIntProperty("foo", i);

      producer.send(message);
    }

    // Create a normal non browsing consumer
    session.createConsumer(QUEUE);

    session.start();

    ClientConsumer browser = session.createConsumer(QUEUE, true);

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message2 = browser.receive(1000);

      assertEquals(i, message2.getIntProperty("foo").intValue());
    }

    session.close();
  }
コード例 #23
0
  @Test
  public void testSimpleConsumerBrowser() throws Exception {
    locator.setBlockOnNonDurableSend(true);

    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(session, "m" + i);
      producer.send(message);
    }

    ClientConsumer consumer = session.createConsumer(QUEUE, null, true);

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message2 = consumer.receive(1000);

      Assert.assertEquals("m" + i, message2.getBodyBuffer().readString());
    }

    consumer.close();

    consumer = session.createConsumer(QUEUE, null, true);

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message2 = consumer.receive(1000);

      Assert.assertEquals("m" + i, message2.getBodyBuffer().readString());
    }

    consumer.close();

    session.close();
  }
コード例 #24
0
  @Test
  public void testRestartCounter() throws Exception {
    Queue queue =
        server.createQueue(new SimpleString("A1"), new SimpleString("A1"), null, true, false);

    PageSubscriptionCounter counter = locateCounter(queue);

    StorageManager storage = server.getStorageManager();

    Transaction tx = new TransactionImpl(server.getStorageManager());

    counter.increment(tx, 1);

    assertEquals(0, counter.getValue());

    tx.commit();

    storage.waitOnOperations();

    assertEquals(1, counter.getValue());

    sl.close();

    server.stop();

    server = newActiveMQServer();

    server.start();

    queue = server.locateQueue(new SimpleString("A1"));

    assertNotNull(queue);

    counter = locateCounter(queue);

    assertEquals(1, counter.getValue());
  }
コード例 #25
0
  @Test
  public void testPagedLargeMessage() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";

    ActiveMQServer server = createServer(true);

    AddressSettings defaultSetting =
        new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();

    ServerLocator locator =
        createInVMNonHALocator()
            // Making it synchronous, just because we want to stop sending messages as soon as the
            // page-store becomes in
            // page mode and we could only guarantee that by setting it to synchronous
            .setBlockOnNonDurableSend(true)
            .setBlockOnDurableSend(true)
            .setBlockOnAcknowledge(true);

    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);

    session.createQueue(MY_ADDRESS, MY_QUEUE, true);

    ClientProducer producer = session.createProducer(MY_ADDRESS);

    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeBytes(new byte[1024]);

    for (int i = 0; i < 200; i++) {
      producer.send(message);
    }

    LargeServerMessageImpl fileMessage =
        new LargeServerMessageImpl((JournalStorageManager) server.getStorageManager());

    fileMessage.setMessageID(1005);
    fileMessage.setDurable(true);

    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
      fileMessage.addBytes(new byte[] {getSamplebyte(i)});
    }

    fileMessage.putLongProperty(
        Message.HDR_LARGE_BODY_SIZE, 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    fileMessage.releaseResources();

    producer.send(fileMessage);

    fileMessage.deleteFile();

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    // System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);

    ClientConsumer consumer = session.createConsumer(MY_QUEUE);

    session.start();

    for (int i = 0; i < 200; i++) {
      message = consumer.receive(CONSUMER_TIMEOUT);

      assertNotNull(message);
    }

    ClientMessage msg = consumer.receive(CONSUMER_TIMEOUT);

    assertNotNull(msg);

    assertEquals(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, msg.getBodySize());

    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
      assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
    }

    session.close();
    locator.close();
    server.stop();
  }
コード例 #26
0
  @Test
  public void testPaging() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";

    server = createServer(true);

    AddressSettings defaultSetting =
        new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();

    locator =
        createInVMNonHALocator()
            // Making it synchronous, just because we want to stop sending messages as soon as the
            // page-store becomes in
            // page mode and we could only guarantee that by setting it to synchronous
            .setBlockOnNonDurableSend(true)
            .setBlockOnDurableSend(true)
            .setBlockOnAcknowledge(true);

    factory = createSessionFactory(locator);
    ClientSession session = factory.createSession(false, true, true);

    session.createQueue(MY_ADDRESS, MY_QUEUE, true);

    ClientProducer producer = session.createProducer(MY_ADDRESS);

    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeBytes(new byte[1024]);

    for (int i = 0; i < 200; i++) {
      producer.send(message);
    }

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);

    ClientConsumer consumer = session.createConsumer(MY_QUEUE);

    session.start();

    for (int i = 0; i < 200; i++) {
      message = consumer.receive(CONSUMER_TIMEOUT);

      assertNotNull(message);
    }
  }
コード例 #27
0
  @Test
  public void testMessageProperties() throws Exception {
    ClientSession session = basicSetUp();

    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);

    ClientProducer producer = session.createProducer(QUEUE_NAME);

    StringBuilder international = new StringBuilder();
    for (char x = 800; x < 1200; x++) {
      international.append(x);
    }

    String special = "\"<>'&";

    for (int i = 0; i < 5; i++) {
      ClientMessage msg = session.createMessage(true);
      msg.getBodyBuffer().writeString("Bob the giant pig " + i);
      msg.putBooleanProperty("myBooleanProperty", Boolean.TRUE);
      msg.putByteProperty("myByteProperty", new Byte("0"));
      msg.putBytesProperty("myBytesProperty", new byte[] {0, 1, 2, 3, 4});
      msg.putDoubleProperty("myDoubleProperty", i * 1.6);
      msg.putFloatProperty("myFloatProperty", i * 2.5F);
      msg.putIntProperty("myIntProperty", i);
      msg.putLongProperty("myLongProperty", Long.MAX_VALUE - i);
      msg.putObjectProperty("myObjectProperty", i);
      msg.putObjectProperty("myNullObjectProperty", null);
      msg.putShortProperty("myShortProperty", new Integer(i).shortValue());
      msg.putStringProperty("myStringProperty", "myStringPropertyValue_" + i);
      msg.putStringProperty("myNullStringProperty", null);
      msg.putStringProperty("myNonAsciiStringProperty", international.toString());
      msg.putStringProperty("mySpecialCharacters", special);
      msg.putStringProperty(
          new SimpleString("mySimpleStringProperty"),
          new SimpleString("mySimpleStringPropertyValue_" + i));
      msg.putStringProperty(new SimpleString("myNullSimpleStringProperty"), null);
      producer.send(msg);
    }

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();

    for (int i = 0; i < 5; i++) {
      ClientMessage msg = consumer.receive(CONSUMER_TIMEOUT);
      byte[] body = new byte[msg.getBodySize()];
      msg.getBodyBuffer().readBytes(body);
      assertTrue(new String(body).contains("Bob the giant pig " + i));
      assertEquals(msg.getBooleanProperty("myBooleanProperty"), Boolean.TRUE);
      assertEquals(msg.getByteProperty("myByteProperty"), new Byte("0"));
      byte[] bytes = msg.getBytesProperty("myBytesProperty");
      for (int j = 0; j < 5; j++) {
        assertEquals(j, bytes[j]);
      }
      assertEquals(i * 1.6, msg.getDoubleProperty("myDoubleProperty"), 0.000001);
      assertEquals(i * 2.5F, msg.getFloatProperty("myFloatProperty"), 0.000001);
      assertEquals(i, msg.getIntProperty("myIntProperty").intValue());
      assertEquals(Long.MAX_VALUE - i, msg.getLongProperty("myLongProperty").longValue());
      assertEquals(i, msg.getObjectProperty("myObjectProperty"));
      assertEquals(null, msg.getObjectProperty("myNullObjectProperty"));
      assertEquals(
          new Integer(i).shortValue(), msg.getShortProperty("myShortProperty").shortValue());
      assertEquals("myStringPropertyValue_" + i, msg.getStringProperty("myStringProperty"));
      assertEquals(null, msg.getStringProperty("myNullStringProperty"));
      assertEquals(international.toString(), msg.getStringProperty("myNonAsciiStringProperty"));
      assertEquals(special, msg.getStringProperty("mySpecialCharacters"));
      assertEquals(
          new SimpleString("mySimpleStringPropertyValue_" + i),
          msg.getSimpleStringProperty(new SimpleString("mySimpleStringProperty")));
      assertEquals(
          null, msg.getSimpleStringProperty(new SimpleString("myNullSimpleStringProperty")));
    }
  }
コード例 #28
0
  @Test
  public void testLargeMessage() throws Exception {
    server = createServer(true);
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    ClientSession session = factory.createSession(false, false);

    LargeServerMessageImpl fileMessage =
        new LargeServerMessageImpl((JournalStorageManager) server.getStorageManager());

    fileMessage.setMessageID(1005);
    fileMessage.setDurable(true);

    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
      fileMessage.addBytes(new byte[] {getSamplebyte(i)});
    }

    fileMessage.putLongProperty(
        Message.HDR_LARGE_BODY_SIZE, 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    fileMessage.releaseResources();

    session.createQueue("A", "A", true);

    ClientProducer prod = session.createProducer("A");

    prod.send(fileMessage);

    fileMessage.deleteFile();

    session.commit();

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);
    session.close();
    session = factory.createSession(false, false);
    session.start();

    ClientConsumer cons = session.createConsumer("A");

    ClientMessage msg = cons.receive(CONSUMER_TIMEOUT);

    assertNotNull(msg);

    assertEquals(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, msg.getBodySize());

    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
      assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
    }

    msg.acknowledge();
    session.commit();
  }
コード例 #29
0
  @Test
  public void testJmsConnectionFactoryBinding() throws Exception {
    final String clientId = "myClientId";
    final long clientFailureCheckPeriod = 1;
    final long connectionTTl = 2;
    final long callTimeout = 3;
    final long callFailoverTimeout = 4;
    final boolean cacheLargeMessagesClient = true;
    final int minLargeMessageSize = 5;
    final boolean compressLargeMessages = true;
    final int consumerWindowSize = 6;
    final int consumerMaxRate = 7;
    final int confirmationWindowSize = 8;
    final int producerWindowSize = 9;
    final int producerMaxrate = 10;
    final boolean blockOnAcknowledge = true;
    final boolean blockOnDurableSend = false;
    final boolean blockOnNonDurableSend = true;
    final boolean autoGroup = true;
    final boolean preacknowledge = true;
    final String loadBalancingPolicyClassName = "myPolicy";
    final int transactionBatchSize = 11;
    final int dupsOKBatchSize = 12;
    final boolean useGlobalPools = true;
    final int scheduledThreadPoolMaxSize = 13;
    final int threadPoolMaxSize = 14;
    final long retryInterval = 15;
    final double retryIntervalMultiplier = 10.0;
    final long maxRetryInterval = 16;
    final int reconnectAttempts = 17;
    final boolean failoverOnInitialConnection = true;
    final String groupId = "myGroupId";
    final String name = "myFirstConnectionFactoryName";
    final String jndi_binding1 = name + "Binding1";
    final String jndi_binding2 = name + "Binding2";
    final JMSFactoryType type = JMSFactoryType.CF;
    final boolean ha = true;
    final List connectors = Arrays.asList("in-vm1", "in-vm2");

    ClientSession session = basicSetUp();

    jmsServer.createConnectionFactory(
        name,
        ha,
        type,
        connectors,
        clientId,
        clientFailureCheckPeriod,
        connectionTTl,
        callTimeout,
        callFailoverTimeout,
        cacheLargeMessagesClient,
        minLargeMessageSize,
        compressLargeMessages,
        consumerWindowSize,
        consumerMaxRate,
        confirmationWindowSize,
        producerWindowSize,
        producerMaxrate,
        blockOnAcknowledge,
        blockOnDurableSend,
        blockOnNonDurableSend,
        autoGroup,
        preacknowledge,
        loadBalancingPolicyClassName,
        transactionBatchSize,
        dupsOKBatchSize,
        useGlobalPools,
        scheduledThreadPoolMaxSize,
        threadPoolMaxSize,
        retryInterval,
        retryIntervalMultiplier,
        maxRetryInterval,
        reconnectAttempts,
        failoverOnInitialConnection,
        groupId,
        jndi_binding1,
        jndi_binding2);

    jmsServer.createConnectionFactory(
        "mySecondConnectionFactoryName",
        false,
        JMSFactoryType.CF,
        Arrays.asList("in-vm1", "in-vm2"),
        "mySecondConnectionFactoryName1",
        "mySecondConnectionFactoryName2");

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsLocation().getAbsolutePath(),
        server.getConfiguration().getJournalLocation().getAbsolutePath(),
        server.getConfiguration().getPagingLocation().getAbsolutePath(),
        server.getConfiguration().getLargeMessagesLocation().getAbsolutePath());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);

    ConnectionFactory cf1 = (ConnectionFactory) namingContext.lookup(jndi_binding1);
    assertNotNull(cf1);
    ActiveMQConnectionFactory hcf1 = (ActiveMQConnectionFactory) cf1;
    assertEquals(ha, hcf1.isHA());
    assertEquals(type.intValue(), hcf1.getFactoryType());
    assertEquals(clientId, hcf1.getClientID());
    assertEquals(clientFailureCheckPeriod, hcf1.getClientFailureCheckPeriod());
    assertEquals(connectionTTl, hcf1.getConnectionTTL());
    assertEquals(callTimeout, hcf1.getCallTimeout());
    //      Assert.assertEquals(callFailoverTimeout, hcf1.getCallFailoverTimeout());  // this value
    // isn't currently persisted by
    // org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl.encode()
    //      Assert.assertEquals(cacheLargeMessagesClient, hcf1.isCacheLargeMessagesClient()); //
    // this value isn't currently supported by
    // org.apache.activemq.artemis.api.jms.management.JMSServerControl.createConnectionFactory(java.lang.String, boolean, boolean, int, java.lang.String, java.lang.String, java.lang.String, long, long, long, long, int, boolean, int, int, int, int, int, boolean, boolean, boolean, boolean, boolean, java.lang.String, int, int, boolean, int, int, long, double, long, int, boolean, java.lang.String)
    assertEquals(minLargeMessageSize, hcf1.getMinLargeMessageSize());
    //      Assert.assertEquals(compressLargeMessages, hcf1.isCompressLargeMessage());  // this
    // value isn't currently handled properly by
    // org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl.createConnectionFactory(java.lang.String, boolean, org.apache.activemq.artemis.api.jms.JMSFactoryType, java.util.List<java.lang.String>, java.lang.String, long, long, long, long, boolean, int, boolean, int, int, int, int, int, boolean, boolean, boolean, boolean, boolean, java.lang.String, int, int, boolean, int, int, long, double, long, int, boolean, java.lang.String, java.lang.String...)()
    assertEquals(consumerWindowSize, hcf1.getConsumerWindowSize());
    assertEquals(consumerMaxRate, hcf1.getConsumerMaxRate());
    assertEquals(confirmationWindowSize, hcf1.getConfirmationWindowSize());
    assertEquals(producerWindowSize, hcf1.getProducerWindowSize());
    assertEquals(producerMaxrate, hcf1.getProducerMaxRate());
    assertEquals(blockOnAcknowledge, hcf1.isBlockOnAcknowledge());
    assertEquals(blockOnDurableSend, hcf1.isBlockOnDurableSend());
    assertEquals(blockOnNonDurableSend, hcf1.isBlockOnNonDurableSend());
    assertEquals(autoGroup, hcf1.isAutoGroup());
    assertEquals(preacknowledge, hcf1.isPreAcknowledge());
    assertEquals(loadBalancingPolicyClassName, hcf1.getConnectionLoadBalancingPolicyClassName());
    assertEquals(transactionBatchSize, hcf1.getTransactionBatchSize());
    assertEquals(dupsOKBatchSize, hcf1.getDupsOKBatchSize());
    assertEquals(useGlobalPools, hcf1.isUseGlobalPools());
    assertEquals(scheduledThreadPoolMaxSize, hcf1.getScheduledThreadPoolMaxSize());
    assertEquals(threadPoolMaxSize, hcf1.getThreadPoolMaxSize());
    assertEquals(retryInterval, hcf1.getRetryInterval());
    assertEquals(retryIntervalMultiplier, hcf1.getRetryIntervalMultiplier(), 0);
    assertEquals(maxRetryInterval, hcf1.getMaxRetryInterval());
    assertEquals(reconnectAttempts, hcf1.getReconnectAttempts());
    assertEquals(failoverOnInitialConnection, hcf1.isFailoverOnInitialConnection());
    assertEquals(groupId, hcf1.getGroupID());

    assertNotNull(namingContext.lookup(jndi_binding2));
    assertNotNull(namingContext.lookup("mySecondConnectionFactoryName1"));
    assertNotNull(namingContext.lookup("mySecondConnectionFactoryName2"));
  }
コード例 #30
0
  @Test
  public void testMessageTypes() throws Exception {

    ClientSession session = basicSetUp();

    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);

    ClientProducer producer = session.createProducer(QUEUE_NAME);

    ClientMessage msg = session.createMessage(Message.BYTES_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.DEFAULT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.MAP_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.OBJECT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.STREAM_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.TEXT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(true);
    producer.send(msg);

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();

    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.BYTES_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.DEFAULT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.MAP_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.OBJECT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.STREAM_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.TEXT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.DEFAULT_TYPE, msg.getType());
  }