示例#1
0
  @Test
  public void testIsolatedClusters() throws Exception {

    HornetQServer server1 = createServer1();

    HornetQServer server2 = createServer2();

    server1.start();
    server2.start();

    waitForTopology(server1, "cc1", 2, 5000);

    waitForTopology(server1, "cc2", 2, 5000);

    waitForTopology(server2, "cc1", 2, 5000);

    waitForTopology(server2, "cc2", 2, 5000);

    String node1 = server1.getNodeID().toString();
    String node2 = server2.getNodeID().toString();

    checkTopology(
        server1,
        "cc1",
        node1,
        node2,
        createInVMTransportConnectorConfig(1, "srv1"),
        createInVMTransportConnectorConfig(3, "srv1"));

    checkTopology(
        server2,
        "cc1",
        node1,
        node2,
        createInVMTransportConnectorConfig(1, "srv1"),
        createInVMTransportConnectorConfig(3, "srv1"));

    checkTopology(
        server1,
        "cc2",
        node1,
        node2,
        createInVMTransportConnectorConfig(2, "srv1"),
        createInVMTransportConnectorConfig(4, "srv1"));

    checkTopology(
        server2,
        "cc2",
        node1,
        node2,
        createInVMTransportConnectorConfig(2, "srv1"),
        createInVMTransportConnectorConfig(4, "srv1"));
    Thread.sleep(500);
  }
示例#2
0
  /**
   * This would force a journal duplication on bindings even with the scenario that generated fixed,
   * the server shouldn't hold of from starting
   *
   * @throws Exception
   */
  @Test
  public void testForceDuplicationOnBindings() throws Exception {
    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

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

    ClientProducer producer = session.createProducer(QUEUE);

    producer.send(session.createMessage(true));
    session.commit();

    long queueID = server.getStorageManager().generateUniqueID();
    long txID = server.getStorageManager().generateUniqueID();

    // Forcing a situation where the server would unexpectedly create a duplicated queue. The server
    // should still start normally
    LocalQueueBinding newBinding =
        new LocalQueueBinding(
            QUEUE,
            new QueueImpl(queueID, QUEUE, QUEUE, null, true, false, null, null, null, null, null),
            server.getNodeID());
    server.getStorageManager().addQueueBinding(txID, newBinding);
    server.getStorageManager().commitBindings(txID);

    server.stop();

    // a duplicate binding would impede the server from starting
    server.start();
    waitForServer(server);

    server.stop();
  }
  public ConnectionEntry createConnectionEntry(
      final Acceptor acceptorUsed, final Connection connection) {
    final Configuration config = server.getConfiguration();

    Executor connectionExecutor = server.getExecutorFactory().getExecutor();

    final CoreRemotingConnection rc =
        new RemotingConnectionImpl(
            connection,
            interceptors,
            config.isAsyncConnectionExecutionEnabled() ? connectionExecutor : null,
            server.getNodeID());

    Channel channel1 = rc.getChannel(CHANNEL_ID.SESSION.id, -1);

    ChannelHandler handler = new HornetQPacketHandler(this, server, channel1, rc);

    channel1.setHandler(handler);

    long ttl = HornetQClient.DEFAULT_CONNECTION_TTL;

    if (config.getConnectionTTLOverride() != -1) {
      ttl = config.getConnectionTTLOverride();
    }

    final ConnectionEntry entry =
        new ConnectionEntry(rc, connectionExecutor, System.currentTimeMillis(), ttl);

    final Channel channel0 = rc.getChannel(0, -1);

    channel0.setHandler(new LocalChannelHandler(config, entry, channel0, acceptorUsed, rc));

    return entry;
  }
示例#4
0
  public synchronized void informClusterOfBackup() {
    String nodeID = server.getNodeID().toString();

    TopologyMemberImpl localMember = new TopologyMemberImpl(nodeID, null, null, connector);

    topology.updateAsLive(nodeID, localMember);
  }
  @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();
    }
  }
  @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();
    }
  }