Ejemplo n.º 1
0
  @Test
  public void failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster()
      throws Throwable {
    // Given
    HighlyAvailableGraphDatabase initialMaster = cluster.getMaster();

    // When
    cluster.shutdown(initialMaster);
    cluster.await(masterAvailable(initialMaster));
    cluster.await(masterSeesSlavesAsAvailable(1));

    // create node on new master to ensure that it has the greatest tx id
    createNodeOn(cluster.getMaster());
    cluster.sync();

    ClusterClient clusterClient = cleanup.add(newClusterClient(new InstanceId(1)));

    final AtomicReference<InstanceId> coordinatorIdWhenReJoined = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    clusterClient.addClusterListener(
        new ClusterListener.Adapter() {
          @Override
          public void enteredCluster(ClusterConfiguration clusterConfiguration) {
            coordinatorIdWhenReJoined.set(clusterConfiguration.getElected(COORDINATOR));
            latch.countDown();
          }
        });

    clusterClient.init();
    clusterClient.start();

    // Then
    latch.await(2, SECONDS);
    assertEquals(new InstanceId(2), coordinatorIdWhenReJoined.get());
  }
Ejemplo n.º 2
0
  @Test
  public void shouldBeAbleToRestartServer() throws Exception {
    // Given
    String dbDirectory1 = baseDir.directory("db1").getAbsolutePath();
    String dbDirectory2 = baseDir.directory("db2").getAbsolutePath();

    ConfigurationBuilder config =
        new PropertyFileConfigurator(
            AdvancedServerBuilder.server().usingDatabaseDir(dbDirectory1).createPropertiesFiles(),
            ConsoleLogger.DEV_NULL);

    // When
    NeoServer server = cleanup.add(new AdvancedNeoServer(config, graphDbDependencies()));
    server.start();

    assertNotNull(server.getDatabase().getGraph());
    assertEquals(dbDirectory1, server.getDatabase().getLocation());

    // Change the database location
    setProperty(config.configuration(), Configurator.DATABASE_LOCATION_PROPERTY_KEY, dbDirectory2);
    ServerManagement bean = new ServerManagement(server);
    bean.restartServer();

    // Then
    assertNotNull(server.getDatabase().getGraph());
    assertEquals(dbDirectory2, server.getDatabase().getLocation());
  }