From: Bryan T. <tho...@us...> - 2007-02-28 13:59:20
|
Update of /cvsroot/cweb/bigdata/src/test/com/bigdata/journal In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv19761/src/test/com/bigdata/journal Modified Files: TestTransactionServer.java TestReadCommittedTx.java TestRootBlockView.java TestReadOnlyTx.java ComparisonTestDriver.java StressTestConcurrent.java TestJournalBasics.java TestTxJournalProtocol.java TestAll.java Added Files: AbstractTestTxRunState.java Removed Files: TestTxRunState.java Log Message: Adds support for read-committed transactions. --- TestTxRunState.java DELETED --- Index: TestJournalBasics.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestJournalBasics.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TestJournalBasics.java 20 Feb 2007 00:27:03 -0000 1.10 --- TestJournalBasics.java 28 Feb 2007 13:59:09 -0000 1.11 *************** *** 103,107 **** // tests of transitions in the transaction RunState state machine. ! suite.addTestSuite( TestTxRunState.class ); // @todo update these tests of the tx-journal integration. suite.addTestSuite( TestTxJournalProtocol.class ); --- 103,107 ---- // tests of transitions in the transaction RunState state machine. ! suite.addTest( AbstractTestTxRunState.suite() ); // @todo update these tests of the tx-journal integration. suite.addTestSuite( TestTxJournalProtocol.class ); Index: ComparisonTestDriver.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/ComparisonTestDriver.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ComparisonTestDriver.java 22 Feb 2007 16:59:34 -0000 1.2 --- ComparisonTestDriver.java 28 Feb 2007 13:59:09 -0000 1.3 *************** *** 291,294 **** --- 291,296 ---- Iterator<Condition> itr = conditions.iterator(); + int i = 0; + while (itr.hasNext()) { *************** *** 297,301 **** IComparisonTest test = (IComparisonTest) cl.newInstance(); ! System.err.println("Running: "+ condition.name); try { --- 299,303 ---- IComparisonTest test = (IComparisonTest) cl.newInstance(); ! System.err.println("Running "+ condition.name +" ("+i+" of "+nconditions+")"); try { *************** *** 310,319 **** writer.write(condition.result + ", " + condition.name+"\n"); } - writer.flush(); - writer.close(); } --- 312,323 ---- writer.write(condition.result + ", " + condition.name+"\n"); + writer.flush(); + } writer.close(); + i++; + } Index: StressTestConcurrent.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/StressTestConcurrent.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** StressTestConcurrent.java 22 Feb 2007 16:59:34 -0000 1.5 --- StressTestConcurrent.java 28 Feb 2007 13:59:09 -0000 1.6 *************** *** 221,226 **** } ! journal.closeAndDelete(); String msg = "#clients=" --- 221,232 ---- } + + journal.shutdown(); ! if(journal.getFile()!=null) { ! ! journal.getFile().delete(); ! ! } String msg = "#clients=" *************** *** 377,381 **** // properties.setProperty(Options.BUFFER_MODE, BufferMode.Transient.toString()); ! // properties.setProperty(Options.FORCE_ON_COMMIT,ForceEnum.No.toString()); // properties.setProperty(Options.BUFFER_MODE, BufferMode.Direct.toString()); --- 383,387 ---- // properties.setProperty(Options.BUFFER_MODE, BufferMode.Transient.toString()); ! properties.setProperty(Options.FORCE_ON_COMMIT,ForceEnum.No.toString()); // properties.setProperty(Options.BUFFER_MODE, BufferMode.Direct.toString()); *************** *** 386,398 **** properties.setProperty(Options.SEGMENT, "0"); - - File file = File.createTempFile("bigdata", ".jnl"); - - file.deleteOnExit(); - - if(!file.delete()) fail("Could not remove temp file before test"); - - properties.setProperty(Options.FILE, file.toString()); new StressTestConcurrent().doComparisonTest(properties); --- 392,398 ---- properties.setProperty(Options.SEGMENT, "0"); + properties.setProperty(Options.CREATE_TEMP_FILE, "true"); + new StressTestConcurrent().doComparisonTest(properties); *************** *** 460,471 **** keyLen, nops); - journal.shutdown(); - - if(journal.getFile()!=null) { - - journal.getFile().delete(); - - } - return msg; --- 460,463 ---- Index: TestTxJournalProtocol.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestTxJournalProtocol.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestTxJournalProtocol.java 22 Feb 2007 16:59:34 -0000 1.2 --- TestTxJournalProtocol.java 28 Feb 2007 13:59:09 -0000 1.3 *************** *** 49,53 **** import java.io.IOException; - import java.util.Properties; /** --- 49,52 ---- *************** *** 56,60 **** * * @todo the tests in this suite are stale and need to be reviewed, possibly ! * revised or replaced, and certainly extended. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> --- 55,63 ---- * * @todo the tests in this suite are stale and need to be reviewed, possibly ! * revised or replaced, and certainly extended. The main issue is that ! * they do not test the basic contract for the journal, transactions, and ! * the transaction manager service but instead test some particulars of ! * the implementation that might not even be the right way to manage that ! * contract. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> *************** *** 78,87 **** Journal journal = new Journal(getProperties()); ! Tx tx0 = new Tx(journal, 0, false); try { // Try to create another transaction with the same identifier. ! new Tx(journal, 0, false); fail("Expecting: " + IllegalStateException.class); --- 81,92 ---- Journal journal = new Journal(getProperties()); ! final long startTime = journal.nextTimestamp(); ! ! Tx tx0 = new Tx(journal, startTime, false); try { // Try to create another transaction with the same identifier. ! new Tx(journal, startTime, false); fail("Expecting: " + IllegalStateException.class); *************** *** 119,130 **** Journal journal = new Journal(getProperties()); ! ITx tx0 = new Tx(journal, 0, false); ! tx0.prepare(); try { ! // Try to create another transaction with the same identifier. ! new Tx(journal, 0, false); fail("Expecting: " + IllegalStateException.class); --- 124,137 ---- Journal journal = new Journal(getProperties()); ! final long startTime = journal.nextTimestamp(); ! ITx tx0 = new Tx(journal, startTime, false); ! ! tx0.prepare(journal.nextTimestamp()); try { ! // Try to create another transaction with the same start time. ! new Tx(journal, startTime, false); fail("Expecting: " + IllegalStateException.class); Index: TestReadCommittedTx.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestReadCommittedTx.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestReadCommittedTx.java 17 Feb 2007 21:34:12 -0000 1.1 --- TestReadCommittedTx.java 28 Feb 2007 13:59:09 -0000 1.2 *************** *** 48,51 **** --- 48,54 ---- package com.bigdata.journal; + import com.bigdata.isolation.UnisolatedBTree; + import com.bigdata.objndx.IIndex; + /** * Test suite for read-committed transactions. *************** *** 69,75 **** } ! public void test_something() { ! fail("write tests"); } --- 72,289 ---- } ! /** ! * Test verifies that you can not write on a read-only transaction. ! */ ! public void test_isReadOnly() { ! Journal journal = new Journal(getProperties()); ! ! String name = "abc"; ! ! final byte[] k1 = new byte[]{1}; ! ! final byte[] v1 = new byte[]{1}; ! ! { ! ! /* ! * register an index, write on the index, and commit the journal. ! */ ! IIndex ndx = journal.registerIndex(name, new UnisolatedBTree( ! journal)); ! ! ndx.insert(k1, v1); ! ! journal.commit(); ! ! } ! ! { ! ! /* ! * create a read-only transaction, verify that we can read the ! * value written on the index but that we can not write on the ! * index. ! */ ! ! final long tx1 = journal.newTx(IsolationEnum.ReadOnly); ! ! IIndex ndx = journal.getIndex(name,tx1); ! ! assertNotNull(ndx); ! ! assertEquals((byte[])v1,(byte[])ndx.lookup(k1)); ! ! try { ! ndx.insert(k1,new byte[]{1,2,3}); ! fail("Expecting: "+UnsupportedOperationException.class); ! } catch( UnsupportedOperationException ex) { ! System.err.println("Ignoring expected exception: "+ex); ! } ! ! journal.commit(tx1); ! ! } ! ! { ! ! /* ! * do it again, but this time we will abort the read-only ! * transaction. ! */ ! ! final long tx1 = journal.newTx(IsolationEnum.ReadOnly); ! ! IIndex ndx = journal.getIndex(name,tx1); ! ! assertNotNull(ndx); ! ! assertEquals((byte[])v1,(byte[])ndx.lookup(k1)); ! ! try { ! ndx.insert(k1,new byte[]{1,2,3}); ! fail("Expecting: "+UnsupportedOperationException.class); ! } catch( UnsupportedOperationException ex) { ! System.err.println("Ignoring expected exception: "+ex); ! } ! ! journal.abort(tx1); ! ! } ! ! journal.closeAndDelete(); ! ! } ! ! /** ! * @todo test that the transaction begins reading from the most recently ! * committed state, that unisolated writes without commits are not ! * visible, that newly committed state shows up in the next index view ! * requested by the tx (so this is either a different index view ! * object or a delegation mechanism that indirects to the current ! * view), and that the same index view object is returned if there ! * have been no intervening commits. ! */ ! public void test_readComittedIsolation() { ! ! Journal journal = new Journal(getProperties()); ! ! String name = "abc"; ! ! final byte[] k1 = new byte[]{1}; ! ! final byte[] v1 = new byte[]{1}; ! ! // create a new read-committed transaction. ! final long ts0 = journal.newTx(IsolationEnum.ReadCommitted); ! ! { ! /* ! * verify that the index is not accessible since it has not been ! * registered. ! */ ! assertNull(journal.getIndex(name,ts0)); ! ! } ! ! { ! ! // register an index and commit the journal. ! ! journal.registerIndex(name, new UnisolatedBTree(journal)); ! ! journal.commit(); ! ! } ! ! { ! ! /* ! * verify that the index is now accessible but that it does not ! * hold any data. ! */ ! ! IIndex ts0_ndx = journal.getIndex(name, ts0); ! ! assertFalse(ts0_ndx.contains(k1)); ! assertNull(ts0_ndx.lookup(k1)); ! assertEquals(0,ts0_ndx.rangeCount(null, null)); ! ! } ! ! { ! // obtain the unisolated index. ! IIndex ndx = journal.getIndex(name); ! ! // write on the index. ! ndx.insert(k1, v1); ! ! } ! ! { ! ! /* ! * verify that the write is not visible since the journal has not ! * been committed. ! */ ! ! IIndex ts0_ndx = journal.getIndex(name, ts0); ! ! assertFalse(ts0_ndx.contains(k1)); ! assertNull(ts0_ndx.lookup(k1)); ! assertEquals(0,ts0_ndx.rangeCount(null, null)); ! ! } ! ! { ! /* ! * commit the journal and verify that the write is now visible to ! * the read-committed transaction. ! */ ! ! journal.commit(); ! ! IIndex ts0_ndx = journal.getIndex(name, ts0); ! ! assertTrue(ts0_ndx.contains(k1)); ! assertEquals(v1,(byte[])ts0_ndx.lookup(k1)); ! assertEquals(1,ts0_ndx.rangeCount(null, null)); ! ! } ! ! { ! /* ! * verify that the write is also visible in a new read-committed ! * transaction. ! */ ! ! long ts1 = journal.newTx(IsolationEnum.ReadCommitted); ! ! IIndex ts1_ndx = journal.getIndex(name, ts1); ! ! assertTrue(ts1_ndx.contains(k1)); ! assertEquals(v1,(byte[])ts1_ndx.lookup(k1)); ! assertEquals(1,ts1_ndx.rangeCount(null, null)); ! ! // should be a nop. ! assertEquals(0,journal.commit(ts1)); ! ! } ! ! // should be a nop. ! journal.abort(ts0); ! ! // close and delete the database. ! journal.closeAndDelete(); ! ! } ! ! /** ! * @todo test protocol for closing index views and releasing holds on commit ! * points. ! */ ! public void test_releaseViews() { ! ! fail("write test"); } Index: TestTransactionServer.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestTransactionServer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestTransactionServer.java 19 Feb 2007 19:00:18 -0000 1.2 --- TestTransactionServer.java 28 Feb 2007 13:59:09 -0000 1.3 *************** *** 48,52 **** package com.bigdata.journal; - import com.bigdata.journal.TransactionServer.IsolationEnum; import junit.framework.TestCase; --- 48,51 ---- Index: TestAll.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestAll.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TestAll.java 22 Feb 2007 16:59:34 -0000 1.9 --- TestAll.java 28 Feb 2007 13:59:09 -0000 1.10 *************** *** 103,106 **** --- 103,114 ---- suite.addTest( TestTransientJournal.suite() ); suite.addTest( TestDirectJournal.suite() ); + /* + * Note: The mapped journal is somewhat problematic and its tests are + * disabled for the moment since (a) we have to pre-allocate large + * extends; (b) it does not perform any better than other options; and + * (c) we can not synchronously unmap or delete a mapped file which + * makes cleanup of the test suites difficult and winds up spewing 200M + * files all over your temp directory. + */ // suite.addTest( TestMappedJournal.suite() ); suite.addTest( TestDiskJournal.suite() ); Index: TestRootBlockView.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestRootBlockView.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TestRootBlockView.java 19 Feb 2007 19:00:18 -0000 1.9 --- TestRootBlockView.java 28 Feb 2007 13:59:09 -0000 1.10 *************** *** 110,117 **** assertEquals("segmentId", segmentId, rootBlock.getSegmentId()); assertEquals("nextOffset", nextOffset, rootBlock.getNextOffset()); ! assertEquals("firstTxId", firstTxId, rootBlock.getFirstTxCommitTime()); ! assertEquals("lastTxId", lastTxId, rootBlock.getLastTxCommitTime()); assertEquals("commitCounter", commitCounter, rootBlock.getCommitCounter()); ! assertEquals("commitTimestamp", commitTimestamp, rootBlock.getCommitTimestamp()); assertEquals("commitRecordAddr", commitRecordAddr, rootBlock.getCommitRecordAddr()); assertEquals("commitRecordIndexAddr", commitRecordIndexAddr, rootBlock.getCommitRecordIndexAddr()); --- 110,117 ---- assertEquals("segmentId", segmentId, rootBlock.getSegmentId()); assertEquals("nextOffset", nextOffset, rootBlock.getNextOffset()); ! assertEquals("firstTxId", firstTxId, rootBlock.getFirstCommitTime()); ! assertEquals("lastTxId", lastTxId, rootBlock.getLastCommitTime()); assertEquals("commitCounter", commitCounter, rootBlock.getCommitCounter()); ! assertEquals("commitTime", commitTimestamp, rootBlock.getCommitTimestamp()); assertEquals("commitRecordAddr", commitRecordAddr, rootBlock.getCommitRecordAddr()); assertEquals("commitRecordIndexAddr", commitRecordIndexAddr, rootBlock.getCommitRecordIndexAddr()); *************** *** 125,132 **** assertEquals("segmentId", segmentId, rootBlock.getSegmentId()); assertEquals("nextOffset", nextOffset, rootBlock.getNextOffset()); ! assertEquals("firstTxId", firstTxId, rootBlock.getFirstTxCommitTime()); ! assertEquals("lastTxId", lastTxId, rootBlock.getLastTxCommitTime()); assertEquals("commitCounter", commitCounter, rootBlock.getCommitCounter()); ! assertEquals("commitTimestamp", commitTimestamp, rootBlock.getCommitTimestamp()); assertEquals("commitRecordAddr", commitRecordAddr, rootBlock.getCommitRecordAddr()); assertEquals("commitRecordIndexAddr", commitRecordIndexAddr, rootBlock.getCommitRecordIndexAddr()); --- 125,132 ---- assertEquals("segmentId", segmentId, rootBlock.getSegmentId()); assertEquals("nextOffset", nextOffset, rootBlock.getNextOffset()); ! assertEquals("firstTxId", firstTxId, rootBlock.getFirstCommitTime()); ! assertEquals("lastTxId", lastTxId, rootBlock.getLastCommitTime()); assertEquals("commitCounter", commitCounter, rootBlock.getCommitCounter()); ! assertEquals("commitTime", commitTimestamp, rootBlock.getCommitTimestamp()); assertEquals("commitRecordAddr", commitRecordAddr, rootBlock.getCommitRecordAddr()); assertEquals("commitRecordIndexAddr", commitRecordIndexAddr, rootBlock.getCommitRecordIndexAddr()); --- NEW FILE: AbstractTestTxRunState.java --- /** The Notice below must appear in each file of the Source Code of any copy you distribute of the Licensed Product. Contributors to any Modifications may add their own copyright notices to identify their own contributions. License: The contents of this file are subject to the CognitiveWeb Open Source License Version 1.1 (the License). You may not copy or use this file, in either source code or executable form, except in compliance with the License. You may obtain a copy of the License from http://www.CognitiveWeb.org/legal/license/ Software distributed under the License is distributed on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyrights: Portions created by or assigned to CognitiveWeb are Copyright (c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact information for CognitiveWeb is available at http://www.CognitiveWeb.org Portions Copyright (c) 2002-2003 Bryan Thompson. Acknowledgements: Special thanks to the developers of the Jabber Open Source License 1.0 (JOSL), from which this License was derived. This License contains terms that differ from JOSL. Special thanks to the CognitiveWeb Open Source Contributors for their suggestions and support of the Cognitive Web. Modifications: */ /* * Created on Feb 13, 2007 */ package com.bigdata.journal; import java.io.IOException; import junit.framework.TestSuite; import com.bigdata.isolation.UnisolatedBTree; import com.bigdata.objndx.IIndex; /** * Test suite for the state machine governing the transaction {@link RunState} * transitions. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ abstract public class AbstractTestTxRunState extends ProxyTestCase { public static TestSuite suite() { TestSuite suite = new TestSuite("Transaction run state"); suite.addTestSuite(TestReadCommitted.class); suite.addTestSuite(TestReadOnly.class); suite.addTestSuite(TestReadWrite.class); return suite; } /** * */ public AbstractTestTxRunState() { } /** * @param name */ public AbstractTestTxRunState(String name) { super(name); } /** * Return a new transaction start time. */ abstract public long newTx(Journal journal); public static class TestReadCommitted extends AbstractTestTxRunState { public TestReadCommitted() { } public TestReadCommitted(String name) { super(name); } public long newTx(Journal journal) { return journal.newTx(IsolationEnum.ReadCommitted); } } public static class TestReadOnly extends AbstractTestTxRunState { public TestReadOnly() { } public TestReadOnly(String name) { super(name); } public long newTx(Journal journal) { return journal.newTx(IsolationEnum.ReadOnly); } } public static class TestReadWrite extends AbstractTestTxRunState { public TestReadWrite() { } public TestReadWrite(String name) { super(name); } public long newTx(Journal journal) { return journal.newTx(IsolationEnum.ReadWrite); } } /* * Transaction run state tests. */ /** * Simple test of the transaction run state machine. */ public void test_runStateMachine_activeAbort() throws IOException { Journal journal = new Journal(getProperties()); assertTrue(journal.activeTx.isEmpty()); assertTrue(journal.preparedTx.isEmpty()); final long ts0 = newTx(journal); final ITx tx0 = journal.getTx(ts0); assertEquals(ts0, tx0.getStartTimestamp()); assertTrue(tx0 == journal.getTx(ts0)); assertTrue(tx0.isActive()); assertFalse(tx0.isPrepared()); assertFalse(tx0.isAborted()); assertFalse(tx0.isCommitted()); assertFalse(tx0.isComplete()); assertTrue(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.abort(ts0); /* * note: when the abort is asynchronous, i.e., for a read-write * transaction, this causes the test to wait until the abort task has * been executed. */ journal.commitService.shutdown(); assertFalse(tx0.isActive()); assertFalse(tx0.isPrepared()); assertTrue(tx0.isAborted()); assertFalse(tx0.isCommitted()); assertTrue(tx0.isComplete()); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.closeAndDelete(); } /** * Simple test of the transaction run state machine. */ public void test_runStateMachine_activePrepareAbort() throws IOException { Journal journal = new Journal(getProperties()); assertTrue(journal.activeTx.isEmpty()); assertTrue(journal.preparedTx.isEmpty()); final long ts0 = newTx(journal); final ITx tx0 = journal.getTx(ts0); assertEquals(ts0, tx0.getStartTimestamp()); assertTrue(tx0 == journal.getTx(ts0)); assertTrue( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertTrue(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); final long commitTime = (tx0.isReadOnly()?0L:journal.nextTimestamp()); tx0.prepare(commitTime); assertFalse( tx0.isActive() ); assertTrue( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertTrue(journal.preparedTx.containsKey(ts0)); tx0.abort(); assertFalse( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertTrue( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertTrue( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.closeAndDelete(); } /** * Simple test of the transaction run state machine. */ public void test_runStateMachine_activePrepareCommit() throws IOException { Journal journal = new Journal(getProperties()); assertTrue(journal.activeTx.isEmpty()); assertTrue(journal.preparedTx.isEmpty()); final long ts0 = newTx(journal); final ITx tx0 = journal.getTx(ts0); assertEquals(ts0, tx0.getStartTimestamp()); assertTrue(tx0 == journal.getTx(ts0)); assertTrue( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertTrue(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); final long commitTime = (tx0.isReadOnly() ? 0L : journal .nextTimestamp()); tx0.prepare(commitTime); assertFalse( tx0.isActive() ); assertTrue( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertTrue(journal.preparedTx.containsKey(ts0)); assertEquals(commitTime,tx0.commit()); assertFalse( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertTrue( tx0.isCommitted() ); assertTrue( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.closeAndDelete(); } /** * Simple test of the transaction run state machine. verifies that a 2nd * attempt to abort the same transaction results in an exception that does * not change the transaction run state. */ public void test_runStateMachine_activeAbortAbort_correctRejection() throws IOException { Journal journal = new Journal(getProperties()); assertTrue(journal.activeTx.isEmpty()); assertTrue(journal.preparedTx.isEmpty()); final long ts0 = newTx(journal); final ITx tx0 = journal.getTx(ts0); assertEquals(ts0, tx0.getStartTimestamp()); assertTrue(tx0 == journal.getTx(ts0)); assertTrue(tx0.isActive()); assertFalse(tx0.isPrepared()); assertFalse(tx0.isAborted()); assertFalse(tx0.isCommitted()); assertFalse(tx0.isComplete()); assertTrue(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); tx0.abort(); assertFalse(tx0.isActive()); assertFalse(tx0.isPrepared()); assertTrue(tx0.isAborted()); assertFalse(tx0.isCommitted()); assertTrue(tx0.isComplete()); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); try { tx0.abort(); fail("Expecting: " + IllegalStateException.class); } catch (IllegalStateException ex) { System.err.println("Ignoring expected exception: " + ex); } assertFalse(tx0.isActive()); assertFalse(tx0.isPrepared()); assertTrue(tx0.isAborted()); assertFalse(tx0.isCommitted()); assertTrue(tx0.isComplete()); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.closeAndDelete(); } /** * Simple test of the transaction run state machine verifies that a 2nd * attempt to prepare the same transaction results in an exception that * changes the transaction run state to 'aborted'. */ public void test_runStateMachine_activePreparePrepare_correctRejection() throws IOException { Journal journal = new Journal(getProperties()); assertTrue(journal.activeTx.isEmpty()); assertTrue(journal.preparedTx.isEmpty()); final long ts0 = newTx(journal); final ITx tx0 = journal.getTx(ts0); assertEquals(ts0, tx0.getStartTimestamp()); assertTrue(tx0 == journal.getTx(ts0)); assertTrue( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertTrue(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); final long commitTime = (tx0.isReadOnly() ? 0L : journal .nextTimestamp()); tx0.prepare(commitTime); assertFalse( tx0.isActive() ); assertTrue( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertTrue(journal.preparedTx.containsKey(ts0)); try { tx0.prepare(commitTime); fail("Expecting: "+IllegalStateException.class); } catch( IllegalStateException ex ) { System.err.println("Ignoring expected exception: "+ex); } assertFalse( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertTrue( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertTrue( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.closeAndDelete(); } /** * Simple test of the transaction run state machine verifies that a commit * out of order results in an exception that changes the transaction run * state to 'aborted'. */ public void test_runStateMachine_activeCommit_correctRejection() throws IOException { Journal journal = new Journal(getProperties()); assertTrue(journal.activeTx.isEmpty()); assertTrue(journal.preparedTx.isEmpty()); final long ts0 = newTx(journal); final ITx tx0 = journal.getTx(ts0); assertEquals(ts0, tx0.getStartTimestamp()); assertTrue(tx0 == journal.getTx(ts0)); assertTrue( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertFalse( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertFalse( tx0.isComplete() ); assertTrue(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); try { tx0.commit(); fail("Expecting: "+IllegalStateException.class); } catch( IllegalStateException ex ) { System.err.println("Ignoring expected exception: "+ex); } assertFalse( tx0.isActive() ); assertFalse( tx0.isPrepared() ); assertTrue( tx0.isAborted() ); assertFalse( tx0.isCommitted() ); assertTrue( tx0.isComplete() ); assertFalse(journal.activeTx.containsKey(ts0)); assertFalse(journal.preparedTx.containsKey(ts0)); journal.closeAndDelete(); } /** * Verifies that access to, and operations on, a named indices is denied * after a PREPARE. * * @throws IOException * * @todo also test after an abort. */ public void test_runStateMachine_prepared_correctRejection() throws IOException { Journal journal = new Journal(getProperties()); String name = "abc"; { journal.registerIndex(name, new UnisolatedBTree(journal)); journal.commit(); } final long tx0 = newTx(journal); ITx tmp = journal.getTx(tx0); assertNotNull(tmp); IIndex ndx = journal.getIndex(name,tx0); assertNotNull(ndx); // commit the journal. journal.commit(tx0); /* * Verify that you can not access a named index after 'prepare'. */ try { journal.getIndex(name,tx0); fail("Expecting: " + IllegalStateException.class); } catch (IllegalStateException ex) { System.err.println("Ignoring expected exception: " + ex); } /* * Verify that operations on an pre-existing index reference are now * denied. */ try { ndx.lookup(new byte[] { 1 }); fail("Expecting: " + IllegalStateException.class); } catch (IllegalStateException ex) { System.err.println("Ignoring expected exception: " + ex); } try { ndx.contains(new byte[] { 1 }); fail("Expecting: " + IllegalStateException.class); } catch (IllegalStateException ex) { System.err.println("Ignoring expected exception: " + ex); } try { ndx.remove(new byte[] { 1 }); fail("Expecting: " + IllegalStateException.class); } catch (IllegalStateException ex) { System.err.println("Ignoring expected exception: " + ex); } try { ndx.insert(new byte[] { 1 }, new byte[] { 2 }); fail("Expecting: " + IllegalStateException.class); } catch (IllegalStateException ex) { System.err.println("Ignoring expected exception: " + ex); } assertFalse(tmp.isActive()); assertTrue(tmp.isPrepared()); assertFalse(tmp.isAborted()); assertFalse(tmp.isCommitted()); assertFalse(tmp.isComplete()); assertFalse(journal.activeTx.containsKey(tmp.getStartTimestamp())); assertFalse(journal.preparedTx.containsKey(tmp.getStartTimestamp())); assertNull(journal.getTx(tmp.getStartTimestamp())); journal.closeAndDelete(); } // /** // * Verifies that access to, and operations on, a named indices is denied // * after an ABORT. // * // * @throws IOException // */ // public void test_runStateMachine_aborted_correctRejection() // throws IOException { // // final Properties properties = getProperties(); // // Journal journal = new Journal(properties); // // String name = "abc"; // // { // // journal.registerIndex(name, new UnisolatedBTree(journal)); // // journal.commit(); // // } // // ITx tx0 = journal.newTx(); // // IIndex ndx = tx0.getIndex(name); // // assertNotNull(ndx); // // tx0.abort(); // // /* // * Verify that you can not access a named index. // */ // try { // tx0.getIndex(name); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // // /* // * Verify that operations on an pre-existing index reference are now // * denied. // */ // try { // ndx.lookup(new byte[] { 1 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // try { // ndx.contains(new byte[] { 1 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // try { // ndx.remove(new byte[] { 1 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // try { // ndx.insert(new byte[] { 1 }, new byte[] { 2 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // // assertFalse(tx0.isActive()); // assertFalse(tx0.isPrepared()); // assertTrue (tx0.isAborted()); // assertFalse(tx0.isCommitted()); // assertTrue (tx0.isComplete()); // // assertFalse(journal.activeTx.containsKey(tx0.getStartTimestamp())); // assertFalse(journal.preparedTx.containsKey(tx0.getStartTimestamp())); // assertNull(journal.getTx(tx0.getStartTimestamp())); // // journal.close(); // // } // // /** // * Verifies that access to, and operations on, a named indices is denied // * after a COMMIT. // * // * @throws IOException // */ // public void test_runStateMachine_commit_correctRejection() // throws IOException { // // final Properties properties = getProperties(); // // Journal journal = new Journal(properties); // // String name = "abc"; // // { // // journal.registerIndex(name, new UnisolatedBTree(journal)); // // journal.commit(); // // } // // ITx tx0 = journal.newTx(); // // IIndex ndx = tx0.getIndex(name); // // assertNotNull(ndx); // // tx0.prepare(); // tx0.commit(); // // /* // * Verify that you can not access a named index. // */ // try { // tx0.getIndex(name); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // // /* // * Verify that operations on an pre-existing index reference are now // * denied. // */ // try { // ndx.lookup(new byte[] { 1 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // try { // ndx.contains(new byte[] { 1 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // try { // ndx.remove(new byte[] { 1 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // try { // ndx.insert(new byte[] { 1 }, new byte[] { 2 }); // fail("Expecting: " + IllegalStateException.class); // } catch (IllegalStateException ex) { // System.err.println("Ignoring expected exception: " + ex); // } // // assertFalse(tx0.isActive()); // assertFalse(tx0.isPrepared()); // assertFalse(tx0.isAborted()); // assertTrue(tx0.isCommitted()); // assertTrue(tx0.isComplete()); // // assertFalse(journal.activeTx.containsKey(tx0.getStartTimestamp())); // assertFalse(journal.preparedTx.containsKey(tx0.getStartTimestamp())); // assertNull(journal.getTx(tx0.getStartTimestamp())); // // journal.close(); // // } } Index: TestReadOnlyTx.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/journal/TestReadOnlyTx.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TestReadOnlyTx.java 22 Feb 2007 16:59:34 -0000 1.4 --- TestReadOnlyTx.java 28 Feb 2007 13:59:09 -0000 1.5 *************** *** 48,53 **** package com.bigdata.journal; - import java.util.Properties; - import com.bigdata.isolation.UnisolatedBTree; import com.bigdata.objndx.IIndex; --- 48,51 ---- *************** *** 109,113 **** */ ! final long tx1 = journal.newTx(true); IIndex ndx = journal.getIndex(name,tx1); --- 107,111 ---- */ ! final long tx1 = journal.newTx(IsolationEnum.ReadOnly); IIndex ndx = journal.getIndex(name,tx1); *************** *** 135,139 **** */ ! final long tx1 = journal.newTx(true); IIndex ndx = journal.getIndex(name,tx1); --- 133,137 ---- */ ! final long tx1 = journal.newTx(IsolationEnum.ReadOnly); IIndex ndx = journal.getIndex(name,tx1); |