Program: 19459
Project: 19459
Buggy source:
/** 
 * Check the listener is getting reads
 */
@Test public void testCacheEntryListener(){
  MyCacheEntryListener<Long,String> listener=new MyCacheEntryListener<Long,String>();
  cache.registerCacheEntryListener(listener,false,null,true);
  assertEquals(0,listener.getCreated());
  assertEquals(0,listener.getUpdated());
  assertEquals(0,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.put(1l,"String_Node_Str");
  assertEquals(1,listener.getCreated());
  assertEquals(0,listener.getUpdated());
  assertEquals(0,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  Map<Long,String> entries=new HashMap<Long,String>();
  entries.put(2l,"String_Node_Str");
  entries.put(3l,"String_Node_Str");
  cache.putAll(entries);
  assertEquals(3,listener.getCreated());
  assertEquals(0,listener.getUpdated());
  assertEquals(0,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.put(1l,"String_Node_Str");
  assertEquals(3,listener.getCreated());
  assertEquals(1,listener.getUpdated());
  assertEquals(0,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.putAll(entries);
  assertEquals(3,listener.getCreated());
  assertEquals(3,listener.getUpdated());
  assertEquals(0,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.getAndPut(4l,"String_Node_Str");
  assertEquals(4,listener.getCreated());
  assertEquals(3,listener.getUpdated());
  assertEquals(0,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.getAndPut(4l,"String_Node_Str");
  assertEquals(4,listener.getCreated());
  assertEquals(4,listener.getUpdated());
  assertEquals(1,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  String value=cache.get(1l);
  assertEquals(4,listener.getCreated());
  assertEquals(4,listener.getUpdated());
  assertEquals(2,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  String result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      assertEquals("String_Node_Str",arguments[0]);
      assertEquals("String_Node_Str",arguments[1]);
      assertEquals("String_Node_Str",arguments[2]);
      return entry.getValue();
    }
  }
,"String_Node_Str","String_Node_Str","String_Node_Str");
  assertEquals(value,result);
  assertEquals(4,listener.getCreated());
  assertEquals(4,listener.getUpdated());
  assertEquals(3,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      entry.setValue("String_Node_Str");
      return entry.getValue();
    }
  }
);
  assertEquals("String_Node_Str",result);
  assertEquals(4,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(3,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      entry.remove();
      return entry.getValue();
    }
  }
);
  assertNull(result);
  assertEquals(4,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(3,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(1,listener.getRemoved());
  result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      entry.setValue("String_Node_Str");
      return entry.getValue();
    }
  }
);
  assertEquals("String_Node_Str",result);
  assertEquals(5,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(3,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(1,listener.getRemoved());
  Iterator<Cache.Entry<Long,String>> iterator=cache.iterator();
  while (iterator.hasNext()) {
    iterator.next();
    iterator.remove();
  }
  assertEquals(5,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(7,listener.getReads());
  assertEquals(0,listener.getExpired());
  assertEquals(5,listener.getRemoved());
}

Fixed version (ground truth):
/** 
 * Check the listener is getting reads
 */
@Test public void testCacheEntryListener(){
  MyCacheEntryListener<Long,String> listener=new MyCacheEntryListener<Long,String>();
  cache.registerCacheEntryListener(listener,false,null,true);
  assertEquals(0,listener.getCreated());
  assertEquals(0,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.put(1l,"String_Node_Str");
  assertEquals(1,listener.getCreated());
  assertEquals(0,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  Map<Long,String> entries=new HashMap<Long,String>();
  entries.put(2l,"String_Node_Str");
  entries.put(3l,"String_Node_Str");
  cache.putAll(entries);
  assertEquals(3,listener.getCreated());
  assertEquals(0,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.put(1l,"String_Node_Str");
  assertEquals(3,listener.getCreated());
  assertEquals(1,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.putAll(entries);
  assertEquals(3,listener.getCreated());
  assertEquals(3,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.getAndPut(4l,"String_Node_Str");
  assertEquals(4,listener.getCreated());
  assertEquals(3,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  cache.getAndPut(4l,"String_Node_Str");
  assertEquals(4,listener.getCreated());
  assertEquals(4,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  String value=cache.get(1l);
  assertEquals(4,listener.getCreated());
  assertEquals(4,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  String result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      assertEquals("String_Node_Str",arguments[0]);
      assertEquals("String_Node_Str",arguments[1]);
      assertEquals("String_Node_Str",arguments[2]);
      return entry.getValue();
    }
  }
,"String_Node_Str","String_Node_Str","String_Node_Str");
  assertEquals(value,result);
  assertEquals(4,listener.getCreated());
  assertEquals(4,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      entry.setValue("String_Node_Str");
      return entry.getValue();
    }
  }
);
  assertEquals("String_Node_Str",result);
  assertEquals(4,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(0,listener.getRemoved());
  result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      entry.remove();
      return entry.getValue();
    }
  }
);
  assertNull(result);
  assertEquals(4,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(1,listener.getRemoved());
  result=cache.invokeEntryProcessor(1l,new Cache.EntryProcessor<Long,String,String>(){
    @Override public String process(    MutableEntry<Long,String> entry,    Object... arguments){
      entry.setValue("String_Node_Str");
      return entry.getValue();
    }
  }
);
  assertEquals("String_Node_Str",result);
  assertEquals(5,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(1,listener.getRemoved());
  Iterator<Cache.Entry<Long,String>> iterator=cache.iterator();
  while (iterator.hasNext()) {
    iterator.next();
    iterator.remove();
  }
  assertEquals(5,listener.getCreated());
  assertEquals(5,listener.getUpdated());
  assertEquals(0,listener.getExpired());
  assertEquals(5,listener.getRemoved());
}