From: Bryan T. <tho...@us...> - 2007-02-21 20:17:58
|
Update of /cvsroot/cweb/bigdata/src/test/com/bigdata/rawstore In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv5461/src/test/com/bigdata/rawstore Modified Files: AbstractRawStoreTestCase.java Log Message: Further work supporting transactional isolation. Index: AbstractRawStoreTestCase.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/rawstore/AbstractRawStoreTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AbstractRawStoreTestCase.java 9 Feb 2007 16:13:17 -0000 1.1 --- AbstractRawStoreTestCase.java 21 Feb 2007 20:17:20 -0000 1.2 *************** *** 93,102 **** * @param actual * Buffer. */ ! public void assertEquals(byte[] expected, ByteBuffer actual ) { if( expected == null ) throw new IllegalArgumentException(); if( actual == null ) fail("actual is null"); /* Create a read-only view on the buffer so that we do not mess with --- 93,113 ---- * @param actual * Buffer. + * + * @todo optimize test helper when ByteBuffer is backed by an array, but + * also compensate for the arrayOffset. */ ! static public void assertEquals(byte[] expected, ByteBuffer actual ) { if( expected == null ) throw new IllegalArgumentException(); if( actual == null ) fail("actual is null"); + + if(actual.hasArray() && actual.arrayOffset()==0) { + + assertEquals(expected,actual.array()); + + return; + + } /* Create a read-only view on the buffer so that we do not mess with *************** *** 185,189 **** try { ! store.read( 0L, null); fail("Expecting: "+IllegalArgumentException.class); --- 196,200 ---- try { ! store.read( 0L ); fail("Expecting: "+IllegalArgumentException.class); *************** *** 212,216 **** final int offset = 10; ! store.read( Addr.toLong(nbytes, offset), null); fail("Expecting: "+IllegalArgumentException.class); --- 223,227 ---- final int offset = 10; ! store.read( Addr.toLong(nbytes, offset) ); fail("Expecting: "+IllegalArgumentException.class); *************** *** 237,241 **** final int offset = 0; ! store.read( Addr.toLong(nbytes, offset), null); fail("Expecting: "+IllegalArgumentException.class); --- 248,252 ---- final int offset = 0; ! store.read( Addr.toLong(nbytes, offset) ); fail("Expecting: "+IllegalArgumentException.class); *************** *** 347,351 **** // read the data back. ! ByteBuffer actual = store.read(addr1,null); assertEquals(expected,actual); --- 358,362 ---- // read the data back. ! ByteBuffer actual = store.read(addr1); assertEquals(expected,actual); *************** *** 387,391 **** { // read the data back. ! ByteBuffer actual = store.read(addr1, null); assertEquals(expected, actual); --- 398,402 ---- { // read the data back. ! ByteBuffer actual = store.read(addr1); assertEquals(expected, actual); *************** *** 403,407 **** { // read the data back. ! ByteBuffer actual2 = store.read(addr1, null); assertEquals(expected, actual2); --- 414,418 ---- { // read the data back. ! ByteBuffer actual2 = store.read(addr1); assertEquals(expected, actual2); *************** *** 416,755 **** } ! /** ! * Test verifies read behavior when the offered buffer has exactly the ! * required #of bytes of remaining. ! */ ! public void test_writeReadWith2ndBuffer_exactCapacity() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len); ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // verify the data are record correct. ! assertEquals(expected1,actual); ! ! /* ! * the caller's buffer MUST be used since it has sufficient bytes ! * remaining ! */ ! assertTrue("Caller's buffer was not used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len,actual.limit()); ! ! } ! ! public void test_writeReadWith2ndBuffer_excessCapacity_zeroPosition() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len+1); ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // verify the data are record correct. ! assertEquals(expected1,actual); ! ! /* ! * the caller's buffer MUST be used since it has sufficient bytes ! * remaining ! */ ! assertTrue("Caller's buffer was not used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len,actual.limit()); ! ! } ! ! public void test_writeReadWith2ndBuffer_excessCapacity_nonZeroPosition() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len+2); ! buf.position(1); // advance the position by one byte. ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // copy the expected data leaving the first byte zero. ! byte[] expected2 = new byte[len+1]; ! System.arraycopy(expected1, 0, expected2, 1, expected1.length); ! ! // verify the data are record correct. ! assertEquals(expected2,actual); ! ! /* ! * the caller's buffer MUST be used since it has sufficient bytes ! * remaining ! */ ! assertTrue("Caller's buffer was not used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len+1,actual.limit()); ! ! } ! ! /** ! * Test verifies read behavior when the offered buffer does not have ! * sufficient remaining capacity. ! */ ! public void test_writeReadWith2ndBuffer_wouldUnderflow_nonZeroPosition() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer that is large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len); ! buf.position(1); // but advance the position so that there is not enough room. ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // verify the data are record correct. ! assertEquals(expected1,actual); ! ! /* ! * the caller's buffer MUST NOT be used since it does not have ! * sufficient bytes remaining. ! */ ! assertFalse("Caller's buffer was used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len,actual.limit()); ! ! } ! ! /** ! * Test verifies read behavior when the offered buffer does not have ! * sufficient remaining capacity. ! */ ! public void test_writeReadWith2ndBuffer_wouldUnderflow_zeroPosition() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer that is not large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len-1); ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // verify the data are record correct. ! assertEquals(expected1,actual); ! ! /* ! * the caller's buffer MUST NOT be used since it does not have ! * sufficient bytes remaining. ! */ ! assertFalse("Caller's buffer was used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len,actual.limit()); ! ! } ! ! /** ! * Test verifies that an oversized buffer provided to ! * {@link IRawStore#read(long, ByteBuffer)} will not cause more bytes to be ! * read than are indicated by the {@link Addr address}. ! */ ! public void test_writeReadWith2ndBuffer_wouldOverflow_zeroPosition() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer that is more than large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len+1); ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // verify the data are record correct - only [len] bytes should be copied. ! assertEquals(expected1,actual); ! ! /* ! * the caller's buffer MUST be used since it has sufficient bytes ! * remaining. ! */ ! assertTrue("Caller's buffer was used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len,actual.limit()); ! ! } ! ! /** ! * Test verifies that an oversized buffer provided to ! * {@link IRawStore#read(long, ByteBuffer)} will not cause more bytes to be ! * read than are indicated by the {@link Addr address}. ! */ ! public void test_writeReadWith2ndBuffer_wouldOverflow_nonZeroPosition() { ! ! IRawStore store = getStore(); ! ! Random r = new Random(); ! ! final int len = 100; ! ! byte[] expected1 = new byte[len]; ! ! r.nextBytes(expected1); ! ! ByteBuffer tmp = ByteBuffer.wrap(expected1); ! ! long addr1 = store.write(tmp); ! ! // verify that the position is advanced to the limit. ! assertEquals(len,tmp.position()); ! assertEquals(tmp.position(),tmp.limit()); ! ! // a buffer that is more than large enough to hold the record. ! ByteBuffer buf = ByteBuffer.allocate(len+2); ! ! // non-zero position. ! buf.position(1); ! ! // read the data, offering our buffer. ! ByteBuffer actual = store.read(addr1, buf); ! ! // copy the expected data leaving the first byte zero. ! byte[] expected2 = new byte[len+1]; ! System.arraycopy(expected1, 0, expected2, 1, expected1.length); ! ! // verify the data are record correct - only [len] bytes should be copied. ! assertEquals(expected2,actual); ! ! /* ! * the caller's buffer MUST be used since it has sufficient bytes ! * remaining. ! */ ! assertTrue("Caller's buffer was used.", actual==buf); ! ! /* ! * verify the position and limit after the read. ! */ ! assertEquals(0,actual.position()); ! assertEquals(len+1,actual.limit()); ! ! } ! /** * Test verifies that write does not permit changes to the store state by --- 427,766 ---- } ! // /** ! // * Test verifies read behavior when the offered buffer has exactly the ! // * required #of bytes of remaining. ! // */ ! // public void test_writeReadWith2ndBuffer_exactCapacity() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len); ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // verify the data are record correct. ! // assertEquals(expected1,actual); ! // ! // /* ! // * the caller's buffer MUST be used since it has sufficient bytes ! // * remaining ! // */ ! // assertTrue("Caller's buffer was not used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len,actual.limit()); ! // ! // } ! // ! // public void test_writeReadWith2ndBuffer_excessCapacity_zeroPosition() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len+1); ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // verify the data are record correct. ! // assertEquals(expected1,actual); ! // ! // /* ! // * the caller's buffer MUST be used since it has sufficient bytes ! // * remaining ! // */ ! // assertTrue("Caller's buffer was not used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len,actual.limit()); ! // ! // } ! // ! // public void test_writeReadWith2ndBuffer_excessCapacity_nonZeroPosition() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len+2); ! // buf.position(1); // advance the position by one byte. ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // copy the expected data leaving the first byte zero. ! // byte[] expected2 = new byte[len+1]; ! // System.arraycopy(expected1, 0, expected2, 1, expected1.length); ! // ! // // verify the data are record correct. ! // assertEquals(expected2,actual); ! // ! // /* ! // * the caller's buffer MUST be used since it has sufficient bytes ! // * remaining ! // */ ! // assertTrue("Caller's buffer was not used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len+1,actual.limit()); ! // ! // } ! // ! // /** ! // * Test verifies read behavior when the offered buffer does not have ! // * sufficient remaining capacity. ! // */ ! // public void test_writeReadWith2ndBuffer_wouldUnderflow_nonZeroPosition() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer that is large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len); ! // buf.position(1); // but advance the position so that there is not enough room. ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // verify the data are record correct. ! // assertEquals(expected1,actual); ! // ! // /* ! // * the caller's buffer MUST NOT be used since it does not have ! // * sufficient bytes remaining. ! // */ ! // assertFalse("Caller's buffer was used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len,actual.limit()); ! // ! // } ! // ! // /** ! // * Test verifies read behavior when the offered buffer does not have ! // * sufficient remaining capacity. ! // */ ! // public void test_writeReadWith2ndBuffer_wouldUnderflow_zeroPosition() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer that is not large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len-1); ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // verify the data are record correct. ! // assertEquals(expected1,actual); ! // ! // /* ! // * the caller's buffer MUST NOT be used since it does not have ! // * sufficient bytes remaining. ! // */ ! // assertFalse("Caller's buffer was used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len,actual.limit()); ! // ! // } ! // ! // /** ! // * Test verifies that an oversized buffer provided to ! // * {@link IRawStore#read(long, ByteBuffer)} will not cause more bytes to be ! // * read than are indicated by the {@link Addr address}. ! // */ ! // public void test_writeReadWith2ndBuffer_wouldOverflow_zeroPosition() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer that is more than large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len+1); ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // verify the data are record correct - only [len] bytes should be copied. ! // assertEquals(expected1,actual); ! // ! // /* ! // * the caller's buffer MUST be used since it has sufficient bytes ! // * remaining. ! // */ ! // assertTrue("Caller's buffer was used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len,actual.limit()); ! // ! // } ! // ! // /** ! // * Test verifies that an oversized buffer provided to ! // * {@link IRawStore#read(long, ByteBuffer)} will not cause more bytes to be ! // * read than are indicated by the {@link Addr address}. ! // */ ! // public void test_writeReadWith2ndBuffer_wouldOverflow_nonZeroPosition() { ! // ! // IRawStore store = getStore(); ! // ! // Random r = new Random(); ! // ! // final int len = 100; ! // ! // byte[] expected1 = new byte[len]; ! // ! // r.nextBytes(expected1); ! // ! // ByteBuffer tmp = ByteBuffer.wrap(expected1); ! // ! // long addr1 = store.write(tmp); ! // ! // // verify that the position is advanced to the limit. ! // assertEquals(len,tmp.position()); ! // assertEquals(tmp.position(),tmp.limit()); ! // ! // // a buffer that is more than large enough to hold the record. ! // ByteBuffer buf = ByteBuffer.allocate(len+2); ! // ! // // non-zero position. ! // buf.position(1); ! // ! // // read the data, offering our buffer. ! // ByteBuffer actual = store.read(addr1, buf); ! // ! // // copy the expected data leaving the first byte zero. ! // byte[] expected2 = new byte[len+1]; ! // System.arraycopy(expected1, 0, expected2, 1, expected1.length); ! // ! // // verify the data are record correct - only [len] bytes should be copied. ! // assertEquals(expected2,actual); ! // ! // /* ! // * the caller's buffer MUST be used since it has sufficient bytes ! // * remaining. ! // */ ! // assertTrue("Caller's buffer was used.", actual==buf); ! // ! // /* ! // * verify the position and limit after the read. ! // */ ! // assertEquals(0,actual.position()); ! // assertEquals(len+1,actual.limit()); ! // ! // } ! // /** * Test verifies that write does not permit changes to the store state by *************** *** 779,783 **** // verify read. ! assertEquals(expected1,store.read(addr1, null)); // clone the data. --- 790,794 ---- // verify read. ! assertEquals(expected1,store.read(addr1)); // clone the data. *************** *** 791,795 **** * the store. */ ! assertEquals(expected2,store.read(addr1, null)); } --- 802,806 ---- * the store. */ ! assertEquals(expected2,store.read(addr1)); } *************** *** 819,823 **** assertEquals(tmp.position(),tmp.limit()); ! ByteBuffer actual = store.read(addr1, null); assertEquals(expected1,actual); --- 830,834 ---- assertEquals(tmp.position(),tmp.limit()); ! ByteBuffer actual = store.read(addr1); assertEquals(expected1,actual); *************** *** 841,845 **** // verify no change in store state. ! assertEquals(expected1,store.read(addr1, null)); } --- 852,856 ---- // verify no change in store state. ! assertEquals(expected1,store.read(addr1)); } *************** *** 881,885 **** assertEquals(tmp.position(),tmp.limit()); ! assertEquals(expected,store.read(addr, null)); addrs[i] = addr; --- 892,896 ---- assertEquals(tmp.position(),tmp.limit()); ! assertEquals(expected,store.read(addr)); addrs[i] = addr; *************** *** 901,905 **** byte[] expected = records[order[i]]; ! assertEquals(expected,store.read(addr, null)); } --- 912,916 ---- byte[] expected = records[order[i]]; ! assertEquals(expected,store.read(addr)); } |