cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r982829 - /cassandra/trunk/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
Date Thu, 05 Aug 2010 23:31:01 GMT
Author: jbellis
Date: Thu Aug  5 23:31:00 2010
New Revision: 982829

URL: http://svn.apache.org/viewvc?rev=982829&view=rev
Log:
improve BufferedRandomAccessFileTest coverage to 100% of lines.  patch by Jon Hermes; reviewed
by jbellis 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=982829&r1=982828&r2=982829&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 23:31:00 2010
@@ -70,7 +70,7 @@ public class BufferedRandomAccessFileTes
     }
 
     @Test
-    public void testReadsOnCapacity() throws IOException
+    public void testReadsAndWriteOnCapacity() throws IOException
     {
         File tmpFile = File.createTempFile("readtest", "bin");
         BufferedRandomAccessFile rw = new BufferedRandomAccessFile(tmpFile, "rw");
@@ -78,7 +78,6 @@ public class BufferedRandomAccessFileTes
         // 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_];
@@ -86,11 +85,17 @@ public class BufferedRandomAccessFileTes
 
         // We're really at the end.
         long rem = rw.bytesRemaining();
+        assert rw.isEOF();
         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;
+
+        // Writing will succeed
+        rw.write(new byte[BufferedRandomAccessFile.BuffSz_]);
+        // Forcing a rebuffer here
+        rw.write(42);
     }
 
     protected void expectException(int size, int offset, int len, BufferedRandomAccessFile
braf)
@@ -140,11 +145,22 @@ public class BufferedRandomAccessFileTes
     {
         File tmpFile = File.createTempFile("overflowtest", "bin");
         tmpFile.deleteOnExit();
-        BufferedRandomAccessFile rw = new BufferedRandomAccessFile(tmpFile, "rw");
+
+        // Create the BRAF by filename instead of by file.
+        BufferedRandomAccessFile rw = new BufferedRandomAccessFile(tmpFile.getPath(), "rw");
+        assert tmpFile.getPath().equals(rw.getPath());
+
+        // Create a mark and move the rw there.
         FileMark mark = rw.mark();
-        rw.seek(4L*1024L*1024L*1024L*1024L); //seek 4gb
+        rw.reset(mark);
 
-        //Expect this call to fail, because the distance from mark to current file pointer
> 2gb.
+        // Expect this call to succeed.
         int bpm = rw.bytesPastMark(mark);
+
+        // Seek 4gb
+        rw.seek(4L*1024L*1024L*1024L*1024L);
+        
+        // Expect this call to fail -- the distance from mark to current file pointer >
2gb.
+        bpm = rw.bytesPastMark(mark);
     }
 }



Mime
View raw message