use of org.h2.test.unit.TestFile in project h2database by h2database.
the class TestFile method doTest.
private void doTest(boolean nioMem, boolean compress) {
int len = getSize(1000, 10000);
Random random = new Random();
FileStore mem = null, file = null;
byte[] buffMem = null;
byte[] buffFile = null;
String prefix = nioMem ? (compress ? "nioMemLZF:" : "nioMemFS:") : (compress ? "memLZF:" : "memFS:");
FileUtils.delete(prefix + "test");
FileUtils.delete("~/testFile");
for (int i = 0; i < len; i++) {
if (buffMem == null) {
int l = 1 + random.nextInt(1000);
buffMem = new byte[l];
buffFile = new byte[l];
}
if (file == null) {
mem = FileStore.open(this, prefix + "test", "rw");
file = FileStore.open(this, "~/testFile", "rw");
}
assertEquals(file.getFilePointer(), mem.getFilePointer());
assertEquals(file.length(), mem.length());
int x = random.nextInt(100);
if ((x -= 20) < 0) {
if (file.length() > 0) {
long pos = random.nextInt((int) (file.length() / 16)) * 16;
trace("seek " + pos);
mem.seek(pos);
file.seek(pos);
}
} else if ((x -= 20) < 0) {
trace("close");
mem.close();
file.close();
mem = null;
file = null;
} else if ((x -= 20) < 0) {
if (buffFile.length > 16) {
random.nextBytes(buffFile);
System.arraycopy(buffFile, 0, buffMem, 0, buffFile.length);
int off = random.nextInt(buffFile.length - 16);
int l = random.nextInt((buffFile.length - off) / 16) * 16;
trace("write " + off + " " + l);
mem.write(buffMem, off, l);
file.write(buffFile, off, l);
}
} else if ((x -= 20) < 0) {
if (buffFile.length > 16) {
int off = random.nextInt(buffFile.length - 16);
int l = random.nextInt((buffFile.length - off) / 16) * 16;
l = (int) Math.min(l, file.length() - file.getFilePointer());
trace("read " + off + " " + l);
Exception a = null, b = null;
try {
file.readFully(buffFile, off, l);
} catch (Exception e) {
a = e;
}
try {
mem.readFully(buffMem, off, l);
} catch (Exception e) {
b = e;
}
if (a != b) {
if (a == null || b == null) {
fail("only one threw an exception");
}
}
assertEquals(buffMem, buffFile);
}
} else if ((x -= 10) < 0) {
trace("reset buffers");
buffMem = null;
buffFile = null;
} else {
int l = random.nextInt(10000) * 16;
long p = file.getFilePointer();
file.setLength(l);
mem.setLength(l);
trace("setLength " + l);
if (p > l) {
file.seek(l);
mem.seek(l);
}
}
}
if (mem != null) {
mem.close();
file.close();
}
FileUtils.delete(prefix + "test");
FileUtils.delete("~/testFile");
}
use of org.h2.test.unit.TestFile in project h2database by h2database.
the class TestAll method testUnit.
private void testUnit() {
// mv store
addTest(new TestCacheConcurrentLIRS());
addTest(new TestCacheLIRS());
addTest(new TestCacheLongKeyLIRS());
addTest(new TestConcurrentLinkedList());
addTest(new TestDataUtils());
addTest(new TestFreeSpace());
addTest(new TestKillProcessWhileWriting());
addTest(new TestMVRTree());
addTest(new TestMVStore());
addTest(new TestMVStoreBenchmark());
addTest(new TestMVStoreStopCompact());
addTest(new TestMVStoreTool());
addTest(new TestMVTableEngine());
addTest(new TestObjectDataType());
addTest(new TestRandomMapOps());
addTest(new TestSpinLock());
addTest(new TestStreamStore());
addTest(new TestTransactionStore());
// unit
addTest(new TestAnsCompression());
addTest(new TestAutoReconnect());
addTest(new TestBinaryArithmeticStream());
addTest(new TestBitStream());
addTest(new TestBnf());
addTest(new TestCache());
addTest(new TestCharsetCollator());
addTest(new TestClearReferences());
addTest(new TestCollation());
addTest(new TestCompress());
addTest(new TestConnectionInfo());
addTest(new TestDataPage());
addTest(new TestDateIso8601());
addTest(new TestExit());
addTest(new TestFile());
addTest(new TestFileLock());
addTest(new TestFtp());
addTest(new TestIntArray());
addTest(new TestIntIntHashMap());
addTest(new TestIntPerfectHash());
addTest(new TestJmx());
addTest(new TestMathUtils());
addTest(new TestMode());
addTest(new TestModifyOnWrite());
addTest(new TestOldVersion());
addTest(new TestObjectDeserialization());
addTest(new TestMultiThreadedKernel());
addTest(new TestOverflow());
addTest(new TestPageStore());
addTest(new TestPageStoreCoverage());
addTest(new TestPerfectHash());
addTest(new TestPgServer());
addTest(new TestReader());
addTest(new TestRecovery());
addTest(new TestScriptReader());
addTest(new RecoverLobTest());
addTest(createTest("org.h2.test.unit.TestServlet"));
addTest(new TestSecurity());
addTest(new TestShell());
addTest(new TestSort());
addTest(new TestStreams());
addTest(new TestStringUtils());
addTest(new TestTimeStampWithTimeZone());
addTest(new TestTraceSystem());
addTest(new TestUpgrade());
addTest(new TestUsingIndex());
addTest(new TestUtils());
addTest(new TestValue());
addTest(new TestValueHashMap());
addTest(new TestWeb());
runAddedTests();
// serial
addTest(new TestDate());
addTest(new TestDateTimeUtils());
addTest(new TestCluster());
addTest(new TestConcurrent());
addTest(new TestFileLockSerialized());
addTest(new TestFileLockProcess());
addTest(new TestFileSystem());
addTest(new TestNetUtils());
addTest(new TestPattern());
addTest(new TestTools());
addTest(new TestSampleApps());
addTest(new TestStringCache());
addTest(new TestValueMemory());
runAddedTests(1);
}
use of org.h2.test.unit.TestFile in project h2database by h2database.
the class TestFileSystem method testUnsupportedFeatures.
private static void testUnsupportedFeatures(String fsBase) throws IOException {
final String fileName = fsBase + "/testFile";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
}
if (FileUtils.createFile(fileName)) {
final FileChannel channel = FileUtils.open(fileName, "rw");
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.map(MapMode.PRIVATE, 0, channel.size());
}
};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.read(new ByteBuffer[] { ByteBuffer.allocate(10) }, 0, 0);
}
};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.write(new ByteBuffer[] { ByteBuffer.allocate(10) }, 0, 0);
}
};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.transferFrom(channel, 0, 0);
}
};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.transferTo(0, 0, channel);
}
};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.lock();
}
};
channel.close();
FileUtils.delete(fileName);
}
}
use of org.h2.test.unit.TestFile in project h2database by h2database.
the class TestFileSystem method testParentEventuallyReturnsNull.
private void testParentEventuallyReturnsNull(String fsBase) {
FilePath p = FilePath.get(fsBase + "/testFile");
assertTrue(p.getScheme().length() > 0);
for (int i = 0; i < 100; i++) {
if (p == null) {
return;
}
p = p.getParent();
}
fail("Parent is not null: " + p);
String path = fsBase + "/testFile";
for (int i = 0; i < 100; i++) {
if (path == null) {
return;
}
path = FileUtils.getParent(path);
}
fail("Parent is not null: " + path);
}
use of org.h2.test.unit.TestFile in project h2database by h2database.
the class TestFileSystem method testRootExists.
private void testRootExists(String fsBase) {
String fileName = fsBase + "/testFile";
FilePath p = FilePath.get(fileName);
while (p.getParent() != null) {
p = p.getParent();
}
assertTrue(p.exists());
}
Aggregations