public void test_concurrent_modification_copy_on_write(){
  final BTree btree;
{
    final IndexMetadata md=new IndexMetadata(UUID.randomUUID());
    md.setBranchingFactor(3);
    btree=BTree.create(new SimpleMemoryRawStore(),md);
    btree.insert(10,"Bryan");
    btree.insert(20,"Mike");
    btree.insert(30,"James");
  }
{
    final ITupleCursor2<String> cursor=newCursor(btree);
    btree.writeCheckpoint2();
    assertTrue(cursor.hasNext());
    assertEquals(new TestTuple<String>(10,"Bryan"),cursor.next());
    btree.remove(10);
    assertEquals(TestKeyBuilder.asSortKey(10),cursor.currentKey());
    assertEquals(null,cursor.tuple());
    assertEquals(new TestTuple<String>(20,"Mike"),cursor.next());
    assertEquals(TestKeyBuilder.asSortKey(20),cursor.currentKey());
    btree.writeCheckpoint2();
    btree.insert(10,"Bryan");
    assertEquals(TestKeyBuilder.asSortKey(20),cursor.currentKey());
    assertEquals(new TestTuple<String>(20,"Mike"),cursor.tuple());
    assertEquals(new TestTuple<String>(10,"Bryan"),cursor.prior());
  }
}

public void test_concurrent_modification_copy_on_write ( ) { final BTree btree ; { final IndexMetadata md = new IndexMetadata ( UUID . randomUUID ( ) ) ; md . setBranchingFactor ( 3 ) ; btree = BTree . create ( new SimpleMemoryRawStore ( ) , md ) ; btree . insert ( 10 , "Bryan" ) ; btree . insert ( 20 , "Mike" ) ; btree . insert ( 30 , "James" ) ; } { final ITupleCursor2 < String > cursor = newCursor ( btree ) ; btree . writeCheckpoint2 ( ) ; assertTrue ( cursor . hasNext ( ) ) ; assertEquals ( new TestTuple < String > ( 10 , "Bryan" ) , cursor . next ( ) ) ; btree . remove ( 10 ) ; assertEquals ( TestKeyBuilder . asSortKey ( 10 ) , cursor . currentKey ( ) ) ; assertEquals ( null , cursor . tuple ( ) ) ; assertEquals ( new TestTuple < String > ( 20 , "Mike" ) , cursor . next ( ) ) ; assertEquals ( TestKeyBuilder . asSortKey ( 20 ) , cursor . currentKey ( ) ) ; btree . writeCheckpoint2 ( ) ; btree . insert ( 10 , "Bryan" ) ; assertEquals ( TestKeyBuilder . asSortKey ( 20 ) , cursor . currentKey ( ) ) ; assertEquals ( new TestTuple < String > ( 20 , "Mike" ) , cursor . tuple ( ) ) ; assertEquals ( new TestTuple < String > ( 10 , "Bryan" ) , cursor . prior ( ) ) ; } }
unit test for copy - on - write ( the leaf is clean and then an update , insert , or remove is requested which forces copy - on - write to clone the leaf ) . the listener needs to notice the event and relocate itself within the btree .
