コード例 #1
0
  private void checkTopology(
      final HornetQServer serverParameter,
      final String clusterName,
      final String nodeId1,
      final String nodeId2,
      final TransportConfiguration cfg1,
      final TransportConfiguration cfg2) {
    Topology topology =
        serverParameter.getClusterManager().getClusterConnection(clusterName).getTopology();

    TopologyMemberImpl member1 = topology.getMember(nodeId1);
    TopologyMemberImpl member2 = topology.getMember(nodeId2);
    Assert.assertEquals(member1.getLive().getParams().toString(), cfg1.getParams().toString());
    Assert.assertEquals(member2.getLive().getParams().toString(), cfg2.getParams().toString());
  }
コード例 #2
0
  @Test
  public void testSimpleDistributionBackupStrategyFull() throws Exception {
    HornetQServer server0 = createServer(0, 1, BackupStrategy.FULL);
    HornetQServer server1 = createServer(1, 0, BackupStrategy.FULL);
    TransportConfiguration liveConnector0 =
        getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 =
        getConnectorTransportConfiguration("liveConnector" + 1, 1);

    try (ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(liveConnector0)) {
      server0.start();
      server1.start();
      ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
      waitForRemoteBackup(sessionFactory0, 10);
      ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
      waitForRemoteBackup(sessionFactory1, 10);
      Topology topology = serverLocator.getTopology();
      Collection<TopologyMemberImpl> members = topology.getMembers();
      assertEquals(members.size(), 2);
      Map<String, HornetQServer> backupServers0 =
          server0.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers0.size(), 1);
      Map<String, HornetQServer> backupServers1 =
          server1.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers1.size(), 1);
      HornetQServer backupServer0 = backupServers0.values().iterator().next();
      HornetQServer backupServer1 = backupServers1.values().iterator().next();
      waitForRemoteBackupSynchronization(backupServer0);
      waitForRemoteBackupSynchronization(backupServer1);
      assertEquals(server0.getNodeID(), backupServer1.getNodeID());
      assertEquals(server1.getNodeID(), backupServer0.getNodeID());
      Set<TransportConfiguration> backupAcceptors0 =
          backupServer0.getConfiguration().getAcceptorConfigurations();
      assertEquals(1, backupAcceptors0.size());
      assertEquals("5545", backupAcceptors0.iterator().next().getParams().get("port"));
      Set<TransportConfiguration> backupAcceptors1 =
          backupServer1.getConfiguration().getAcceptorConfigurations();
      assertEquals(1, backupAcceptors1.size());
      assertEquals("5546", backupAcceptors1.iterator().next().getParams().get("port"));
      Map<String, TransportConfiguration> connectorConfigurations0 =
          backupServer0.getConfiguration().getConnectorConfigurations();
      assertEquals(2, connectorConfigurations0.size());
      assertEquals("5545", connectorConfigurations0.get("liveConnector0").getParams().get("port"));
      assertEquals(
          "5446", connectorConfigurations0.get("remoteConnector0").getParams().get("port"));
      Map<String, TransportConfiguration> connectorConfigurations1 =
          backupServer1.getConfiguration().getConnectorConfigurations();
      assertEquals(2, connectorConfigurations1.size());
      assertEquals("5546", connectorConfigurations1.get("liveConnector1").getParams().get("port"));
      assertEquals(
          "5445", connectorConfigurations1.get("remoteConnector1").getParams().get("port"));
      if (policyType == HAPolicy.POLICY_TYPE.COLOCATED_SHARED_STORE) {
        assertEquals(
            server0.getConfiguration().getJournalDirectory(),
            backupServer1.getConfiguration().getJournalDirectory());
        assertEquals(
            server0.getConfiguration().getBindingsDirectory(),
            backupServer1.getConfiguration().getBindingsDirectory());
        assertEquals(
            server0.getConfiguration().getLargeMessagesDirectory(),
            backupServer1.getConfiguration().getLargeMessagesDirectory());
        assertEquals(
            server0.getConfiguration().getPagingDirectory(),
            backupServer1.getConfiguration().getPagingDirectory());
        assertEquals(
            server1.getConfiguration().getJournalDirectory(),
            backupServer0.getConfiguration().getJournalDirectory());
        assertEquals(
            server1.getConfiguration().getBindingsDirectory(),
            backupServer0.getConfiguration().getBindingsDirectory());
        assertEquals(
            server1.getConfiguration().getLargeMessagesDirectory(),
            backupServer0.getConfiguration().getLargeMessagesDirectory());
        assertEquals(
            server1.getConfiguration().getPagingDirectory(),
            backupServer0.getConfiguration().getPagingDirectory());
      } else {
        assertNotEquals(
            server0.getConfiguration().getJournalDirectory(),
            backupServer1.getConfiguration().getJournalDirectory());
        assertNotEquals(
            server0.getConfiguration().getBindingsDirectory(),
            backupServer1.getConfiguration().getBindingsDirectory());
        assertNotEquals(
            server0.getConfiguration().getLargeMessagesDirectory(),
            backupServer1.getConfiguration().getLargeMessagesDirectory());
        assertNotEquals(
            server0.getConfiguration().getPagingDirectory(),
            backupServer1.getConfiguration().getPagingDirectory());
        assertNotEquals(
            server1.getConfiguration().getJournalDirectory(),
            backupServer0.getConfiguration().getJournalDirectory());
        assertNotEquals(
            server1.getConfiguration().getBindingsDirectory(),
            backupServer0.getConfiguration().getBindingsDirectory());
        assertNotEquals(
            server1.getConfiguration().getLargeMessagesDirectory(),
            backupServer0.getConfiguration().getLargeMessagesDirectory());
        assertNotEquals(
            server1.getConfiguration().getPagingDirectory(),
            backupServer0.getConfiguration().getPagingDirectory());
      }
    } finally {
      server0.stop();
      server1.stop();
    }
  }
コード例 #3
0
  @Test
  public void testSimpleDistributionOfBackupsMaxBackupsExceeded() throws Exception {
    HornetQServer server0 = createServer(0, 1, BackupStrategy.FULL);
    HornetQServer server1 = createServer(1, 0, BackupStrategy.FULL);
    HornetQServer server2 = createServer(2, 0, BackupStrategy.FULL);
    HornetQServer server3 = createServer(3, 0, BackupStrategy.FULL);
    TransportConfiguration liveConnector0 =
        getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 =
        getConnectorTransportConfiguration("liveConnector" + 1, 1);
    TransportConfiguration liveConnector2 =
        getConnectorTransportConfiguration("liveConnector" + 2, 2);
    TransportConfiguration liveConnector3 =
        getConnectorTransportConfiguration("liveConnector" + 3, 3);

    try (ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(liveConnector0)) {
      server0.start();
      server1.start();
      ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
      waitForRemoteBackup(sessionFactory0, 10);
      ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
      waitForRemoteBackup(sessionFactory1, 10);
      Topology topology = serverLocator.getTopology();
      Collection<TopologyMemberImpl> members = topology.getMembers();
      assertEquals(members.size(), 2);
      Map<String, HornetQServer> backupServers0 =
          server0.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers0.size(), 1);
      Map<String, HornetQServer> backupServers1 =
          server1.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers1.size(), 1);
      HornetQServer backupServer0 = backupServers0.values().iterator().next();
      HornetQServer backupServer1 = backupServers1.values().iterator().next();
      waitForRemoteBackupSynchronization(backupServer0);
      waitForRemoteBackupSynchronization(backupServer1);
      assertEquals(server0.getNodeID(), backupServer1.getNodeID());
      assertEquals(server1.getNodeID(), backupServer0.getNodeID());
      server2.start();
      // just give server2 time to try both server 0 and 1
      ClientSessionFactory sessionFactory2 = serverLocator.createSessionFactory(liveConnector2);
      server3.start();
      ClientSessionFactory sessionFactory3 = serverLocator.createSessionFactory(liveConnector3);
      waitForRemoteBackup(sessionFactory2, 10);
      waitForRemoteBackup(sessionFactory3, 10);
      assertEquals(members.size(), 2);
      Map<String, HornetQServer> backupServers2 =
          server2.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers2.size(), 1);
      Map<String, HornetQServer> backupServers3 =
          server3.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers3.size(), 1);
      HornetQServer backupServer2 = backupServers2.values().iterator().next();
      HornetQServer backupServer3 = backupServers3.values().iterator().next();
      waitForRemoteBackupSynchronization(backupServer2);
      waitForRemoteBackupSynchronization(backupServer3);
      assertEquals(server0.getNodeID(), backupServer1.getNodeID());
      assertEquals(server1.getNodeID(), backupServer0.getNodeID());
      assertEquals(server2.getNodeID(), backupServer3.getNodeID());
      assertEquals(server3.getNodeID(), backupServer2.getNodeID());
    } finally {
      server0.stop();
      server1.stop();
      server2.stop();
      server3.stop();
    }
  }
コード例 #4
0
  @Test
  public void testStartStop() throws Exception {
    Map<String, Object> server0Params = new HashMap<String, Object>();
    HornetQServer server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);

    Map<String, Object> server1Params = new HashMap<String, Object>();
    if (isNetty()) {
      server1Params.put(
          "port", org.hornetq.core.remoting.impl.netty.TransportConstants.DEFAULT_PORT + 1);
    } else {
      server1Params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    }
    HornetQServer server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    ServerLocator locator = null;
    try {
      final String testAddress = "testAddress";
      final String queueName0 = "queue0";
      final String forwardAddress = "forwardAddress";
      final String queueName1 = "queue1";

      Map<String, TransportConfiguration> connectors =
          new HashMap<String, TransportConfiguration>();
      TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
      TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
      connectors.put(server1tc.getName(), server1tc);

      server0.getConfiguration().setConnectorConfigurations(connectors);

      ArrayList<String> staticConnectors = new ArrayList<String>();
      staticConnectors.add(server1tc.getName());

      final String bridgeName = "bridge1";

      BridgeConfiguration bridgeConfiguration =
          new BridgeConfiguration()
              .setName(bridgeName)
              .setQueueName(queueName0)
              .setForwardingAddress(forwardAddress)
              .setRetryInterval(1000)
              .setReconnectAttempts(0)
              .setReconnectAttemptsOnSameNode(0)
              .setConfirmationWindowSize(1024)
              .setStaticConnectors(staticConnectors);

      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
      bridgeConfigs.add(bridgeConfiguration);
      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);

      CoreQueueConfiguration queueConfig0 =
          new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
      List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs0.add(queueConfig0);
      server0.getConfiguration().setQueueConfigurations(queueConfigs0);

      CoreQueueConfiguration queueConfig1 =
          new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
      List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs1.add(queueConfig1);
      server1.getConfiguration().setQueueConfigurations(queueConfigs1);

      server1.start();
      waitForServer(server1);

      server0.start();
      waitForServer(server0);

      locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
      ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);

      ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);

      ClientSession session0 = sf0.createSession(false, true, true);

      ClientSession session1 = sf1.createSession(false, true, true);

      ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));

      ClientConsumer consumer1 = session1.createConsumer(queueName1);

      session1.start();

      final int numMessages = 10;

      final SimpleString propKey = new SimpleString("testkey");

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

        message.putIntProperty(propKey, i);

        producer0.send(message);
      }

      for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);

        Assert.assertNotNull(message);

        Assert.assertEquals(i, message.getObjectProperty(propKey));

        message.acknowledge();
      }

      Assert.assertNull(consumer1.receiveImmediate());

      Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);

      bridge.stop();

      bridge.flushExecutor();

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

        message.putIntProperty(propKey, i);

        producer0.send(message);
      }

      Assert.assertNull(consumer1.receiveImmediate());

      bridge.start();

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

        Assert.assertNotNull(message);

        Assert.assertEquals(i, message.getObjectProperty(propKey));

        message.acknowledge();
      }

      Assert.assertNull(consumer1.receiveImmediate());

      session0.close();

      session1.close();

      sf0.close();

      sf1.close();
    } finally {
      if (locator != null) {
        locator.close();
      }

      server0.stop();

      server1.stop();
    }
  }