示例#1
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());
  }
示例#2
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());
  }
  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();
  }