コード例 #1
0
  @Test
  public void testCreateDurableQueueUsingJMXAndRestartServer() throws Exception {
    String queueName = RandomUtil.randomString();
    String binding = RandomUtil.randomString();

    UnitTestCase.checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    JMSServerControl control = ManagementControlHelper.createJMSServerControl(mbeanServer);
    control.createQueue(queueName, binding);

    Object o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    Queue queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager.stop();

    checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager = createJMSServer();
    serverManager.start();

    o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));
  }
コード例 #2
0
  public void testCreateAndDestroyQueueWithEmptyStringForFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    String filter = "";
    boolean durable = true;

    HornetQServerControl serverControl = createManagementControl();

    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));

    serverControl.createQueue(address.toString(), name.toString(), filter, durable);

    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));
    QueueControl queueControl =
        ManagementControlHelper.createQueueControl(address, name, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());

    serverControl.destroyQueue(name.toString());

    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));
  }
コード例 #3
0
  @Test
  public void testCreateDurableQueueUsingJMSAndRestartServer() throws Exception {
    String queueName = RandomUtil.randomString();
    String binding = RandomUtil.randomString();

    UnitTestCase.checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    TransportConfiguration config =
        new TransportConfiguration(InVMConnectorFactory.class.getName());
    Connection connection =
        HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, config)
            .createConnection();
    connection.start();
    Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
    QueueSession session = (QueueSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueRequestor requestor = new QueueRequestor(session, managementQueue);
    Message message = session.createMessage();
    JMSManagementHelper.putOperationInvocation(
        message, "jms.server", "createQueue", queueName, binding);
    Message reply = requestor.request(message);
    assertTrue(JMSManagementHelper.hasOperationSucceeded(reply));
    connection.close();

    Object o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    Queue queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager.stop();

    checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager = createJMSServer();
    serverManager.start();

    o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));
  }
コード例 #4
0
ファイル: HornetNest.java プロジェクト: znepok/activeweb
 private JMSQueueControl getQueueControl(String queue) {
   ObjectName queueName;
   try {
     queueName = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queue);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return MBeanServerInvocationHandler.newProxyInstance(
       ManagementFactory.getPlatformMBeanServer(), queueName, JMSQueueControl.class, false);
 }
コード例 #5
0
  public void testStartStop() throws Exception {
    checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(bridgeConfig.getName()));
    BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);

    // started by the server
    Assert.assertTrue(bridgeControl.isStarted());

    bridgeControl.stop();
    Assert.assertFalse(bridgeControl.isStarted());

    bridgeControl.start();
    Assert.assertTrue(bridgeControl.isStarted());
  }
コード例 #6
0
  public void testAttributes() throws Exception {
    checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(bridgeConfig.getName()));
    BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);

    Assert.assertEquals(bridgeConfig.getName(), bridgeControl.getName());
    Assert.assertEquals(
        bridgeConfig.getDiscoveryGroupName(), bridgeControl.getDiscoveryGroupName());
    Assert.assertEquals(bridgeConfig.getQueueName(), bridgeControl.getQueueName());
    Assert.assertEquals(bridgeConfig.getForwardingAddress(), bridgeControl.getForwardingAddress());
    Assert.assertEquals(bridgeConfig.getFilterString(), bridgeControl.getFilterString());
    Assert.assertEquals(bridgeConfig.getRetryInterval(), bridgeControl.getRetryInterval());
    Assert.assertEquals(
        bridgeConfig.getRetryIntervalMultiplier(), bridgeControl.getRetryIntervalMultiplier());
    Assert.assertEquals(bridgeConfig.getReconnectAttempts(), bridgeControl.getReconnectAttempts());
    Assert.assertEquals(
        bridgeConfig.isUseDuplicateDetection(), bridgeControl.isUseDuplicateDetection());

    String[] connectorPairData = bridgeControl.getStaticConnectors();
    Assert.assertEquals(bridgeConfig.getStaticConnectors().get(0), connectorPairData[0]);

    Assert.assertTrue(bridgeControl.isStarted());
  }
コード例 #7
0
  public void testCreateAndDestroyBridge() throws Exception {
    String name = RandomUtil.randomString();
    String sourceAddress = RandomUtil.randomString();
    String sourceQueue = RandomUtil.randomString();
    String targetAddress = RandomUtil.randomString();
    String targetQueue = RandomUtil.randomString();

    HornetQServerControl serverControl = createManagementControl();

    checkNoResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
    assertEquals(0, serverControl.getBridgeNames().length);

    ServerLocator locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    ClientSessionFactory csf = locator.createSessionFactory();
    ClientSession session = csf.createSession();

    session.createQueue(sourceAddress, sourceQueue);
    session.createQueue(targetAddress, targetQueue);

    serverControl.createBridge(
        name,
        sourceQueue,
        targetAddress,
        null, // forwardingAddress
        null, // filterString
        HornetQClient.DEFAULT_RETRY_INTERVAL,
        HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
        HornetQClient.DEFAULT_RECONNECT_ATTEMPTS,
        false, // duplicateDetection
        1, // confirmationWindowSize
        HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
        connectorConfig.getName(), // liveConnector
        false,
        false,
        null,
        null);

    checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
    String[] bridgeNames = serverControl.getBridgeNames();
    assertEquals(1, bridgeNames.length);
    assertEquals(name, bridgeNames[0]);

    BridgeControl bridgeControl = ManagementControlHelper.createBridgeControl(name, mbeanServer);
    assertEquals(name, bridgeControl.getName());
    assertTrue(bridgeControl.isStarted());

    // check that a message sent to the sourceAddress is put in the tagetQueue
    ClientProducer producer = session.createProducer(sourceAddress);
    ClientMessage message = session.createMessage(false);
    String text = RandomUtil.randomString();
    message.putStringProperty("prop", text);
    producer.send(message);

    session.start();

    ClientConsumer targetConsumer = session.createConsumer(targetQueue);
    message = targetConsumer.receive(5000);
    assertNotNull(message);
    assertEquals(text, message.getStringProperty("prop"));

    ClientConsumer sourceConsumer = session.createConsumer(sourceQueue);
    assertNull(sourceConsumer.receiveImmediate());

    serverControl.destroyBridge(name);

    checkNoResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
    assertEquals(0, serverControl.getBridgeNames().length);

    // check that a message is no longer diverted
    message = session.createMessage(false);
    String text2 = RandomUtil.randomString();
    message.putStringProperty("prop", text2);
    producer.send(message);

    assertNull(targetConsumer.receiveImmediate());
    message = sourceConsumer.receive(5000);
    assertNotNull(message);
    assertEquals(text2, message.getStringProperty("prop"));

    sourceConsumer.close();
    targetConsumer.close();

    session.deleteQueue(sourceQueue);
    session.deleteQueue(targetQueue);

    session.close();

    locator.close();
  }
コード例 #8
0
  public void testCreateAndDestroyDivert() throws Exception {
    String address = RandomUtil.randomString();
    String name = RandomUtil.randomString();
    String routingName = RandomUtil.randomString();
    String forwardingAddress = RandomUtil.randomString();

    HornetQServerControl serverControl = createManagementControl();

    checkNoResource(ObjectNameBuilder.DEFAULT.getDivertObjectName(name));
    assertEquals(0, serverControl.getDivertNames().length);

    serverControl.createDivert(
        name.toString(), routingName, address, forwardingAddress, true, null, null);

    checkResource(ObjectNameBuilder.DEFAULT.getDivertObjectName(name));
    DivertControl divertControl =
        ManagementControlHelper.createDivertControl(name.toString(), mbeanServer);
    assertEquals(name.toString(), divertControl.getUniqueName());
    assertEquals(address, divertControl.getAddress());
    assertEquals(forwardingAddress, divertControl.getForwardingAddress());
    assertEquals(routingName, divertControl.getRoutingName());
    assertTrue(divertControl.isExclusive());
    assertNull(divertControl.getFilter());
    assertNull(divertControl.getTransformerClassName());
    String[] divertNames = serverControl.getDivertNames();
    assertEquals(1, divertNames.length);
    assertEquals(name, divertNames[0]);

    // check that a message sent to the address is diverted exclusively
    ServerLocator locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));

    ClientSessionFactory csf = locator.createSessionFactory();
    ClientSession session = csf.createSession();

    String divertQueue = RandomUtil.randomString();
    String queue = RandomUtil.randomString();
    session.createQueue(forwardingAddress, divertQueue);
    session.createQueue(address, queue);

    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(false);
    String text = RandomUtil.randomString();
    message.putStringProperty("prop", text);
    producer.send(message);

    ClientConsumer consumer = session.createConsumer(queue);
    ClientConsumer divertedConsumer = session.createConsumer(divertQueue);

    session.start();

    assertNull(consumer.receiveImmediate());
    message = divertedConsumer.receive(5000);
    assertNotNull(message);
    assertEquals(text, message.getStringProperty("prop"));

    serverControl.destroyDivert(name.toString());

    checkNoResource(ObjectNameBuilder.DEFAULT.getDivertObjectName(name));
    assertEquals(0, serverControl.getDivertNames().length);

    // check that a message is no longer diverted
    message = session.createMessage(false);
    String text2 = RandomUtil.randomString();
    message.putStringProperty("prop", text2);
    producer.send(message);

    assertNull(divertedConsumer.receiveImmediate());
    message = consumer.receive(5000);
    assertNotNull(message);
    assertEquals(text2, message.getStringProperty("prop"));

    consumer.close();
    divertedConsumer.close();
    session.deleteQueue(queue);
    session.deleteQueue(divertQueue);
    session.close();

    locator.close();
  }