@Test
 public void testStartBackupFirst() throws Exception {
   for (TestableServer backupServer : backupServers) {
     backupServer.start();
   }
   for (TestableServer liveServer : liveServers) {
     liveServer.start();
   }
   waitForTopology(liveServers.get(0).getServer(), liveServers.size(), liveServers.size());
   sendCrashReceive();
 }
Пример #2
0
 protected final void adaptLiveConfigForReplicatedFailBack(TestableServer server) {
   Configuration configuration = server.getServer().getConfiguration();
   final TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
   if (server.getServer().getHAPolicy().isSharedStore()) {
     ClusterConnectionConfiguration cc = configuration.getClusterConfigurations().get(0);
     Assert.assertNotNull("cluster connection configuration", cc);
     Assert.assertNotNull("static connectors", cc.getStaticConnectors());
     cc.getStaticConnectors().add(backupConnector.getName());
     // backupConnector is only necessary for fail-back tests
     configuration.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
     return;
   }
   ReplicatedPolicy haPolicy = (ReplicatedPolicy) server.getServer().getHAPolicy();
   haPolicy.setCheckForLiveServer(true);
 }
 public void run() {
   try {
     server.start();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #4
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    createConfigs();

    setLiveIdentity();
    liveServer.start();
    waitForServerToStart(liveServer.getServer());

    if (backupServer != null) {
      setBackupIdentity();
      if (startBackupServer) {
        backupServer.start();
        waitForBackup();
      }
    }
  }
Пример #5
0
 /**
  * Waits for backup to be in the "started" state and to finish synchronization with its live.
  *
  * @param sessionFactory
  * @param seconds
  * @throws Exception
  */
 protected void waitForBackup(ClientSessionFactoryInternal sessionFactory, int seconds)
     throws Exception {
   final ActiveMQServerImpl actualServer = (ActiveMQServerImpl) backupServer.getServer();
   if (actualServer.getHAPolicy().isSharedStore()) {
     waitForServerToStart(actualServer);
   } else {
     waitForRemoteBackup(sessionFactory, seconds, true, actualServer);
   }
 }
  protected void sendCrashReceive() throws Exception {
    ServerLocator[] locators = new ServerLocator[liveServers.size()];
    try {
      for (int i = 0; i < locators.length; i++) {
        locators[i] = getServerLocator(i);
      }

      ClientSessionFactory[] factories = new ClientSessionFactory[liveServers.size()];
      for (int i = 0; i < factories.length; i++) {
        factories[i] = createSessionFactory(locators[i]);
      }

      ClientSession[] sessions = new ClientSession[liveServers.size()];
      for (int i = 0; i < factories.length; i++) {
        sessions[i] = createSession(factories[i], true, true);
        sessions[i].createQueue(ADDRESS, ADDRESS, null, true);
      }

      // make sure bindings are ready before sending messages
      for (int i = 0; i < liveServers.size(); i++) {
        this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), true, 1, 0, 2000);
        this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), false, 1, 0, 2000);
      }

      ClientProducer producer = sessions[0].createProducer(ADDRESS);

      for (int i = 0; i < liveServers.size() * 100; i++) {
        ClientMessage message = sessions[0].createMessage(true);

        setBody(i, message);

        message.putIntProperty("counter", i);

        producer.send(message);
      }

      producer.close();

      for (TestableServer liveServer : liveServers) {
        waitForDistribution(ADDRESS, liveServer.getServer(), 100);
      }

      for (TestableServer liveServer : liveServers) {
        liveServer.crash();
      }
      ClientConsumer[] consumers = new ClientConsumer[liveServers.size()];
      for (int i = 0; i < factories.length; i++) {
        consumers[i] = sessions[i].createConsumer(ADDRESS);
        sessions[i].start();
      }

      for (int i = 0; i < 100; i++) {
        for (ClientConsumer consumer : consumers) {
          ClientMessage message = consumer.receive(1000);
          assertNotNull("expecting durable msg " + i, message);
          message.acknowledge();
        }
      }
    } finally {
      for (ServerLocator locator : locators) {
        if (locator != null) {
          try {
            locator.close();
          } catch (Exception e) {
            // ignore
          }
        }
      }
    }
  }
Пример #7
0
 protected void crash(final boolean waitFailure, final ClientSession... sessions)
     throws Exception {
   liveServer.crash(waitFailure, sessions);
 }
Пример #8
0
 protected void crash(final ClientSession... sessions) throws Exception {
   liveServer.crash(sessions);
 }
Пример #9
0
 protected void setLiveIdentity() {
   liveServer.setIdentity(this.getClass().getSimpleName() + "/liveServer");
 }
Пример #10
0
 protected void setBackupIdentity() {
   backupServer.setIdentity(this.getClass().getSimpleName() + "/backupServers");
 }
Пример #11
0
 protected void waitForBackup() {
   waitForRemoteBackupSynchronization(backupServer.getServer());
 }