Program: 132496
Project: 132496
Buggy source:
public void testSnapshots() throws Exception {
  byte[][] keys=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  byte[][] vals=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  LSMTree tree=new LSMTree(null,new DefaultByteRangeComparator());
  SortedMap<byte[],byte[]> map=new TreeMap<byte[],byte[]>(new DefaultByteRangeComparator());
  for (int i=0; i < keys.length; i++) {
    tree.insert(keys[i],vals[i]);
    map.put(keys[i],vals[i]);
  }
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  int snapId=tree.createSnapshot();
  tree.materializeSnapshot(SNAP_FILE,snapId);
  tree.linkToSnapshot(SNAP_FILE);
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  byte[][] newKeys=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  byte[][] newVals=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  for (int i=0; i < newKeys.length; i++) {
    tree.insert(newKeys[i],newVals[i]);
    map.put(newKeys[i],newVals[i]);
  }
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  snapId=tree.createSnapshot();
  tree.materializeSnapshot(SNAP_FILE2,snapId);
  tree.linkToSnapshot(SNAP_FILE2);
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
}

Fixed version (ground truth):
public void testSnapshots() throws Exception {
  byte[][] keys=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  byte[][] vals=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  LSMTree tree=new LSMTree(null,new DefaultByteRangeComparator());
  SortedMap<byte[],byte[]> map=new TreeMap<byte[],byte[]>(new DefaultByteRangeComparator());
  for (int i=0; i < keys.length; i++) {
    tree.insert(keys[i],vals[i]);
    map.put(keys[i],vals[i]);
  }
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  int snapId=tree.createSnapshot();
  tree.materializeSnapshot(SNAP_FILE,snapId);
  tree.linkToSnapshot(SNAP_FILE);
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  byte[][] newKeys=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes()};
  byte[][] newVals=new byte[][]{"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),"String_Node_Str".getBytes(),null};
  for (int i=0; i < newKeys.length; i++) {
    tree.insert(newKeys[i],newVals[i]);
    if (newVals[i] != null)     map.put(newKeys[i],newVals[i]);
 else     map.remove(newKeys[i]);
  }
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  Iterator<Entry<byte[],byte[]>> it=tree.prefixLookup(new byte[0]);
  Iterator<Entry<byte[],byte[]>> entries=map.entrySet().iterator();
  int count=0;
  for (; it.hasNext(); count++) {
    Entry<byte[],byte[]> entry=it.next();
    Entry<byte[],byte[]> mapEntry=entries.next();
    assertEquals(new String(entry.getKey()),new String(mapEntry.getKey()));
    assertEquals(new String(entry.getValue()),new String(mapEntry.getValue()));
  }
  assertEquals(map.size(),count);
  snapId=tree.createSnapshot();
  tree.materializeSnapshot(SNAP_FILE2,snapId);
  tree.linkToSnapshot(SNAP_FILE2);
  for (  byte[] key : map.keySet())   assertEquals(new String(map.get(key)),new String(tree.lookup(key)));
  for (  byte[] key : keys) {
    map.remove(key);
    tree.delete(key);
  }
  for (  byte[] key : newKeys) {
    map.remove(key);
    tree.delete(key);
  }
  assertEquals(0,map.size());
  assertFalse(tree.prefixLookup(new byte[0]).hasNext());
  snapId=tree.createSnapshot();
  tree.materializeSnapshot(SNAP_FILE3,snapId);
  tree.linkToSnapshot(SNAP_FILE3);
  it=tree.prefixLookup(new byte[0]);
  assertFalse(it.hasNext());
}