Ejemplo n.º 1
0
  private boolean dumpRecord(
      STORE store, int size, StoreChannel fileChannel, ByteBuffer buffer, long id)
      throws Exception {
    RECORD record = store.forceGetRecord(id);

    Object transform = transform(record);
    if (transform != null) {
      if (!"".equals(transform)) {
        out.println(transform);
      }
    } else {
      out.print(record);
      buffer.clear();
      fileChannel.read(buffer, id * size);
      buffer.flip();
      if (record.inUse()) {
        dumpHex(buffer, id * size);
      } else if (allZero(buffer)) {
        out.printf(": all zeros @ 0x%x - 0x%x%n", id * size, (id + 1) * size);
      } else {
        dumpHex(buffer, id * size);
      }
    }

    return record.inUse();
  }
Ejemplo n.º 2
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());
      }
    }
  }
 @Override
 public int read(ByteBuffer dst) throws IOException {
   return delegateChannel.read(dst);
 }
 @Override
 public long read(ByteBuffer[] dsts) throws IOException {
   return delegateChannel.read(dsts);
 }
 @Override
 public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
   return delegateChannel.read(dsts, offset, length);
 }