You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by mo...@apache.org on 2009/10/27 18:04:26 UTC
svn commit: r830273 -
/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/test/java/org/apache/kato/jvmti/util/CachedRandomAccessFileTest.java
Author: monteith
Date: Tue Oct 27 18:04:26 2009
New Revision: 830273
URL: http://svn.apache.org/viewvc?rev=830273&view=rev
Log:
Add more tests.
Modified:
incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/test/java/org/apache/kato/jvmti/util/CachedRandomAccessFileTest.java
Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/test/java/org/apache/kato/jvmti/util/CachedRandomAccessFileTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/test/java/org/apache/kato/jvmti/util/CachedRandomAccessFileTest.java?rev=830273&r1=830272&r2=830273&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/test/java/org/apache/kato/jvmti/util/CachedRandomAccessFileTest.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/test/java/org/apache/kato/jvmti/util/CachedRandomAccessFileTest.java Tue Oct 27 18:04:26 2009
@@ -13,6 +13,7 @@
******************************************************************************/
package org.apache.kato.jvmti.util;
+import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -29,7 +30,10 @@
CachedRandomAccessFile craf;
File file;
- final static int FILE_SIZE = 93;
+
+ final static int FILE_SIZE = 187; // Should not be a power of two and must be >127 for tests to work with signed bytes.
+ final static int BIG_FILESIZE = 1049576; // about 4MB
+
protected void setUp() throws Exception {
super.setUp();
@@ -90,7 +94,7 @@
craf.read(bytes);
for (int i=0; i < FILE_SIZE-1; i++) {
- assertEquals("Bytes read don't match.", i, bytes[i]);
+ assertEquals("Bytes read don't match.", i, bytes[i] & 0xff);
}
craf.close();
@@ -114,7 +118,7 @@
assertEquals("First portion of array not zeros.", 0, bytes[i]);
}
for (int i=0; i < FILE_SIZE-1; i++) {
- assertEquals("Bytes read don't match.", i, bytes[i+offset]);
+ assertEquals("Bytes read don't match.", i, bytes[i+offset] & 0xff);
}
for (int i = offset+FILE_SIZE; i < bytes.length; i++) {
assertEquals("End portion of array not zeros.", 0, bytes[i]);
@@ -136,7 +140,7 @@
craf.read(bytes);
for (int i=0; i < FILE_SIZE-1; i++) {
- assertEquals("Bytes read don't match.", i, bytes[i]);
+ assertEquals("Bytes read don't match.", i, bytes[i] & 0xff);
}
craf.close();
@@ -160,7 +164,7 @@
assertEquals("First portion of array not zeros.", 0, bytes[i]);
}
for (int i=0; i < FILE_SIZE-1; i++) {
- assertEquals("Bytes read don't match.", i, bytes[i+offset]);
+ assertEquals("Bytes read don't match.", i, bytes[i+offset] & 0xff);
}
for (int i = offset+FILE_SIZE; i < bytes.length; i++) {
assertEquals("End portion of array not zeros.", 0, bytes[i]);
@@ -574,7 +578,7 @@
// Check that the bytes that should have been read are read.
for(int i=0; i<offset; i++) {
- assertEquals("Bytes read did not match",FILE_SIZE-offset+i, array[i]);
+ assertEquals("Bytes read did not match",FILE_SIZE-offset+i, array[i] & 0xff);
}
// check that the part of the array that could not be read is
@@ -693,6 +697,55 @@
craf.close();
}
+ /**
+ * Test a big file that will overflow the cache.
+ * Previous tests won't cause cache
+ *
+ * @throws Exception
+ */
+ public void testBigFileSmallCache() throws Exception {
+ File bigfile = File.createTempFile("CachedRandomAccessFileTest", "testfile");
+ RandomAccessFile raf = new RandomAccessFile(bigfile,"rw");
+
+ for(int i=0; i < BIG_FILESIZE; i++) {
+ raf.writeInt(i);
+ }
+
+ raf.close();
+
+ craf = new CachedRandomAccessFile(bigfile, 12,1);
+
+ for (int i = 0; i < BIG_FILESIZE; i++) {
+ int value = craf.readInt();
+
+ assertEquals("Int values did not match",i, value);
+ }
+
+ craf.close();
+
+ bigfile.delete();
+ }
+
+ /**
+ * Test that reading a long will produce an EOFException if it occurs
+ * at the end of the file.
+ *
+ * @throws Exception
+ */
+ public void testReadLongEOF() throws Exception {
+ craf = new CachedRandomAccessFile(file, 4, 1);
+
+ craf.seek(FILE_SIZE-2);
+
+ try {
+ long value = craf.readLong();
+ fail("Expected EOFException not thrown by readLong. Got 0x"+Long.toHexString(value));
+ } catch (EOFException e) {
+ // Expected
+ }
+
+ craf.close();
+ }
/*