use of org.h2.dev.util.BinaryArithmeticStream.Out in project h2database by h2database.
the class TestFileLockSerialized method testPendingWrite.
private void testPendingWrite() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0";
Connection conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
Thread.sleep(100);
String propFile = getBaseDir() + "/fileLockSerialized.lock.db";
SortedProperties p = SortedProperties.loadProperties(propFile);
p.setProperty("changePending", "true");
p.setProperty("modificationDataId", "1000");
try (OutputStream out = FileUtils.newOutputStream(propFile, false)) {
p.store(out, "test");
}
Thread.sleep(100);
stat.execute("select * from test");
conn.close();
}
use of org.h2.dev.util.BinaryArithmeticStream.Out in project h2database by h2database.
the class TestAll method addTest.
private void addTest(TestBase test) {
// tests.add(test);
// run directly for now, because concurrently running tests
// fails on Raspberry Pi quite often (seems to be a JVM problem)
// event queue watchdog for tests that get stuck when running in Jenkins
final java.util.Timer watchdog = new java.util.Timer();
// 5 minutes
watchdog.schedule(new TimerTask() {
@Override
public void run() {
ThreadDeadlockDetector.dumpAllThreadsAndLocks("test watchdog timed out");
}
}, 5 * 60 * 1000);
try {
test.runTest(this);
} finally {
watchdog.cancel();
}
}
use of org.h2.dev.util.BinaryArithmeticStream.Out in project h2database by h2database.
the class TestConcurrent method testConcurrentOnlineBackup.
private void testConcurrentOnlineBackup() throws Exception {
String fileName = getBaseDir() + "/" + getTestName();
String fileNameRestore = getBaseDir() + "/" + getTestName() + "2";
final MVStore s = openStore(fileName);
final MVMap<Integer, byte[]> map = s.openMap("test");
final Random r = new Random();
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
for (int i = 0; i < 10; i++) {
map.put(i, new byte[100 * r.nextInt(100)]);
}
s.commit();
map.clear();
s.commit();
long len = s.getFileStore().size();
if (len > 1024 * 1024) {
// slow down writing a lot
Thread.sleep(200);
} else if (len > 20 * 1024) {
// slow down writing
Thread.sleep(20);
}
}
}
};
task.execute();
try {
for (int i = 0; i < 10; i++) {
// System.out.println("test " + i);
s.setReuseSpace(false);
OutputStream out = new BufferedOutputStream(new FileOutputStream(fileNameRestore));
long len = s.getFileStore().size();
copyFileSlowly(s.getFileStore().getFile(), len, out);
out.close();
s.setReuseSpace(true);
MVStore s2 = openStore(fileNameRestore);
MVMap<Integer, byte[]> test = s2.openMap("test");
for (Integer k : test.keySet()) {
test.get(k);
}
s2.close();
// let it compact
Thread.sleep(10);
}
} finally {
task.get();
}
s.close();
}
use of org.h2.dev.util.BinaryArithmeticStream.Out in project h2database by h2database.
the class TestBinaryArithmeticStream method testHuffmanRandomized.
private void testHuffmanRandomized() throws IOException {
Random r = new Random(1);
int[] freq = new int[r.nextInt(200) + 1];
for (int i = 0; i < freq.length; i++) {
freq[i] = r.nextInt(1000) + 1;
}
int seed = r.nextInt();
r.setSeed(seed);
Huffman huff = new Huffman(freq);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
Out out = new Out(byteOut);
for (int i = 0; i < 10000; i++) {
huff.write(out, r.nextInt(freq.length));
}
out.flush();
In in = new In(new ByteArrayInputStream(byteOut.toByteArray()));
r.setSeed(seed);
for (int i = 0; i < 10000; i++) {
int expected = r.nextInt(freq.length);
int got = huff.read(in);
assertEquals(expected, got);
}
}
use of org.h2.dev.util.BinaryArithmeticStream.Out in project h2database by h2database.
the class TestBinaryArithmeticStream method testCompressionRatio.
private void testCompressionRatio() throws IOException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
Out out = new Out(byteOut);
int prob = 1000;
int len = 1024;
for (int i = 0; i < len; i++) {
out.writeBit(true, prob);
}
out.flush();
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
In in = new In(byteIn);
for (int i = 0; i < len; i++) {
assertTrue(in.readBit(prob));
}
// System.out.println(len / 8 + " comp: " +
// byteOut.toByteArray().length);
}
Aggregations