Exemple #1
0
  @Test
  public void shouldRenameFiles() throws IOException {
    // given
    final EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    fs.mkdirs(storeDir);
    final File unrelated = new File(storeDir, "unrelated");
    final List<File> files =
        Arrays.asList(
            new File(storeDir, "active_tx_log"),
            new File(storeDir, "tm_tx_log.v0"),
            new File(storeDir, "tm_tx_log.v1"),
            new File(storeDir, "nioneo_logical.log.1"),
            new File(storeDir, "nioneo_logical.log.2"),
            new File(storeDir, getLegacyLogFilename(1)),
            new File(storeDir, getLegacyLogFilename(2)),
            unrelated);

    for (File file : files) {
      fs.create(file).close();
    }

    // when
    new LegacyLogs(fs, reader, writer).renameLogFiles(storeDir);

    // then
    final Set<File> expected =
        new HashSet<>(
            Arrays.asList(
                unrelated,
                new File(storeDir, getLogFilenameForVersion(1)),
                new File(storeDir, getLogFilenameForVersion(2))));
    assertEquals(expected, new HashSet<>(Arrays.asList(fs.listFiles(storeDir))));
  }
 private EphemeralFileSystemAbstraction produceUncleanStore(
     EphemeralFileSystemAbstraction fileSystem, String storeDir) {
   GraphDatabaseService db =
       new TestGraphDatabaseFactory().setFileSystem(fileSystem).newImpermanentDatabase(storeDir);
   Transaction tx = db.beginTx();
   Node node = db.createNode();
   node.setProperty("name", "Something");
   properties((GraphDatabaseAPI) db).setProperty("prop", "Some value");
   tx.success();
   tx.finish();
   EphemeralFileSystemAbstraction snapshot = fileSystem.snapshot();
   db.shutdown();
   return snapshot;
 }
Exemple #3
0
  @Test
  public void shouldMoveFiles() throws IOException {
    // given
    final EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    fs.mkdirs(storeDir);
    fs.mkdirs(migrationDir);

    final Set<File> logsInStoreDir =
        new HashSet<>(
            Arrays.asList(
                new File(storeDir, getLegacyLogFilename(1)),
                new File(storeDir, getLegacyLogFilename(2))));

    final List<File> logsInMigrationDir =
        Arrays.asList(
            new File(migrationDir, getLegacyLogFilename(1)),
            new File(migrationDir, getLegacyLogFilename(2)));

    for (File file : logsInMigrationDir) {
      try (StoreChannel channel = fs.create(file)) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(42);
        buffer.flip();
        channel.write(buffer);
      }
    }

    // should override older files
    for (File file : logsInStoreDir) {
      try (StoreChannel channel = fs.create(file)) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(13);
        buffer.flip();
        channel.write(buffer);
      }
    }

    // when
    new LegacyLogs(fs, reader, writer).operate(FileOperation.MOVE, migrationDir, storeDir);

    // then
    assertEquals(logsInStoreDir, new HashSet<>(Arrays.asList(fs.listFiles(storeDir))));
    for (File file : logsInStoreDir) {
      try (StoreChannel channel = fs.open(file, "r")) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        channel.read(buffer);
        buffer.flip();
        assertEquals(42, buffer.getLong());
      }
    }
  }