use of org.h2.test.db.TestTwoPhaseCommit in project h2database by h2database.
the class TestMVTableEngine method testTwoPhaseCommit.
private void testTwoPhaseCommit() throws Exception {
if (config.memory) {
return;
}
Connection conn;
Statement stat;
deleteDb(getTestName());
String url = getTestName() + ";MV_STORE=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("set write_delay 0");
conn.setAutoCommit(false);
stat.execute("insert into test values(1, 'Hello')");
stat.execute("prepare commit test_tx");
stat.execute("shutdown immediately");
JdbcUtils.closeSilently(conn);
conn = getConnection(url);
stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from information_schema.in_doubt");
assertTrue(rs.next());
stat.execute("commit transaction test_tx");
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
conn.close();
}
use of org.h2.test.db.TestTwoPhaseCommit in project h2database by h2database.
the class TestAll method test.
/**
* Run all tests with the current settings.
*/
private void test() throws SQLException {
System.out.println();
System.out.println("Test " + toString() + " (" + Utils.getMemoryUsed() + " KB used)");
beforeTest();
// db
addTest(new TestScriptSimple());
addTest(new TestScript());
addTest(new TestAlter());
addTest(new TestAlterSchemaRename());
addTest(new TestAutoRecompile());
addTest(new TestBackup());
addTest(new TestBigDb());
addTest(new TestBigResult());
addTest(new TestCases());
addTest(new TestCheckpoint());
addTest(new TestCompatibility());
addTest(new TestCompatibilityOracle());
addTest(new TestCsv());
addTest(new TestDeadlock());
if (vmlens) {
return;
}
addTest(new TestDrop());
addTest(new TestDuplicateKeyUpdate());
addTest(new TestEncryptedDb());
addTest(new TestExclusive());
addTest(new TestFullText());
addTest(new TestFunctionOverload());
addTest(new TestFunctions());
addTest(new TestInit());
addTest(new TestIndex());
addTest(new TestIndexHints());
addTest(new TestLargeBlob());
addTest(new TestLinkedTable());
addTest(new TestListener());
addTest(new TestLob());
addTest(new TestMergeUsing());
addTest(new TestMultiConn());
addTest(new TestMultiDimension());
addTest(new TestMultiThreadedKernel());
addTest(new TestOpenClose());
addTest(new TestOptimizations());
addTest(new TestOptimizerHints());
addTest(new TestOutOfMemory());
addTest(new TestReadOnly());
addTest(new TestRecursiveQueries());
addTest(new TestGeneralCommonTableQueries());
if (!memory) {
// requires persistent store for reconnection tests
addTest(new TestPersistentCommonTableExpressions());
}
addTest(new TestRights());
addTest(new TestRunscript());
addTest(new TestSQLInjection());
addTest(new TestSessionsLocks());
addTest(new TestSelectCountNonNullColumn());
addTest(new TestSequence());
addTest(new TestShow());
addTest(new TestSpaceReuse());
addTest(new TestSpatial());
addTest(new TestSpeed());
addTest(new TestTableEngines());
addTest(new TestRowFactory());
addTest(new TestTempTables());
addTest(new TestTransaction());
addTest(new TestTriggersConstraints());
addTest(new TestTwoPhaseCommit());
addTest(new TestView());
addTest(new TestViewAlterTable());
addTest(new TestViewDropView());
addTest(new TestReplace());
addTest(new TestSynonymForTable());
addTest(new TestColumnNamer());
// jaqu
addTest(new AliasMapTest());
addTest(new AnnotationsTest());
addTest(new ClobTest());
addTest(new ModelsTest());
addTest(new SamplesTest());
addTest(new UpdateTest());
// jdbc
addTest(new TestBatchUpdates());
addTest(new TestCallableStatement());
addTest(new TestCancel());
addTest(new TestConcurrentConnectionUsage());
addTest(new TestConnection());
addTest(new TestDatabaseEventListener());
addTest(new TestJavaObject());
addTest(new TestLimitUpdates());
addTest(new TestLobApi());
addTest(new TestManyJdbcObjects());
addTest(new TestMetaData());
addTest(new TestNativeSQL());
addTest(new TestPreparedStatement());
addTest(new TestResultSet());
addTest(new TestStatement());
addTest(new TestGetGeneratedKeys());
addTest(new TestTransactionIsolation());
addTest(new TestUpdatableResultSet());
addTest(new TestZloty());
addTest(new TestCustomDataTypesHandler());
addTest(new TestSetCollation());
// jdbcx
addTest(new TestConnectionPool());
addTest(new TestDataSource());
addTest(new TestXA());
addTest(new TestXASimple());
// server
addTest(new TestAutoServer());
addTest(new TestNestedLoop());
// mvcc & row level locking
addTest(new TestMvcc1());
addTest(new TestMvcc2());
addTest(new TestMvcc3());
addTest(new TestMvcc4());
addTest(new TestMvccMultiThreaded());
addTest(new TestMvccMultiThreaded2());
addTest(new TestRowLocks());
// synth
addTest(new TestBtreeIndex());
addTest(new TestConcurrentUpdate());
addTest(new TestDiskFull());
addTest(new TestCrashAPI());
addTest(new TestFuzzOptimizations());
addTest(new TestLimit());
addTest(new TestRandomCompare());
addTest(new TestKillRestart());
addTest(new TestKillRestartMulti());
addTest(new TestMultiThreaded());
addTest(new TestOuterJoins());
addTest(new TestNestedJoins());
addTest(new TestStringAggCompatibility());
runAddedTests();
// serial
addTest(new TestDateStorage());
addTest(new TestDriver());
addTest(new TestJavaObjectSerializer());
addTest(new TestLocale());
addTest(new TestMemoryUsage());
addTest(new TestMultiThread());
addTest(new TestPowerOff());
addTest(new TestReorderWrites());
addTest(new TestRandomSQL());
addTest(new TestQueryCache());
addTest(new TestUrlJavaObjectSerializer());
addTest(new TestWeb());
runAddedTests(1);
afterTest();
}
use of org.h2.test.db.TestTwoPhaseCommit in project h2database by h2database.
the class TestTransactionStore method testTwoPhaseCommit.
private void testTwoPhaseCommit() {
String fileName = getBaseDir() + "/testTwoPhaseCommit.h3";
FileUtils.delete(fileName);
MVStore s;
TransactionStore ts;
Transaction tx;
Transaction txOld;
TransactionMap<String, String> m;
List<Transaction> list;
s = MVStore.open(fileName);
ts = new TransactionStore(s);
ts.init();
tx = ts.begin();
assertEquals(null, tx.getName());
tx.setName("first transaction");
assertEquals("first transaction", tx.getName());
assertEquals(1, tx.getId());
assertEquals(Transaction.STATUS_OPEN, tx.getStatus());
m = tx.openMap("test");
m.put("1", "Hello");
list = ts.getOpenTransactions();
assertEquals(1, list.size());
txOld = list.get(0);
assertTrue(tx.getId() == txOld.getId());
assertEquals("first transaction", txOld.getName());
s.commit();
ts.close();
s.close();
s = MVStore.open(fileName);
ts = new TransactionStore(s);
ts.init();
tx = ts.begin();
assertEquals(2, tx.getId());
m = tx.openMap("test");
assertEquals(null, m.get("1"));
m.put("2", "Hello");
list = ts.getOpenTransactions();
assertEquals(2, list.size());
txOld = list.get(0);
assertEquals(1, txOld.getId());
assertEquals(Transaction.STATUS_OPEN, txOld.getStatus());
assertEquals("first transaction", txOld.getName());
txOld.prepare();
assertEquals(Transaction.STATUS_PREPARED, txOld.getStatus());
txOld = list.get(1);
txOld.commit();
s.commit();
s.close();
s = MVStore.open(fileName);
ts = new TransactionStore(s);
ts.init();
tx = ts.begin();
m = tx.openMap("test");
m.put("3", "Test");
assertEquals(2, tx.getId());
list = ts.getOpenTransactions();
assertEquals(2, list.size());
txOld = list.get(1);
assertEquals(2, txOld.getId());
assertEquals(Transaction.STATUS_OPEN, txOld.getStatus());
assertEquals(null, txOld.getName());
txOld.rollback();
txOld = list.get(0);
assertEquals(1, txOld.getId());
assertEquals(Transaction.STATUS_PREPARED, txOld.getStatus());
assertEquals("first transaction", txOld.getName());
txOld.commit();
assertEquals("Hello", m.get("1"));
s.close();
FileUtils.delete(fileName);
}
Aggregations