Exemplo n.º 1
0
 public void testReadLoop() throws Exception {
   WritableGridFileChannel wgfc = fs.getWritableChannel("/readTest.txt", false, 100);
   try {
     assertTrue(wgfc.isOpen());
     wgfc.write(ByteBuffer.wrap("This tests read loop.".getBytes()));
   } finally {
     wgfc.close();
   }
   ReadableGridFileChannel rgfc = fs.getReadableChannel("/readTest.txt");
   try {
     assertTrue(
         "This tests read loop.".equals(new String(toBytes(Channels.newInputStream(rgfc)))));
   } finally {
     rgfc.close();
   }
 }
Exemplo n.º 2
0
  public void testReadableChannel() throws Exception {
    String content = "This is the content of channelTest.txt";
    writeToFile("/channelTest.txt", content, 10);

    ReadableGridFileChannel channel = fs.getReadableChannel("/channelTest.txt");
    try {
      assertTrue(channel.isOpen());
      ByteBuffer buffer = ByteBuffer.allocate(1000);
      channel.read(buffer);
      assertEquals(getStringFrom(buffer), content);
    } finally {
      channel.close();
    }

    assertFalse(channel.isOpen());
  }
Exemplo n.º 3
0
  public void testReadableChannelPosition() throws Exception {
    writeToFile("/position.txt", "0123456789", 3);

    ReadableGridFileChannel channel = fs.getReadableChannel("/position.txt");
    try {
      assertEquals(channel.position(), 0);

      channel.position(5);
      assertEquals(channel.position(), 5);
      assertEquals(getStringFromChannel(channel, 3), "567");
      assertEquals(channel.position(), 8);

      channel.position(2);
      assertEquals(channel.position(), 2);
      assertEquals(getStringFromChannel(channel, 5), "23456");
      assertEquals(channel.position(), 7);
    } finally {
      channel.close();
    }
  }