Program: 55485
Project: 55485
Buggy source:
/** 
 * This test covers the matching of instances to instance types It addresses the automatic matching through the hardware description as well as user-defined instance type matching.
 */
@Test public void testInstanceMatching(){
  final String configDir=getConfigDir();
  if (configDir == null) {
    fail("String_Node_Str");
  }
  GlobalConfiguration.loadConfiguration(configDir);
  final TestInstanceListener testInstanceListener=new TestInstanceListener();
  final ClusterManager cm=new ClusterManager();
  cm.setInstanceListener(testInstanceListener);
  Map<InstanceType,InstanceTypeDescription> instanceTypeDescriptions=null;
  try {
    final int ipcPort=ConfigConstants.DEFAULT_TASK_MANAGER_IPC_PORT;
    final int dataPort=ConfigConstants.DEFAULT_TASK_MANAGER_DATA_PORT;
    HardwareDescription hardwareDescription=HardwareDescriptionFactory.construct(2,2L * 1024L * 1024L* 1024L,2L * 1024L * 1024L* 1024L);
    InstanceConnectionInfo ici=new InstanceConnectionInfo(InetAddress.getByName("String_Node_Str"),ipcPort,dataPort);
    cm.reportHeartBeat(ici,hardwareDescription);
    instanceTypeDescriptions=cm.getMapOfAvailableInstanceTypes();
    assertEquals(3,instanceTypeDescriptions.size());
    Iterator<Map.Entry<InstanceType,InstanceTypeDescription>> it=instanceTypeDescriptions.entrySet().iterator();
    while (it.hasNext()) {
      final Map.Entry<InstanceType,InstanceTypeDescription> entry=it.next();
      if (LARGE_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(1,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (MEDIUM_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(2,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (SMALL_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(4,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else {
        fail("String_Node_Str" + entry.getKey());
      }
    }
    hardwareDescription=HardwareDescriptionFactory.construct(3,2L * 1024L * 1024L* 1024L,1024L * 1024L * 1024L);
    ici=new InstanceConnectionInfo(InetAddress.getByName("String_Node_Str"),ipcPort,dataPort);
    cm.reportHeartBeat(ici,hardwareDescription);
    instanceTypeDescriptions=cm.getMapOfAvailableInstanceTypes();
    assertEquals(3,instanceTypeDescriptions.size());
    it=instanceTypeDescriptions.entrySet().iterator();
    while (it.hasNext()) {
      final Map.Entry<InstanceType,InstanceTypeDescription> entry=it.next();
      if (LARGE_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(1,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (MEDIUM_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(2,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (SMALL_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(5,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else {
        fail("String_Node_Str" + entry.getKey());
      }
    }
  }
 catch (  UnknownHostException e) {
    fail(e.getMessage());
  }
 finally {
    if (cm != null) {
      cm.shutdown();
    }
  }
}

Fixed version (ground truth):
/** 
 * This test covers the matching of instances to instance types It addresses the automatic matching through the hardware description as well as user-defined instance type matching.
 */
@Test public void testInstanceMatching(){
  final String configDir=getConfigDir();
  if (configDir == null) {
    fail("String_Node_Str");
  }
  GlobalConfiguration.loadConfiguration(configDir);
  final TestInstanceListener testInstanceListener=new TestInstanceListener();
  final ClusterManager cm=new ClusterManager();
  cm.setInstanceListener(testInstanceListener);
  Map<InstanceType,InstanceTypeDescription> instanceTypeDescriptions=null;
  try {
    final int ipcPort=ConfigConstants.DEFAULT_TASK_MANAGER_IPC_PORT;
    final int dataPort=ConfigConstants.DEFAULT_TASK_MANAGER_DATA_PORT;
    HardwareDescription hardwareDescription=HardwareDescriptionFactory.construct(2,2L * 1024L * 1024L* 1024L,2L * 1024L * 1024L* 1024L);
    String ipAddress="String_Node_Str";
    InstanceConnectionInfo ici=new InstanceConnectionInfo(InetAddress.getByName(ipAddress),ipAddress,null,ipcPort,dataPort);
    cm.reportHeartBeat(ici,hardwareDescription);
    instanceTypeDescriptions=cm.getMapOfAvailableInstanceTypes();
    assertEquals(3,instanceTypeDescriptions.size());
    Iterator<Map.Entry<InstanceType,InstanceTypeDescription>> it=instanceTypeDescriptions.entrySet().iterator();
    while (it.hasNext()) {
      final Map.Entry<InstanceType,InstanceTypeDescription> entry=it.next();
      if (LARGE_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(1,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (MEDIUM_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(2,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (SMALL_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(4,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else {
        fail("String_Node_Str" + entry.getKey());
      }
    }
    hardwareDescription=HardwareDescriptionFactory.construct(3,2L * 1024L * 1024L* 1024L,1024L * 1024L * 1024L);
    ipAddress="String_Node_Str";
    ici=new InstanceConnectionInfo(InetAddress.getByName(ipAddress),ipAddress,null,ipcPort,dataPort);
    cm.reportHeartBeat(ici,hardwareDescription);
    instanceTypeDescriptions=cm.getMapOfAvailableInstanceTypes();
    assertEquals(3,instanceTypeDescriptions.size());
    it=instanceTypeDescriptions.entrySet().iterator();
    while (it.hasNext()) {
      final Map.Entry<InstanceType,InstanceTypeDescription> entry=it.next();
      if (LARGE_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(1,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (MEDIUM_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(2,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else       if (SMALL_INSTANCE_TYPE_NAME.equals(entry.getKey().getIdentifier())) {
        assertEquals(5,entry.getValue().getMaximumNumberOfAvailableInstances());
      }
 else {
        fail("String_Node_Str" + entry.getKey());
      }
    }
  }
 catch (  UnknownHostException e) {
    fail(e.getMessage());
  }
 finally {
    if (cm != null) {
      cm.shutdown();
    }
  }
}