Program: 55487
Project: 55487
Buggy source:
/** 
 * This test checks the correctness of extracting instance types from the configuration, mapping IPs to instance types from the slave file, instance slicing and allocation/deallocation.
 */
@Test public void testAllocationDeallocation(){
  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);
  try {
    final InstanceConnectionInfo instanceConnectionInfo=new InstanceConnectionInfo(InetAddress.getByName("String_Node_Str"),1234,1235);
    final HardwareDescription hardwareDescription=HardwareDescriptionFactory.construct(8,8L * 1024L * 1024L* 1024L,8L * 1024L * 1024L* 1024L);
    cm.reportHeartBeat(instanceConnectionInfo,hardwareDescription);
    final JobID jobID=new JobID();
    final Configuration conf=new Configuration();
    final InstanceRequestMap instanceRequestMap=new InstanceRequestMap();
    instanceRequestMap.setNumberOfInstances(cm.getInstanceTypeByName(SMALL_INSTANCE_TYPE_NAME),2);
    instanceRequestMap.setNumberOfInstances(cm.getInstanceTypeByName(MEDIUM_INSTANCE_TYPE_NAME),1);
    try {
      cm.requestInstance(jobID,conf,instanceRequestMap,null);
    }
 catch (    InstanceException ie) {
      fail(ie.getMessage());
    }
    ClusterManagerTestUtils.waitForInstances(jobID,testInstanceListener,3,MAX_WAIT_TIME);
    final List<AllocatedResource> allocatedResources=testInstanceListener.getAllocatedResourcesForJob(jobID);
    assertEquals(3,allocatedResources.size());
    Iterator<AllocatedResource> it=allocatedResources.iterator();
    final Set<AllocationID> allocationIDs=new HashSet<AllocationID>();
    while (it.hasNext()) {
      final AllocatedResource allocatedResource=it.next();
      if (!LARGE_INSTANCE_TYPE_NAME.equals(allocatedResource.getInstance().getType().getIdentifier())) {
        fail("String_Node_Str" + allocatedResource.getInstance().getType().getIdentifier());
      }
      if (allocationIDs.contains(allocatedResource.getAllocationID())) {
        fail("String_Node_Str" + allocatedResource.getAllocationID() + "String_Node_Str");
      }
 else {
        allocationIDs.add(allocatedResource.getAllocationID());
      }
    }
    try {
      InstanceRequestMap instancem=new InstanceRequestMap();
      instancem.setNumberOfInstances(cm.getInstanceTypeByName(MEDIUM_INSTANCE_TYPE_NAME),1);
      cm.requestInstance(jobID,conf,instancem,null);
      fail("String_Node_Str");
    }
 catch (    InstanceException ie) {
    }
    it=allocatedResources.iterator();
    try {
      while (it.hasNext()) {
        final AllocatedResource allocatedResource=it.next();
        cm.releaseAllocatedResource(jobID,conf,allocatedResource);
      }
    }
 catch (    InstanceException ie) {
      fail(ie.getMessage());
    }
    try {
      InstanceRequestMap instancem=new InstanceRequestMap();
      instancem.setNumberOfInstances(cm.getInstanceTypeByName(LARGE_INSTANCE_TYPE_NAME),1);
      cm.requestInstance(jobID,conf,instancem,null);
    }
 catch (    InstanceException ie) {
      fail(ie.getMessage());
    }
  }
 catch (  UnknownHostException e) {
    fail(e.getMessage());
  }
 finally {
    if (cm != null) {
      cm.shutdown();
    }
  }
}

Fixed version (ground truth):
/** 
 * This test checks the correctness of extracting instance types from the configuration, mapping IPs to instance types from the slave file, instance slicing and allocation/deallocation.
 */
@Test public void testAllocationDeallocation(){
  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);
  try {
    final String ipAddress="String_Node_Str";
    final InstanceConnectionInfo instanceConnectionInfo=new InstanceConnectionInfo(InetAddress.getByName(ipAddress),ipAddress,null,1234,1235);
    final HardwareDescription hardwareDescription=HardwareDescriptionFactory.construct(8,8L * 1024L * 1024L* 1024L,8L * 1024L * 1024L* 1024L);
    cm.reportHeartBeat(instanceConnectionInfo,hardwareDescription);
    final JobID jobID=new JobID();
    final Configuration conf=new Configuration();
    final InstanceRequestMap instanceRequestMap=new InstanceRequestMap();
    instanceRequestMap.setNumberOfInstances(cm.getInstanceTypeByName(SMALL_INSTANCE_TYPE_NAME),2);
    instanceRequestMap.setNumberOfInstances(cm.getInstanceTypeByName(MEDIUM_INSTANCE_TYPE_NAME),1);
    try {
      cm.requestInstance(jobID,conf,instanceRequestMap,null);
    }
 catch (    InstanceException ie) {
      fail(ie.getMessage());
    }
    ClusterManagerTestUtils.waitForInstances(jobID,testInstanceListener,3,MAX_WAIT_TIME);
    final List<AllocatedResource> allocatedResources=testInstanceListener.getAllocatedResourcesForJob(jobID);
    assertEquals(3,allocatedResources.size());
    Iterator<AllocatedResource> it=allocatedResources.iterator();
    final Set<AllocationID> allocationIDs=new HashSet<AllocationID>();
    while (it.hasNext()) {
      final AllocatedResource allocatedResource=it.next();
      if (!LARGE_INSTANCE_TYPE_NAME.equals(allocatedResource.getInstance().getType().getIdentifier())) {
        fail("String_Node_Str" + allocatedResource.getInstance().getType().getIdentifier());
      }
      if (allocationIDs.contains(allocatedResource.getAllocationID())) {
        fail("String_Node_Str" + allocatedResource.getAllocationID() + "String_Node_Str");
      }
 else {
        allocationIDs.add(allocatedResource.getAllocationID());
      }
    }
    try {
      InstanceRequestMap instancem=new InstanceRequestMap();
      instancem.setNumberOfInstances(cm.getInstanceTypeByName(MEDIUM_INSTANCE_TYPE_NAME),1);
      cm.requestInstance(jobID,conf,instancem,null);
      fail("String_Node_Str");
    }
 catch (    InstanceException ie) {
    }
    it=allocatedResources.iterator();
    try {
      while (it.hasNext()) {
        final AllocatedResource allocatedResource=it.next();
        cm.releaseAllocatedResource(jobID,conf,allocatedResource);
      }
    }
 catch (    InstanceException ie) {
      fail(ie.getMessage());
    }
    try {
      InstanceRequestMap instancem=new InstanceRequestMap();
      instancem.setNumberOfInstances(cm.getInstanceTypeByName(LARGE_INSTANCE_TYPE_NAME),1);
      cm.requestInstance(jobID,conf,instancem,null);
    }
 catch (    InstanceException ie) {
      fail(ie.getMessage());
    }
  }
 catch (  UnknownHostException e) {
    fail(e.getMessage());
  }
 finally {
    if (cm != null) {
      cm.shutdown();
    }
  }
}