Author: jbellis
Date: Thu Aug  5 02:08:56 2010
New Revision: 982452

URL: http://svn.apache.org/viewvc?rev=982452&view=rev
Log:
flesh out BufferedRandomAccessFileTest.  patch by Jon Hermes; reviewed by Stu 
Hood for CASSANDRA-1269

Modified:
    
cassandra/trunk/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java

Modified: 
cassandra/trunk/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java?rev=982452&r1=982451&r2=982452&view=diff
==============================================================================
--- 
cassandra/trunk/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
 (original)
+++ 
cassandra/trunk/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
 Thu Aug  5 02:08:56 2010
@@ -69,6 +69,30 @@ public class BufferedRandomAccessFileTes
         r.close();
     }
 
+    @Test
+    public void testReadsOnCapacity() throws IOException
+    {
+        File tmpFile = File.createTempFile("readtest", "bin");
+        BufferedRandomAccessFile rw = new BufferedRandomAccessFile(tmpFile, 
"rw");
+
+        // Fully write the file and sync..
+        byte[] in = new byte[BufferedRandomAccessFile.BuffSz_];
+        rw.write(in);
+        rw.sync();
+
+        // Read it into a same size array.
+        byte[] out = new byte[BufferedRandomAccessFile.BuffSz_];
+        rw.read(out);
+
+        // We're really at the end.
+        long rem = rw.bytesRemaining();
+        assert rem == 0 : "BytesRemaining should be 0 but it's " + rem;
+
+        // Cannot read any more.
+        int negone = rw.read();
+        assert negone == -1 : "We read past the end of the file, should have 
gotten EOF -1. Instead, " + negone;
+    }
+
     protected void expectException(int size, int offset, int len, 
BufferedRandomAccessFile braf)
     {
         boolean threw = false;
@@ -110,4 +134,17 @@ public class BufferedRandomAccessFileTes
         return f;
     }
 
+
+    @Test (expected=UnsupportedOperationException.class)
+    public void testOverflowMark() throws IOException
+    {
+        File tmpFile = File.createTempFile("overflowtest", "bin");
+        tmpFile.deleteOnExit();
+        BufferedRandomAccessFile rw = new BufferedRandomAccessFile(tmpFile, 
"rw");
+        FileMark mark = rw.mark();
+        rw.seek(4L*1024L*1024L*1024L*1024L); //seek 4gb
+
+        //Expect this call to fail, because the distance from mark to current 
file pointer > 2gb.
+        int bpm = rw.bytesPastMark(mark);
+    }
 }


Reply via email to