use of org.h2.test.unit.TestCache in project h2database by h2database.
the class TestFileLockSerialized method testCache.
/**
* Caches must be cleared. Session.reconnect only closes the DiskFile (which
* is associated with the cache) if there is one session
*/
private void testCache() throws Exception {
deleteDb("fileLockSerialized");
String urlShared = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
Connection connShared1 = getConnection(urlShared);
Statement statement1 = connShared1.createStatement();
Connection connShared2 = getConnection(urlShared);
Statement statement2 = connShared2.createStatement();
statement1.execute("create table test1(id int)");
statement1.execute("insert into test1 values(1)");
ResultSet rs = statement1.executeQuery("select id from test1");
rs.close();
rs = statement2.executeQuery("select id from test1");
rs.close();
statement1.execute("update test1 set id=2");
Thread.sleep(500);
rs = statement2.executeQuery("select id from test1");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
rs.close();
connShared1.close();
connShared2.close();
deleteDb("fileLockSerialized");
}
use of org.h2.test.unit.TestCache 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.TestCache in project h2database by h2database.
the class TestCache method testCache.
private void testCache() {
out = "";
Cache c = CacheLRU.getCache(this, "LRU", 16);
for (int i = 0; i < 20; i++) {
c.put(new Obj(i));
}
assertEquals("flush 0 flush 1 flush 2 flush 3 ", out);
}
use of org.h2.test.unit.TestCache in project h2database by h2database.
the class TestMultiThreadedKernel method testCache.
private void testCache() throws Exception {
ArrayList<Task> list = New.arrayList();
int size = 3;
final int count = 100;
final Connection[] connections = new Connection[count];
String url = getURL("multiThreadedKernel;" + "MULTI_THREADED=TRUE;CACHE_SIZE=1", true);
for (int i = 0; i < size; i++) {
final Connection conn = DriverManager.getConnection(url, getUser(), getPassword());
connections[i] = conn;
if (i == 0) {
Statement stat = conn.createStatement();
stat.execute("drop table test if exists");
stat.execute("create table test(id int primary key, name varchar) " + "as select x, space(3000) from system_range(1, " + count + ")");
}
final Random random = new Random(i);
Task t = new Task() {
@Override
public void call() throws SQLException {
PreparedStatement prep = conn.prepareStatement("select * from test where id = ?");
while (!stop) {
prep.setInt(1, random.nextInt(count));
prep.execute();
}
}
};
t.execute();
list.add(t);
}
Thread.sleep(1000);
for (Task t : list) {
t.get();
}
for (int i = 0; i < size; i++) {
connections[i].close();
}
}
use of org.h2.test.unit.TestCache in project h2database by h2database.
the class TestMVStoreCachePerformance method testCache.
private void testCache(int threadCount, String fileNamePrefix) {
String fileName = getBaseDir() + "/" + getTestName();
fileName = fileNamePrefix + fileName;
FileUtils.delete(fileName);
MVStore store = new MVStore.Builder().fileName(fileName).open();
final MVMap<Integer, byte[]> map = store.openMap("test");
final AtomicInteger counter = new AtomicInteger();
byte[] data = new byte[8 * 1024];
final int count = 10000;
for (int i = 0; i < count; i++) {
map.put(i, data);
store.commit();
if (i % 1000 == 0) {
// System.out.println("add " + i);
}
}
Task[] tasks = new Task[threadCount];
for (int i = 0; i < threadCount; i++) {
tasks[i] = new Task() {
@Override
public void call() throws Exception {
Random r = new Random();
do {
int id = r.nextInt(count);
map.get(id);
counter.incrementAndGet();
} while (!stop);
}
};
tasks[i].execute();
}
for (int i = 0; i < 4; i++) {
// Profiler prof = new Profiler().startCollecting();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
// System.out.println(prof.getTop(5));
// System.out.println(" " + counter.get() / (i + 1) + " op/s");
}
// long time = System.nanoTime();
for (Task t : tasks) {
t.get();
}
store.close();
System.out.println(counter.get() / 10000 + " ops/ms; " + threadCount + " thread(s); " + fileNamePrefix);
}
Aggregations