예제 #1
0
  @Before
  public void setup() throws Throwable {
    // setup a cluster with some data and entries in log files in fully functional and shutdown
    // state
    clusterManager.start();

    cluster = clusterManager.getDefaultCluster();
    try {
      cluster.await(allSeesAllAsAvailable());

      master = cluster.getMaster();
      try (Transaction tx = master.beginTx()) {
        master.createNode();
        tx.success();
      }
      cluster.sync();

      slave1 = cluster.getAnySlave();
      slave2 = cluster.getAnySlave(slave1);
    } finally {
      clusterManager.shutdown();
    }

    assertAllStoreConsistent();
  }
예제 #2
0
  @Test
  public void aSlaveWithoutAnyGraphDBFilesShouldBeAbleToJoinACluster() throws Throwable {
    // GIVEN a cluster with some data and entry in log files

    // WHEN removing all the files in graphdb on the slave and restarting the cluster
    deleteAllFilesOn(slave1);

    clusterManager.start();

    // THEN the cluster should work
    cluster = clusterManager.getDefaultCluster();
    try {
      cluster.await(allSeesAllAsAvailable());
    } finally {
      clusterManager.shutdown();
    }

    assertAllStoreConsistent();
  }
예제 #3
0
  @Test
  public void aClusterShouldStartAndRunWhenSeededWithAStoreHavingNoLogicalLogFiles()
      throws Throwable {
    // GIVEN a cluster with some data and entry in log files

    // WHEN removing all logical log files in graphdb on the slave and restarting a new cluster
    File seedDir = deleteAllLogsOn(slave1);

    File newDir = new File(dir.directory(), "new");
    FileUtils.deleteRecursively(newDir);
    ClusterManager newClusterManager =
        new ClusterManager(
            new ClusterManager.Builder(newDir).withProvider(clusterOfSize(3)).withSeedDir(seedDir));

    newClusterManager.start();

    // THEN the new cluster should work
    ClusterManager.ManagedCluster newCluster = newClusterManager.getDefaultCluster();
    HighlyAvailableGraphDatabase newMaster;
    HighlyAvailableGraphDatabase newSlave1;
    HighlyAvailableGraphDatabase newSlave2;
    try {
      newCluster.await(allSeesAllAsAvailable());
      newMaster = newCluster.getMaster();
      newSlave1 = newCluster.getAnySlave();
      newSlave2 = newCluster.getAnySlave(newSlave1);
    } finally {
      newClusterManager.shutdown();
    }

    assertAllStoreConsistent(newMaster, newSlave1, newSlave2);

    assertConsistentStore(new File(newMaster.getStoreDir()));
    assertConsistentStore(new File(newSlave1.getStoreDir()));
    assertConsistentStore(new File(newSlave2.getStoreDir()));
  }
예제 #4
0
 @After
 public void after() throws Throwable {
   clusterManager.shutdown();
 }
예제 #5
0
  @Test
  public void testPullStorm() throws Throwable {
    // given

    ClusterManager clusterManager =
        new ClusterManager(
            ClusterManager.clusterWithAdditionalArbiters(2, 1),
            testDirectory.directory(),
            stringMap(
                HaSettings.pull_interval.name(), "0",
                HaSettings.tx_push_factor.name(), "1"));

    clusterManager.start();

    try {
      ClusterManager.ManagedCluster cluster = clusterManager.getDefaultCluster();
      cluster.await(ClusterManager.masterAvailable());
      cluster.await(ClusterManager.masterSeesSlavesAsAvailable(1));

      // Create data
      final HighlyAvailableGraphDatabase master = cluster.getMaster();
      {
        Transaction tx = master.beginTx();
        for (int i = 0; i < 1000; i++) {
          master.createNode().setProperty("foo", "bar");
        }
        tx.success();
        tx.finish();
      }

      // Slave goes down
      HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
      ClusterManager.RepairKit repairKit = cluster.fail(slave);

      // Create more data
      for (int i = 0; i < 1000; i++) {
        {
          Transaction tx = master.beginTx();
          for (int j = 0; j < 1000; j++) {
            master.createNode().setProperty("foo", "bar");
            master.createNode().setProperty("foo", "bar");
          }
          tx.success();
          tx.finish();
        }
      }

      // Slave comes back online
      repairKit.repair();

      cluster.await(ClusterManager.masterSeesSlavesAsAvailable(1));

      // when

      // Create 20 concurrent transactions
      System.out.println("Pull storm");
      ExecutorService executor = Executors.newFixedThreadPool(20);
      for (int i = 0; i < 20; i++) {
        executor.submit(
            new Runnable() {
              @Override
              public void run() {
                Transaction tx = master.beginTx();
                master.createNode().setProperty("foo", "bar");
                tx.success();
                tx.finish(); // This should cause lots of concurrent calls to pullUpdate()
              }
            });
      }

      executor.shutdown();
      executor.awaitTermination(1, TimeUnit.MINUTES);

      System.out.println("Pull storm done");

      // then

      long masterLastCommittedTxId = lastCommittedTxId(master);
      for (HighlyAvailableGraphDatabase member : cluster.getAllMembers()) {
        assertEquals(masterLastCommittedTxId, lastCommittedTxId(member));
      }
    } finally {
      System.err.println("Shutting down");
      clusterManager.shutdown();
      System.err.println("Shut down");
    }
  }