public void test_rangeIterator(){
  final byte[] k3=i2k(3);
  final byte[] k5=i2k(5);
  final byte[] k7=i2k(7);
  final byte[] v3a=new byte[]{3};
  final byte[] v5a=new byte[]{5};
  final IRawStore store=new SimpleMemoryRawStore();
  final BTree btree1, btree2;
{
    final IndexMetadata md=new IndexMetadata(UUID.randomUUID());
    md.setBranchingFactor(3);
    md.setDeleteMarkers(true);
    md.setTupleSerializer(NOPTupleSerializer.INSTANCE);
    btree1=BTree.create(store,md);
    btree2=BTree.create(store,md.clone());
  }
  final FusedView view=new FusedView(new AbstractBTree[]{btree1,btree2});
  assertEquals(0,btree1.rangeCount(null,null));
  assertEquals(0,btree2.rangeCount(null,null));
  assertEquals(0,view.rangeCount(null,null));
  assertEquals(0,view.rangeCountExact(null,null));
  assertEquals(0,view.rangeCountExactWithDeleted(null,null));
  assertSameIterator(new byte[][]{},btree1.rangeIterator(null,null));
  assertSameIterator(new byte[][]{},btree2.rangeIterator(null,null));
  assertSameIterator(new byte[][]{},view.rangeIterator(null,null));
  assertFalse(view.contains(k3));
  assertFalse(view.contains(k5));
  assertFalse(view.contains(k7));
  btree2.insert(k3,v3a);
  assertEquals(0,btree1.rangeCount(null,null));
  assertEquals(1,btree2.rangeCount(null,null));
  assertEquals(1,view.rangeCount(null,null));
  assertEquals(1,view.rangeCountExact(null,null));
  assertEquals(1,view.rangeCountExactWithDeleted(null,null));
  assertSameIterator(new byte[][]{},btree1.rangeIterator(null,null));
  assertSameIterator(new byte[][]{v3a},btree2.rangeIterator(null,null));
  assertSameIterator(new byte[][]{v3a},view.rangeIterator(null,null));
  assertTrue(view.contains(k3));
  assertFalse(view.contains(k5));
  assertFalse(view.contains(k7));
  btree1.insert(k5,v5a);
  assertEquals(1,btree1.rangeCount(null,null));
  assertEquals(1,btree2.rangeCount(null,null));
  assertEquals(2,view.rangeCount(null,null));
  assertEquals(2,view.rangeCountExact(null,null));
  assertEquals(2,view.rangeCountExactWithDeleted(null,null));
  assertSameIterator(new byte[][]{v5a},btree1.rangeIterator(null,null));
  assertSameIterator(new byte[][]{v3a},btree2.rangeIterator(null,null));
  assertSameIterator(new byte[][]{v3a,v5a},view.rangeIterator(null,null));
  assertTrue(view.contains(k3));
  assertTrue(view.contains(k5));
  assertFalse(view.contains(k7));
  btree1.remove(k3);
  assertEquals(2,btree1.rangeCount(null,null));
  assertEquals(1,btree2.rangeCount(null,null));
  assertEquals(3,view.rangeCount(null,null));
  assertEquals(1,view.rangeCountExact(null,null));
  assertEquals(2,view.rangeCountExactWithDeleted(null,null));
  assertSameIterator(new byte[][]{v5a},btree1.rangeIterator(null,null));
  assertSameIterator(new byte[][]{null,v5a},btree1.rangeIterator(null,null,0,IRangeQuery.DEFAULT | IRangeQuery.DELETED,null));
  assertSameIterator(new byte[][]{v3a},btree2.rangeIterator(null,null));
  assertSameIterator(new byte[][]{v5a},view.rangeIterator(null,null));
  assertFalse(view.contains(k3));
  assertTrue(view.contains(k5));
  assertFalse(view.contains(k7));
}

public void test_rangeIterator ( ) { final byte [ ] k3 = i2k ( 3 ) ; final byte [ ] k5 = i2k ( 5 ) ; final byte [ ] k7 = i2k ( 7 ) ; final byte [ ] v3a = new byte [ ] { 3 } ; final byte [ ] v5a = new byte [ ] { 5 } ; final IRawStore store = new SimpleMemoryRawStore ( ) ; final BTree btree1 , btree2 ; { final IndexMetadata md = new IndexMetadata ( UUID . randomUUID ( ) ) ; md . setBranchingFactor ( 3 ) ; md . setDeleteMarkers ( true ) ; md . setTupleSerializer ( NOPTupleSerializer . INSTANCE ) ; btree1 = BTree . create ( store , md ) ; btree2 = BTree . create ( store , md . clone ( ) ) ; } final FusedView view = new FusedView ( new AbstractBTree [ ] { btree1 , btree2 } ) ; assertEquals ( 0 , btree1 . rangeCount ( null , null ) ) ; assertEquals ( 0 , btree2 . rangeCount ( null , null ) ) ; assertEquals ( 0 , view . rangeCount ( null , null ) ) ; assertEquals ( 0 , view . rangeCountExact ( null , null ) ) ; assertEquals ( 0 , view . rangeCountExactWithDeleted ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { } , btree1 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { } , btree2 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { } , view . rangeIterator ( null , null ) ) ; assertFalse ( view . contains ( k3 ) ) ; assertFalse ( view . contains ( k5 ) ) ; assertFalse ( view . contains ( k7 ) ) ; btree2 . insert ( k3 , v3a ) ; assertEquals ( 0 , btree1 . rangeCount ( null , null ) ) ; assertEquals ( 1 , btree2 . rangeCount ( null , null ) ) ; assertEquals ( 1 , view . rangeCount ( null , null ) ) ; assertEquals ( 1 , view . rangeCountExact ( null , null ) ) ; assertEquals ( 1 , view . rangeCountExactWithDeleted ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { } , btree1 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v3a } , btree2 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v3a } , view . rangeIterator ( null , null ) ) ; assertTrue ( view . contains ( k3 ) ) ; assertFalse ( view . contains ( k5 ) ) ; assertFalse ( view . contains ( k7 ) ) ; btree1 . insert ( k5 , v5a ) ; assertEquals ( 1 , btree1 . rangeCount ( null , null ) ) ; assertEquals ( 1 , btree2 . rangeCount ( null , null ) ) ; assertEquals ( 2 , view . rangeCount ( null , null ) ) ; assertEquals ( 2 , view . rangeCountExact ( null , null ) ) ; assertEquals ( 2 , view . rangeCountExactWithDeleted ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v5a } , btree1 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v3a } , btree2 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v3a , v5a } , view . rangeIterator ( null , null ) ) ; assertTrue ( view . contains ( k3 ) ) ; assertTrue ( view . contains ( k5 ) ) ; assertFalse ( view . contains ( k7 ) ) ; btree1 . remove ( k3 ) ; assertEquals ( 2 , btree1 . rangeCount ( null , null ) ) ; assertEquals ( 1 , btree2 . rangeCount ( null , null ) ) ; assertEquals ( 3 , view . rangeCount ( null , null ) ) ; assertEquals ( 1 , view . rangeCountExact ( null , null ) ) ; assertEquals ( 2 , view . rangeCountExactWithDeleted ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v5a } , btree1 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { null , v5a } , btree1 . rangeIterator ( null , null , 0 , IRangeQuery . DEFAULT | IRangeQuery . DELETED , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v3a } , btree2 . rangeIterator ( null , null ) ) ; assertSameIterator ( new byte [ ] [ ] { v5a } , view . rangeIterator ( null , null ) ) ; assertFalse ( view . contains ( k3 ) ) ; assertTrue ( view . contains ( k5 ) ) ; assertFalse ( view . contains ( k7 ) ) ; }
test verifies some of the basic principles of the fused view , including that a deleted entry in the first source will mask an undeleted entry in a secondary source .
