Program: 51215
Project: 51215
Buggy source:
/** 
 * Tests whether the data source plugin is able to tell mondrian to read the hierarchy and aggregates again.
 */
public void testDataSourceChangeListenerPlugin(){
  final MondrianProperties properties=MondrianProperties.instance();
  if (properties.TestExpDependencies.get() > 0) {
    return;
  }
  final TestContext testContext=getTestContext();
  final mondrian.olap.CacheControl cacheControl=testContext.getConnection().getCacheControl(null);
  final Connection connection=testContext.getConnection();
  final mondrian.olap.Cube salesCube=connection.getSchema().lookupCube("String_Node_Str",true);
  final mondrian.olap.CacheControl.CellRegion measuresRegion=cacheControl.createMeasuresRegion(salesCube);
  cacheControl.flush(measuresRegion);
  boolean do_caching_orig=properties.DisableCaching.get();
  properties.DisableCaching.setString("String_Node_Str");
  cacheControl.flushSchemaCache();
  SmartMemberReader smr=getSmartMemberReader("String_Node_Str");
  MemberCacheHelper smrch=(MemberCacheHelper)smr.getMemberCache();
  smrch.mapLevelToMembers.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapLevel,Object>,List<RolapMember>>());
  smrch.mapMemberToChildren.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapMember,Object>,List<RolapMember>>());
  smrch.mapKeyToMember=new HardSmartCache<Object,RolapMember>();
  SmartMemberReader ssmr=getSharedSmartMemberReader("String_Node_Str");
  MemberCacheHelper ssmrch=(MemberCacheHelper)ssmr.getMemberCache();
  ssmrch.mapLevelToMembers.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapLevel,Object>,List<RolapMember>>());
  ssmrch.mapMemberToChildren.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapMember,Object>,List<RolapMember>>());
  ssmrch.mapKeyToMember=new HardSmartCache<Object,RolapMember>();
  SqlLogger sqlLogger=new SqlLogger();
  RolapUtil.threadHooks.set(sqlLogger);
  try {
    String s1, s2, s3, s4, s5, s6;
    Result r1=executeQuery("String_Node_Str");
    Util.discard(r1);
    s1=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertFalse("String_Node_Str".equals(s1));
    Result r2=executeQuery("String_Node_Str");
    Util.discard(r2);
    s2=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals("String_Node_Str",s2);
    smrch.changeListener=new DataSourceChangeListenerImpl();
    ssmrch.changeListener=new DataSourceChangeListenerImpl();
    Result r3=executeQuery("String_Node_Str");
    Util.discard(r3);
    s3=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals("String_Node_Str",s3);
    smrch.mapKeyToMember.clear();
    smrch.mapLevelToMembers.clear();
    smrch.mapMemberToChildren.clear();
    ssmrch.mapKeyToMember.clear();
    ssmrch.mapLevelToMembers.clear();
    ssmrch.mapMemberToChildren.clear();
    Result r4=executeQuery("String_Node_Str");
    Util.discard(r4);
    s4=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertFalse("String_Node_Str".equals(s4));
    smrch.changeListener=new DataSourceChangeListenerImpl2();
    ssmrch.changeListener=new DataSourceChangeListenerImpl2();
    Result r5=executeQuery("String_Node_Str");
    Util.discard(r5);
    s5=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals(s4,s5);
    smrch.changeListener=new DataSourceChangeListenerImpl3();
    ssmrch.changeListener=new DataSourceChangeListenerImpl3();
    RolapStar star=getStar("String_Node_Str");
    star.setChangeListener(smrch.changeListener);
    Result r6=executeQuery("String_Node_Str");
    Util.discard(r6);
    s6=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals(s1,s6);
  }
  finally {
    smrch.changeListener=null;
    ssmrch.changeListener=null;
    RolapStar star=getStar("String_Node_Str");
    star.setChangeListener(null);
    RolapUtil.threadHooks.set(null);
    if (do_caching_orig) {
      properties.DisableCaching.setString("String_Node_Str");
    }
 else {
      properties.DisableCaching.setString("String_Node_Str");
    }
  }
}

Fixed version (ground truth):
/** 
 * Tests whether the data source plugin is able to tell mondrian to read the hierarchy and aggregates again.
 */
public void testDataSourceChangeListenerPlugin(){
  final MondrianProperties properties=MondrianProperties.instance();
  if (properties.TestExpDependencies.get() > 0) {
    return;
  }
  final TestContext testContext=getTestContext();
  final mondrian.olap.CacheControl cacheControl=testContext.getConnection().getCacheControl(null);
  final Connection connection=testContext.getConnection();
  final mondrian.olap.Cube salesCube=connection.getSchema().lookupCube("String_Node_Str",true);
  final mondrian.olap.CacheControl.CellRegion measuresRegion=cacheControl.createMeasuresRegion(salesCube);
  cacheControl.flush(measuresRegion);
  boolean do_caching_orig=properties.DisableCaching.get();
  properties.DisableCaching.setString("String_Node_Str");
  cacheControl.flushSchemaCache();
  RolapCubeHierarchy.RolapCubeHierarchyMemberReader smr=getSmartMemberReader("String_Node_Str");
  MemberCacheHelper smrch=(MemberCacheHelper)smr.getMemberCache();
  smrch.mapLevelToMembers.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapLevel,Object>,List<RolapMember>>());
  smrch.mapMemberToChildren.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapMember,Object>,List<RolapMember>>());
  smrch.mapKeyToMember=new HardSmartCache<Object,RolapMember>();
  MemberCacheHelper rcsmrch=(MemberCacheHelper)smr.getRolapCubeMemberCacheHelper();
  rcsmrch.mapLevelToMembers.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapLevel,Object>,List<RolapMember>>());
  rcsmrch.mapMemberToChildren.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapMember,Object>,List<RolapMember>>());
  rcsmrch.mapKeyToMember=new HardSmartCache<Object,RolapMember>();
  SmartMemberReader ssmr=getSharedSmartMemberReader("String_Node_Str");
  MemberCacheHelper ssmrch=(MemberCacheHelper)ssmr.getMemberCache();
  ssmrch.mapLevelToMembers.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapLevel,Object>,List<RolapMember>>());
  ssmrch.mapMemberToChildren.setCache(new HardSmartCache<SmartMemberListCache.Key2<RolapMember,Object>,List<RolapMember>>());
  ssmrch.mapKeyToMember=new HardSmartCache<Object,RolapMember>();
  SqlLogger sqlLogger=new SqlLogger();
  RolapUtil.threadHooks.set(sqlLogger);
  try {
    String s1, s2, s3, s4, s5, s6;
    Result r1=executeQuery("String_Node_Str");
    Util.discard(r1);
    s1=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertFalse("String_Node_Str".equals(s1));
    Result r2=executeQuery("String_Node_Str");
    Util.discard(r2);
    s2=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals("String_Node_Str",s2);
    smrch.changeListener=new DataSourceChangeListenerImpl();
    ssmrch.changeListener=new DataSourceChangeListenerImpl();
    rcsmrch.changeListener=new DataSourceChangeListenerImpl();
    Result r3=executeQuery("String_Node_Str");
    Util.discard(r3);
    s3=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals("String_Node_Str",s3);
    smrch.mapKeyToMember.clear();
    smrch.mapLevelToMembers.clear();
    smrch.mapMemberToChildren.clear();
    ssmrch.mapKeyToMember.clear();
    ssmrch.mapLevelToMembers.clear();
    ssmrch.mapMemberToChildren.clear();
    rcsmrch.mapKeyToMember.clear();
    rcsmrch.mapLevelToMembers.clear();
    rcsmrch.mapMemberToChildren.clear();
    Result r4=executeQuery("String_Node_Str");
    Util.discard(r4);
    s4=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertFalse("String_Node_Str".equals(s4));
    smrch.changeListener=new DataSourceChangeListenerImpl2();
    ssmrch.changeListener=new DataSourceChangeListenerImpl2();
    rcsmrch.changeListener=new DataSourceChangeListenerImpl2();
    Result r5=executeQuery("String_Node_Str");
    Util.discard(r5);
    s5=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals(s4,s5);
    smrch.changeListener=new DataSourceChangeListenerImpl3();
    ssmrch.changeListener=new DataSourceChangeListenerImpl3();
    rcsmrch.changeListener=new DataSourceChangeListenerImpl3();
    RolapStar star=getStar("String_Node_Str");
    star.setChangeListener(smrch.changeListener);
    Result r6=executeQuery("String_Node_Str");
    Util.discard(r6);
    s6=sqlLogger.getSqlQueries().toString();
    sqlLogger.clear();
    assertEquals(s1,s6);
  }
  finally {
    smrch.changeListener=null;
    ssmrch.changeListener=null;
    rcsmrch.changeListener=null;
    RolapStar star=getStar("String_Node_Str");
    star.setChangeListener(null);
    RolapUtil.threadHooks.set(null);
    if (do_caching_orig) {
      properties.DisableCaching.setString("String_Node_Str");
    }
 else {
      properties.DisableCaching.setString("String_Node_Str");
    }
  }
}