Example usage for org.apache.cassandra.io.util RandomAccessReader mark

List of usage examples for org.apache.cassandra.io.util RandomAccessReader mark

Introduction

In this page you can find the example usage for org.apache.cassandra.io.util RandomAccessReader mark.

Prototype

public DataPosition mark() 

Source Link

Usage

From source file:com.fullcontact.cassandra.io.util.BufferedRandomAccessFileTest.java

License:Apache License

@Test
public void testBytesPastMark() throws IOException {
    File tmpFile = File.createTempFile("overflowtest", "bin");
    tmpFile.deleteOnExit();/*  w w  w. j  a  va2s  .c o m*/

    // Create the BRAF by filename instead of by file.
    final RandomAccessReader r = RandomAccessReader.open(new Path(new File(tmpFile.getPath()).getPath()), fs);
    assert tmpFile.getPath().equals(r.getPath());

    // Create a mark and move the rw there.
    final FileMark mark = r.mark();
    r.reset(mark);

    // Expect this call to succeed.
    r.bytesPastMark(mark);
}

From source file:com.fullcontact.cassandra.io.util.BufferedRandomAccessFileTest.java

License:Apache License

@Test
public void testMarkAndReset() throws IOException {
    SequentialWriter w = createTempFile("brafTestMark");
    w.write(new byte[30]);

    w.close();//  www.j a  v  a2s. c  o m

    RandomAccessReader file = RandomAccessReader.open(w, fs);

    file.seek(10);
    FileMark mark = file.mark();

    file.seek(file.length());
    assertTrue(file.isEOF());

    file.reset();
    assertEquals(file.bytesRemaining(), 20);

    file.seek(file.length());
    assertTrue(file.isEOF());

    file.reset(mark);
    assertEquals(file.bytesRemaining(), 20);

    file.seek(file.length());
    assertEquals(file.bytesPastMark(), 20);
    assertEquals(file.bytesPastMark(mark), 20);

    file.reset(mark);
    assertEquals(file.bytesPastMark(), 0);

    file.close();
}

From source file:com.fullcontact.cassandra.io.util.BufferedRandomAccessFileTest.java

License:Apache License

@Test(expected = AssertionError.class)
public void testAssertionErrorWhenBytesPastMarkIsNegative() throws IOException {
    SequentialWriter w = createTempFile("brafAssertionErrorWhenBytesPastMarkIsNegative");
    w.write(new byte[30]);
    w.close();/*from   w  w  w.  j a va  2s.  c om*/

    RandomAccessReader r = RandomAccessReader.open(w, fs);
    r.seek(10);
    r.mark();

    r.seek(0);
    r.bytesPastMark();
}