nus-yam/ex-repair huggingface dataset:
Program: 48016
Project: 48016
Buggy source:
public boolean containsValue(Object value){
  Data valueData=toData(value);
  ContainsRequest request=new ContainsRequest(name,null,valueData);
  Boolean result=invoke(request);
  return result;
}

Fixed version (ground truth):
public boolean containsValue(Object value){
  Data valueData=toData(value);
  ClientRequest request=new ContainsRequest(name,valueData);
  Boolean result=invoke(request);
  return result;
}
Program: 48017
Project: 48017
Buggy source:
public boolean containsEntry(K key,V value){
  Data keyData=toData(key);
  Data valueData=toData(value);
  ContainsRequest request=new ContainsRequest(name,keyData,valueData);
  Boolean result=invoke(request,keyData);
  return result;
}

Fixed version (ground truth):
public boolean containsEntry(K key,V value){
  Data keyData=toData(key);
  Data valueData=toData(value);
  ClientRequest request;
  if (keyData == null) {
    request=new ContainsRequest(name,valueData);
  }
 else {
    request=new KeyBasedContainsRequest(name,keyData,valueData);
  }
  Boolean result=invoke(request,keyData);
  return result;
}
Program: 48018
Project: 48018
Buggy source:
public boolean containsKey(K key){
  Data keyData=toData(key);
  ContainsRequest request=new ContainsRequest(name,keyData,null);
  Boolean result=invoke(request,keyData);
  return result;
}

Fixed version (ground truth):
public boolean containsKey(K key){
  Data keyData=toData(key);
  ClientRequest request=new KeyBasedContainsRequest(name,keyData,null);
  Boolean result=invoke(request,keyData);
  return result;
}
Program: 48020
Project: 48020
Buggy source:
public Portable createNew(Integer arg){
  return new TxnMultiMapRemoveAllRequest();
}

Fixed version (ground truth):
@Override public Portable createNew(Integer arg){
  return new KeyBasedContainsRequest();
}
Program: 48021
Project: 48021
Buggy source:
public ContainsRequest(String name,Data key,Data value){
  super(name);
  this.key=key;
  this.value=value;
}

Fixed version (ground truth):
public ContainsRequest(String name,Data value){
  super(name);
  this.value=value;
}
Program: 48022
Project: 48022
Buggy source:
public void read(PortableReader reader) throws IOException {
  super.read(reader);
  final ObjectDataInput in=reader.getRawDataInput();
  key=IOUtil.readNullableData(in);
  value=IOUtil.readNullableData(in);
}

Fixed version (ground truth):
public void read(PortableReader reader) throws IOException {
  super.read(reader);
  final ObjectDataInput in=reader.getRawDataInput();
  value=IOUtil.readNullableData(in);
}
Program: 48023
Project: 48023
Buggy source:
@Override public String getMethodName(){
  if (key != null && value != null) {
    return "String_Node_Str";
  }
 else   if (key != null) {
    return "String_Node_Str";
  }
  return "String_Node_Str";
}

Fixed version (ground truth):
@Override public String getMethodName(){
  return "String_Node_Str";
}
Program: 48024
Project: 48024
Buggy source:
protected OperationFactory createOperationFactory(){
  return new MultiMapOperationFactory(name,MultiMapOperationFactory.OperationFactoryType.CONTAINS,key,value);
}

Fixed version (ground truth):
protected OperationFactory createOperationFactory(){
  return new MultiMapOperationFactory(name,MultiMapOperationFactory.OperationFactoryType.CONTAINS,null,value);
}
Program: 48025
Project: 48025
Buggy source:
@Override public Object[] getParameters(){
  if (key != null && value != null) {
    return new Object[]{key,value};
  }
 else   if (key != null) {
    return new Object[]{key};
  }
  return new Object[]{value};
}

Fixed version (ground truth):
@Override public Object[] getParameters(){
  return new Object[]{value};
}
Program: 48026
Project: 48026
Buggy source:
public void write(PortableWriter writer) throws IOException {
  super.write(writer);
  final ObjectDataOutput out=writer.getRawDataOutput();
  IOUtil.writeNullableData(out,key);
  IOUtil.writeNullableData(out,value);
}

Fixed version (ground truth):
public void write(PortableWriter writer) throws IOException {
  super.write(writer);
  final ObjectDataOutput out=writer.getRawDataOutput();
  IOUtil.writeNullableData(out,value);
}
Program: 48027
Project: 48027
Buggy source:
@Test public void testContainsEntry() throws IOException {
  MultiMap mm=getMultiMap();
  mm.put("String_Node_Str","String_Node_Str");
  mm.put("String_Node_Str","String_Node_Str");
  mm.put("String_Node_Str","String_Node_Str");
  final SimpleClient client=getClient();
  client.send(new ContainsRequest(name,ss.toData("String_Node_Str"),ss.toData("String_Node_Str")));
  boolean result=(Boolean)client.receive();
  assertTrue(result);
  client.send(new ContainsRequest(name,ss.toData("String_Node_Str"),ss.toData("String_Node_Str")));
  result=(Boolean)client.receive();
  assertFalse(result);
  client.send(new ContainsRequest(name,ss.toData("String_Node_Str"),null));
  result=(Boolean)client.receive();
  assertTrue(result);
  client.send(new ContainsRequest(name,ss.toData("String_Node_Str"),null));
  result=(Boolean)client.receive();
  assertFalse(result);
  client.send(new ContainsRequest(name,null,ss.toData("String_Node_Str")));
  result=(Boolean)client.receive();
  assertTrue(result);
  client.send(new ContainsRequest(name,null,ss.toData("String_Node_Str")));
  result=(Boolean)client.receive();
  assertFalse(result);
}

Fixed version (ground truth):
@Test public void testContainsEntry() throws IOException {
  MultiMap mm=getMultiMap();
  mm.put("String_Node_Str","String_Node_Str");
  mm.put("String_Node_Str","String_Node_Str");
  mm.put("String_Node_Str","String_Node_Str");
  final SimpleClient client=getClient();
  client.send(new KeyBasedContainsRequest(name,ss.toData("String_Node_Str"),ss.toData("String_Node_Str")));
  boolean result=(Boolean)client.receive();
  assertTrue(result);
  client.send(new KeyBasedContainsRequest(name,ss.toData("String_Node_Str"),ss.toData("String_Node_Str")));
  result=(Boolean)client.receive();
  assertFalse(result);
  client.send(new KeyBasedContainsRequest(name,ss.toData("String_Node_Str"),null));
  result=(Boolean)client.receive();
  assertTrue(result);
  client.send(new KeyBasedContainsRequest(name,ss.toData("String_Node_Str"),null));
  result=(Boolean)client.receive();
  assertFalse(result);
  client.send(new ContainsRequest(name,ss.toData("String_Node_Str")));
  result=(Boolean)client.receive();
  assertTrue(result);
  client.send(new ContainsRequest(name,ss.toData("String_Node_Str")));
  result=(Boolean)client.receive();
  assertFalse(result);
}
Program: 48028
Project: 48028
Buggy source:
@Override public void setMinEvictionCheckMillis(long checkIfEvictableAfterMillis){
  throw new UnsupportedOperationException("String_Node_Str" + getName());
}

Fixed version (ground truth):
@Override public MapConfig setMinEvictionCheckMillis(long checkIfEvictableAfterMillis){
  throw new UnsupportedOperationException("String_Node_Str" + getName());
}
Program: 48029
Project: 48029
Buggy source:
@Test public void testIssue1085WriteBehindBackup() throws InterruptedException {
  Config config=new Config();
  String name="String_Node_Str";
  MapConfig writeBehindBackup=config.getMapConfig(name);
  MapStoreConfig mapStoreConfig=new MapStoreConfig();
  mapStoreConfig.setWriteDelaySeconds(5);
  int size=1000;
  MapStoreWithStoreCount mapStore=new MapStoreWithStoreCount(size,120);
  mapStoreConfig.setImplementation(mapStore);
  writeBehindBackup.setMapStoreConfig(mapStoreConfig);
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(3);
  HazelcastInstance instance=factory.newHazelcastInstance(config);
  HazelcastInstance instance2=factory.newHazelcastInstance(config);
  final IMap map=instance.getMap(name);
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  instance2.getLifecycleService().terminate();
  mapStore.awaitStores();
}

Fixed version (ground truth):
@Test public void testIssue1085WriteBehindBackup() throws InterruptedException {
  Config config=new Config();
  String name="String_Node_Str";
  MapConfig writeBehindBackup=config.getMapConfig(name);
  MapStoreConfig mapStoreConfig=new MapStoreConfig();
  mapStoreConfig.setWriteDelaySeconds(5);
  int size=1000;
  MapStoreWithStoreCount mapStore=new MapStoreWithStoreCount(size,120);
  mapStoreConfig.setImplementation(mapStore);
  writeBehindBackup.setMapStoreConfig(mapStoreConfig);
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(3);
  HazelcastInstance instance=factory.newHazelcastInstance(config);
  HazelcastInstance instance2=factory.newHazelcastInstance(config);
  final IMap map=instance.getMap(name);
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  instance2.getLifecycleService().shutdown();
  mapStore.awaitStores();
}
Program: 48030
Project: 48030
Buggy source:
/** 
 * @param connectionTimeout Timeout value in millis for nodes to accept client connection client.
 * @return configured {@link com.hazelcast.client.config.ClientNetworkConfig} for chaining
 */
public ClientNetworkConfig setConnectionTimeout(int connectionTimeout){
  this.connectionTimeout=connectionTimeout;
  return this;
}

Fixed version (ground truth):
/** 
 * @param connectionTimeout Timeout value in millis for nodes to accept client connection requests.
 * @return configured {@link com.hazelcast.client.config.ClientNetworkConfig} for chaining
 */
public ClientNetworkConfig setConnectionTimeout(int connectionTimeout){
  this.connectionTimeout=connectionTimeout;
  return this;
}
Program: 48031
Project: 48031
Buggy source:
/** 
 * Timeout value in millis for nodes to accept client connection client.
 * @return connection timeout value in millis
 */
public int getConnectionTimeout(){
  return connectionTimeout;
}

Fixed version (ground truth):
/** 
 * Timeout value in millis for nodes to accept client connection requests.
 * @return connection timeout value in millis
 */
public int getConnectionTimeout(){
  return connectionTimeout;
}
Program: 48032
Project: 48032
Buggy source:
/** 
 * Version for internal client. This version can be configured per class by overriding this method. <p/> <p> This should be updated/incremented when serialization of a request changes. </p>
 */
@Override public int getClassVersion(){
  return 1;
}

Fixed version (ground truth):
/** 
 * Version for internal requests. This version can be configured per class by overriding this method. <p/> <p> This should be updated/incremented when serialization of a request changes. </p>
 */
@Override public int getClassVersion(){
  return 1;
}
Program: 48033
Project: 48033
Buggy source:
/** 
 * Used for   {@link com.hazelcast.security.SecurityInterceptor}Method name which called via a distributedObject for map.put, methodName will be 'put' For client which do not produced via a distributedObject should return null, for example internal client.
 * @return
 */
String getMethodName();

Fixed version (ground truth):
/** 
 * Used for   {@link com.hazelcast.security.SecurityInterceptor}Method name which called via a distributedObject for map.put, methodName will be 'put' For requests which do not produced via a distributedObject should return null, for example internal client.
 * @return
 */
String getMethodName();
Program: 48034
Project: 48034
Buggy source:
/** 
 * Sets the trusted interfaces. <p/> By default, so when the set of trusted interfaces is empty, a Hazelcast member will accept join-client from every member. With a trusted interface you can control the members you want to receive join request from. <p/> The interface is an ip address where the last octet can be a wildcard '*' or a range '10-20'.
 * @param interfaces the new trusted interfaces.
 * @return the updated MulticastConfig.
 * @see IllegalArgumentException if interfaces is null.
 */
public MulticastConfig setTrustedInterfaces(Set<String> interfaces){
  isNotNull(interfaces,"String_Node_Str");
  trustedInterfaces.clear();
  trustedInterfaces.addAll(interfaces);
  return this;
}

Fixed version (ground truth):
/** 
 * Sets the trusted interfaces. <p/> By default, so when the set of trusted interfaces is empty, a Hazelcast member will accept join-requests from every member. With a trusted interface you can control the members you want to receive join request from. <p/> The interface is an ip address where the last octet can be a wildcard '*' or a range '10-20'.
 * @param interfaces the new trusted interfaces.
 * @return the updated MulticastConfig.
 * @see IllegalArgumentException if interfaces is null.
 */
public MulticastConfig setTrustedInterfaces(Set<String> interfaces){
  isNotNull(interfaces,"String_Node_Str");
  trustedInterfaces.clear();
  trustedInterfaces.addAll(interfaces);
  return this;
}
Program: 48035
Project: 48035
Buggy source:
private void doInvokeRemote(){
  long callId=operationService.registerInvocation(this);
  boolean sent=operationService.send(op,invTarget);
  if (!sent) {
    operationService.deregisterInvocation(this);
    notify(new RetryableIOException("String_Node_Str" + invTarget));
  }
}

Fixed version (ground truth):
private void doInvokeRemote(){
  operationService.registerInvocation(this);
  boolean sent=operationService.send(op,invTarget);
  if (!sent) {
    operationService.deregisterInvocation(this);
    notify(new RetryableIOException("String_Node_Str" + invTarget));
  }
}
Program: 48036
Project: 48036
Buggy source:
public long registerInvocation(BasicInvocation invocation){
  long callId=callIdGen.getAndIncrement();
  Operation op=invocation.op;
  if (op.getCallId() != 0) {
    invocations.remove(op.getCallId());
  }
  invocations.put(callId,invocation);
  setCallId(invocation.op,callId);
  return callId;
}

Fixed version (ground truth):
public void registerInvocation(BasicInvocation invocation){
  long callId=callIdGen.getAndIncrement();
  Operation op=invocation.op;
  if (op.getCallId() != 0) {
    invocations.remove(op.getCallId());
  }
  invocations.put(callId,invocation);
  setCallId(invocation.op,callId);
}
Program: 48037
Project: 48037
Buggy source:
private void doInvokeRemote(){
  long callId=operationService.registerInvocation(this);
  boolean sent=operationService.send(op,invTarget);
  if (!sent) {
    operationService.deregisterInvocation(this);
    notify(new RetryableIOException("String_Node_Str" + invTarget));
  }
}

Fixed version (ground truth):
private void doInvokeRemote(){
  operationService.registerInvocation(this);
  boolean sent=operationService.send(op,invTarget);
  if (!sent) {
    operationService.deregisterInvocation(this);
    notify(new RetryableIOException("String_Node_Str" + invTarget));
  }
}
Program: 48038
Project: 48038
Buggy source:
public long registerInvocation(BasicInvocation invocation){
  long callId=callIdGen.getAndIncrement();
  Operation op=invocation.op;
  if (op.getCallId() != 0) {
    invocations.remove(op.getCallId());
  }
  invocations.put(callId,invocation);
  setCallId(invocation.op,callId);
  return callId;
}

Fixed version (ground truth):
public void registerInvocation(BasicInvocation invocation){
  long callId=callIdGen.getAndIncrement();
  Operation op=invocation.op;
  if (op.getCallId() != 0) {
    invocations.remove(op.getCallId());
  }
  invocations.put(callId,invocation);
  setCallId(invocation.op,callId);
}
Program: 48039
Project: 48039
Buggy source:
@Test public void testIssue1085WriteBehindBackup() throws InterruptedException {
  Config config=new Config();
  String name="String_Node_Str";
  MapConfig writeBehindBackup=config.getMapConfig(name);
  MapStoreConfig mapStoreConfig=new MapStoreConfig();
  mapStoreConfig.setWriteDelaySeconds(5);
  int size=1000;
  MapStoreWithStoreCount mapStore=new MapStoreWithStoreCount(size,120);
  mapStoreConfig.setImplementation(mapStore);
  writeBehindBackup.setMapStoreConfig(mapStoreConfig);
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(3);
  HazelcastInstance instance=factory.newHazelcastInstance(config);
  HazelcastInstance instance2=factory.newHazelcastInstance(config);
  final IMap map=instance.getMap(name);
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  instance2.getLifecycleService().terminate();
  mapStore.awaitStores();
}

Fixed version (ground truth):
@Test public void testIssue1085WriteBehindBackup() throws InterruptedException {
  Config config=new Config();
  String name="String_Node_Str";
  MapConfig writeBehindBackup=config.getMapConfig(name);
  MapStoreConfig mapStoreConfig=new MapStoreConfig();
  mapStoreConfig.setWriteDelaySeconds(5);
  int size=1000;
  MapStoreWithStoreCount mapStore=new MapStoreWithStoreCount(size,120);
  mapStoreConfig.setImplementation(mapStore);
  writeBehindBackup.setMapStoreConfig(mapStoreConfig);
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(3);
  HazelcastInstance instance=factory.newHazelcastInstance(config);
  HazelcastInstance instance2=factory.newHazelcastInstance(config);
  final IMap map=instance.getMap(name);
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  instance2.getLifecycleService().shutdown();
  mapStore.awaitStores();
}
Program: 48040
Project: 48040
Buggy source:
@Override protected HazelcastHttpSession createNewSession(RequestWrapper requestWrapper,String existingSessionId){
  HazelcastHttpSession session=super.createNewSession(requestWrapper,existingSessionId);
  ApplicationContext appContext=WebApplicationContextUtils.getWebApplicationContext(servletContext);
  if (appContext != null) {
    ensureSessionRegistryInitialized(appContext);
    if (sessionRegistry != null) {
      String originalSessionId=session.getOriginalSessionId();
      sessionRegistry.removeSessionInformation(originalSessionId);
      if (!isSessionRegistered(session.getId())) {
        appContext.publishEvent(new HttpSessionCreatedEvent(session));
        if (LOGGER.isLoggable(Level.FINEST)) {
          LOGGER.finest("String_Node_Str" + session);
        }
      }
    }
  }
  return session;
}

Fixed version (ground truth):
@Override protected HazelcastHttpSession createNewSession(RequestWrapper requestWrapper,String existingSessionId){
  HazelcastHttpSession session=super.createNewSession(requestWrapper,existingSessionId);
  ApplicationContext appContext=WebApplicationContextUtils.getWebApplicationContext(servletContext);
  if (appContext != null) {
    ensureSessionRegistryInitialized(appContext);
    if (sessionRegistry != null) {
      String originalSessionId=session.getOriginalSessionId();
      sessionRegistry.removeSessionInformation(originalSessionId);
      if (!isSessionRegistered(session.getId())) {
        appContext.publishEvent(new HttpSessionCreatedEvent(session));
        LOGGER.finest("String_Node_Str" + session.getId());
      }
    }
  }
  return session;
}
Program: 48041
Project: 48041
Buggy source:
@Override protected void destroySession(HazelcastHttpSession session,boolean invalidate){
  super.destroySession(session,invalidate);
  if (invalidate) {
    ApplicationContext appContext=WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (appContext != null) {
      ensureSessionRegistryInitialized(appContext);
      if (sessionRegistry != null) {
        String originalSessionId=session.getOriginalSessionId();
        sessionRegistry.removeSessionInformation(originalSessionId);
        appContext.publishEvent(new HttpSessionDestroyedEvent(session));
        if (LOGGER.isLoggable(Level.FINEST)) {
          LOGGER.finest("String_Node_Str" + session);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override protected void destroySession(HazelcastHttpSession session,boolean invalidate){
  super.destroySession(session,invalidate);
  if (invalidate) {
    ApplicationContext appContext=WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (appContext != null) {
      ensureSessionRegistryInitialized(appContext);
      if (sessionRegistry != null) {
        String originalSessionId=session.getOriginalSessionId();
        sessionRegistry.removeSessionInformation(originalSessionId);
        appContext.publishEvent(new HttpSessionDestroyedEvent(session));
        LOGGER.finest("String_Node_Str" + session.getId());
      }
    }
  }
}
Program: 48042
Project: 48042
Buggy source:
private void handleSelectFailure(Throwable e){
  logger.warning(e.toString(),e);
  try {
    Thread.sleep(1000);
  }
 catch (  InterruptedException i) {
    Thread.currentThread().interrupt();
  }
}

Fixed version (ground truth):
private void handleSelectFailure(Throwable e){
  logger.warning(e.toString(),e);
  try {
    Thread.sleep(SELECT_FAILURE_PAUSE_MILLIS);
  }
 catch (  InterruptedException i) {
    Thread.currentThread().interrupt();
  }
}
Program: 48043
Project: 48043
Buggy source:
/** 
 * Tests data safety when multiple nodes start and a non-master node is shutdown immediately after start and doing a partition based operation.
 */
@Test public void testGracefulShutdown_Issue2804(){
  Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_COUNT,"String_Node_Str");
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance h1=factory.newHazelcastInstance(config);
  HazelcastInstance h2=factory.newHazelcastInstance(config);
  Object key="String_Node_Str";
  Object value="String_Node_Str";
  IMap<Object,Object> map=h1.getMap(MAP_NAME);
  map.put(key,value);
  h2.shutdown();
  assertEquals(value,map.get(key));
}

Fixed version (ground truth):
/** 
 * Tests data safety when multiple nodes start and a non-master node is shutdown immediately after start and doing a partition based operation.
 */
@Test public void testGracefulShutdown_Issue2804(){
  Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_COUNT,"String_Node_Str");
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance h1=factory.newHazelcastInstance(config);
  HazelcastInstance h2=factory.newHazelcastInstance(config);
  String key="String_Node_Str";
  String value="String_Node_Str";
  IMap<String,String> map=h1.getMap(MAP_NAME);
  map.put(key,value);
  h2.shutdown();
  assertEquals(value,map.get(key));
}
Program: 48044
Project: 48044
Buggy source:
@Test public void testGracefulShutdown2() throws Exception {
  Config config=new Config();
  config.getMapConfig(MAP_NAME).setBackupCount(2);
  TestHazelcastInstanceFactory f=createHazelcastInstanceFactory(6);
  final HazelcastInstance hz=f.newHazelcastInstance(config);
  final IMap<Object,Object> map=hz.getMap(MAP_NAME);
  final int size=50000;
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  final HazelcastInstance hz2=f.newHazelcastInstance(config);
  final IMap<Object,Object> map2=hz2.getMap(MAP_NAME);
  assertEquals(size,map2.size());
  final HazelcastInstance hz3=f.newHazelcastInstance(config);
  final IMap<Object,Object> map3=hz3.getMap(MAP_NAME);
  final HazelcastInstance hz4=f.newHazelcastInstance(config);
  final IMap<Object,Object> map4=hz4.getMap(MAP_NAME);
  assertEquals(size,map3.size());
  assertEquals(size,map4.size());
  final HazelcastInstance hz5=f.newHazelcastInstance(config);
  final IMap<Object,Object> map5=hz5.getMap(MAP_NAME);
  final HazelcastInstance hz6=f.newHazelcastInstance(config);
  final IMap<Object,Object> map6=hz6.getMap(MAP_NAME);
  assertEquals(size,map5.size());
  assertEquals(size,map6.size());
  hz.shutdown();
  hz2.shutdown();
  assertEquals(size,map3.size());
  assertEquals(size,map4.size());
  assertEquals(size,map5.size());
  assertEquals(size,map6.size());
  hz3.shutdown();
  hz4.shutdown();
  assertEquals(size,map5.size());
  assertEquals(size,map6.size());
}

Fixed version (ground truth):
@Test public void testGracefulShutdown2() throws Exception {
  Config config=new Config();
  config.getMapConfig(MAP_NAME).setBackupCount(2);
  TestHazelcastInstanceFactory f=createHazelcastInstanceFactory(6);
  final HazelcastInstance hz=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map=hz.getMap(MAP_NAME);
  final int size=50000;
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  final HazelcastInstance hz2=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map2=hz2.getMap(MAP_NAME);
  waitForSafeStateAndCheckSize(size,hz2,map2);
  final HazelcastInstance hz3=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map3=hz3.getMap(MAP_NAME);
  final HazelcastInstance hz4=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map4=hz4.getMap(MAP_NAME);
  waitForSafeStateAndCheckSize(size,hz3,map3);
  waitForSafeStateAndCheckSize(size,hz4,map4);
  final HazelcastInstance hz5=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map5=hz5.getMap(MAP_NAME);
  final HazelcastInstance hz6=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map6=hz6.getMap(MAP_NAME);
  waitForSafeStateAndCheckSize(size,hz5,map5);
  waitForSafeStateAndCheckSize(size,hz6,map6);
  shutdownAndWait(hz);
  shutdownAndWait(hz2);
  waitForSafeStateAndCheckSize(size,hz3,map3);
  waitForSafeStateAndCheckSize(size,hz4,map4);
  waitForSafeStateAndCheckSize(size,hz5,map5);
  waitForSafeStateAndCheckSize(size,hz6,map6);
  shutdownAndWait(hz3);
  shutdownAndWait(hz4);
  waitForSafeStateAndCheckSize(size,hz5,map5);
  waitForSafeStateAndCheckSize(size,hz6,map6);
}
Program: 48046
Project: 48046
Buggy source:
private void testBackupMigrationAndRecovery(int nodeCount,int backupCount,int mapSize) throws Exception {
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(nodeCount);
  final String name=MAP_NAME;
  final Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_BACKUP_SYNC_INTERVAL,"String_Node_Str");
  config.getMapConfig(name).setBackupCount(backupCount).setStatisticsEnabled(true);
  final HazelcastInstance[] instances=new HazelcastInstance[nodeCount];
  HazelcastInstance hz=nodeFactory.newHazelcastInstance(config);
  instances[0]=hz;
  IMap map1=hz.getMap(name);
  for (int i=0; i < mapSize; i++) {
    map1.put(i,"String_Node_Str" + i);
  }
  checkMapSizes(mapSize,backupCount,instances);
  for (int i=1; i < nodeCount; i++) {
    instances[i]=nodeFactory.newHazelcastInstance(config);
    checkMapSizes(mapSize,backupCount,instances);
  }
  final Random rand=new Random();
  for (int i=1; i < nodeCount; i++) {
    int ix;
    do {
      ix=rand.nextInt(nodeCount);
    }
 while (instances[ix] == null);
    TestUtil.terminateInstance(instances[ix]);
    instances[ix]=null;
    checkMapSizes(mapSize,backupCount,instances);
  }
}

Fixed version (ground truth):
private void testBackupMigrationAndRecovery(int nodeCount,int backupCount,int mapSize) throws Exception {
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(nodeCount);
  final String name=MAP_NAME;
  final Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_BACKUP_SYNC_INTERVAL,"String_Node_Str");
  config.getMapConfig(name).setBackupCount(backupCount).setStatisticsEnabled(true);
  final HazelcastInstance[] instances=new HazelcastInstance[nodeCount];
  HazelcastInstance hz=nodeFactory.newHazelcastInstance(config);
  instances[0]=hz;
  IMap<Integer,String> map1=hz.getMap(name);
  for (int i=0; i < mapSize; i++) {
    map1.put(i,"String_Node_Str" + i);
  }
  checkMapSizes(mapSize,backupCount,instances);
  for (int i=1; i < nodeCount; i++) {
    instances[i]=nodeFactory.newHazelcastInstance(config);
    checkMapSizes(mapSize,backupCount,instances);
  }
  final Random rand=new Random();
  for (int i=1; i < nodeCount; i++) {
    int ix;
    do {
      ix=rand.nextInt(nodeCount);
    }
 while (instances[ix] == null);
    TestUtil.terminateInstance(instances[ix]);
    instances[ix]=null;
    checkMapSizes(mapSize,backupCount,instances);
  }
}
Program: 48047
Project: 48047
Buggy source:
@Test public void testGracefulShutdown() throws Exception {
  int size=50000;
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  final Config config=new Config();
  HazelcastInstance h1=nodeFactory.newHazelcastInstance(config);
  IMap m1=h1.getMap(MAP_NAME);
  for (int i=0; i < size; i++) {
    m1.put(i,i);
  }
  HazelcastInstance h2=nodeFactory.newHazelcastInstance(config);
  IMap m2=h2.getMap(MAP_NAME);
  h1.shutdown();
  assertEquals(size,m2.size());
  HazelcastInstance h3=nodeFactory.newHazelcastInstance(config);
  IMap m3=h3.getMap(MAP_NAME);
  h2.shutdown();
  assertEquals(size,m3.size());
  HazelcastInstance h4=nodeFactory.newHazelcastInstance(config);
  IMap m4=h4.getMap(MAP_NAME);
  h3.shutdown();
  assertEquals(size,m4.size());
}

Fixed version (ground truth):
@Test public void testGracefulShutdown() throws Exception {
  int size=50000;
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  final Config config=new Config();
  HazelcastInstance h1=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m1=h1.getMap(MAP_NAME);
  for (int i=0; i < size; i++) {
    m1.put(i,i);
  }
  HazelcastInstance h2=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m2=h2.getMap(MAP_NAME);
  shutdownAndWait(h1);
  waitForSafeStateAndCheckSize(size,h2,m2);
  HazelcastInstance h3=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m3=h3.getMap(MAP_NAME);
  shutdownAndWait(h2);
  waitForSafeStateAndCheckSize(size,h3,m3);
  HazelcastInstance h4=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m4=h4.getMap(MAP_NAME);
  shutdownAndWait(h3);
  waitForSafeStateAndCheckSize(size,h4,m4);
}
Program: 48048
Project: 48048
Buggy source:
/** 
 * Test for issue #259.
 */
@Test public void testBackupPutWhenOwnerNodeDead() throws InterruptedException {
  final TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(2);
  final String name=MAP_NAME;
  final HazelcastInstance hz=nodeFactory.newHazelcastInstance();
  final HazelcastInstance hz2=nodeFactory.newHazelcastInstance();
  final IMap<Object,Object> map=hz2.getMap(name);
  final int size=100000;
  final byte[] data=new byte[250];
  final int threads=100;
  final int l=size / threads;
  final CountDownLatch latch=new CountDownLatch(threads);
  ExecutorService ex=Executors.newFixedThreadPool(threads);
  new Thread(){
    public void run(){
      while (hz.getMap(name).size() < size / 2) {
        try {
          sleep(5);
        }
 catch (        InterruptedException ignored) {
          return;
        }
      }
      TestUtil.terminateInstance(hz);
    }
  }
.start();
  for (int i=0; i < threads; i++) {
    final int n=i;
    ex.execute(new Runnable(){
      public void run(){
        for (int j=(n * l); j < (n + 1) * l; j++) {
          map.put(j,data);
          try {
            Thread.sleep(1);
          }
 catch (          InterruptedException ignored) {
            return;
          }
        }
        latch.countDown();
      }
    }
);
  }
  try {
    assertTrue(latch.await(5,TimeUnit.MINUTES));
    assertEquals("String_Node_Str",size,map.size());
  }
  finally {
    ex.shutdownNow();
  }
}

Fixed version (ground truth):
/** 
 * Test for issue #259.
 */
@Test public void testBackupPutWhenOwnerNodeDead() throws InterruptedException {
  final TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(2);
  final String name=MAP_NAME;
  final HazelcastInstance hz=nodeFactory.newHazelcastInstance();
  final HazelcastInstance hz2=nodeFactory.newHazelcastInstance();
  final IMap<Integer,byte[]> map=hz2.getMap(name);
  final int size=100000;
  final byte[] data=new byte[250];
  final int threads=100;
  final int l=size / threads;
  final CountDownLatch latch=new CountDownLatch(threads);
  ExecutorService ex=Executors.newFixedThreadPool(threads);
  new Thread(){
    public void run(){
      while (hz.getMap(name).size() < size / 2) {
        try {
          sleep(5);
        }
 catch (        InterruptedException ignored) {
          return;
        }
      }
      TestUtil.terminateInstance(hz);
    }
  }
.start();
  for (int i=0; i < threads; i++) {
    final int n=i;
    ex.execute(new Runnable(){
      public void run(){
        for (int j=(n * l); j < (n + 1) * l; j++) {
          map.put(j,data);
          try {
            Thread.sleep(1);
          }
 catch (          InterruptedException ignored) {
            return;
          }
        }
        latch.countDown();
      }
    }
);
  }
  try {
    assertTrue(latch.await(5,TimeUnit.MINUTES));
    assertEquals("String_Node_Str",size,map.size());
  }
  finally {
    ex.shutdownNow();
  }
}
Program: 48050
Project: 48050
Buggy source:
/** 
 * Tests data safety when multiple nodes start and a non-master node is shutdown immediately after start and doing a partition based operation.
 */
@Test public void testGracefulShutdown_Issue2804(){
  Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_COUNT,"String_Node_Str");
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance h1=factory.newHazelcastInstance(config);
  HazelcastInstance h2=factory.newHazelcastInstance(config);
  String key="String_Node_Str";
  String value="String_Node_Str";
  IMap<String,String> map=h1.getMap(MAP_NAME);
  map.put(key,value);
  h2.shutdown();
  Assert.assertEquals(value,map.get(key));
}

Fixed version (ground truth):
/** 
 * Tests data safety when multiple nodes start and a non-master node is shutdown immediately after start and doing a partition based operation.
 */
@Test public void testGracefulShutdown_Issue2804(){
  Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_COUNT,"String_Node_Str");
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance h1=factory.newHazelcastInstance(config);
  HazelcastInstance h2=factory.newHazelcastInstance(config);
  String key="String_Node_Str";
  String value="String_Node_Str";
  IMap<String,String> map=h1.getMap(MAP_NAME);
  map.put(key,value);
  h2.shutdown();
  assertEquals(value,map.get(key));
}
Program: 48051
Project: 48051
Buggy source:
private void shutdownAndWait(HazelcastInstance instance){
  instance.shutdown();
  waitForTermination(instance);
}

Fixed version (ground truth):
private void shutdownAndWait(HazelcastInstance instance){
  long migrationActivationDelay=findMigrationActivationDelayTime(instance);
  instance.shutdown();
  waitForTermination(instance,migrationActivationDelay);
}
Program: 48054
Project: 48054
Buggy source:
@Test public void testGracefulShutdown() throws Exception {
  int size=50000;
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  final Config config=new Config();
  HazelcastInstance h1=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m1=h1.getMap(MAP_NAME);
  for (int i=0; i < size; i++) {
    m1.put(i,i);
  }
  HazelcastInstance h2=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m2=h2.getMap(MAP_NAME);
  shutdownAndWait(h1);
  waitForMigrationAndCheckSize(size,h2,m2);
  HazelcastInstance h3=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m3=h3.getMap(MAP_NAME);
  shutdownAndWait(h2);
  waitForMigrationAndCheckSize(size,h3,m3);
  HazelcastInstance h4=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m4=h4.getMap(MAP_NAME);
  shutdownAndWait(h3);
  waitForMigrationAndCheckSize(size,h4,m4);
}

Fixed version (ground truth):
@Test public void testGracefulShutdown() throws Exception {
  int size=50000;
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  final Config config=new Config();
  HazelcastInstance h1=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m1=h1.getMap(MAP_NAME);
  for (int i=0; i < size; i++) {
    m1.put(i,i);
  }
  HazelcastInstance h2=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m2=h2.getMap(MAP_NAME);
  shutdownAndWait(h1);
  waitForSafeStateAndCheckSize(size,h2,m2);
  HazelcastInstance h3=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m3=h3.getMap(MAP_NAME);
  shutdownAndWait(h2);
  waitForSafeStateAndCheckSize(size,h3,m3);
  HazelcastInstance h4=nodeFactory.newHazelcastInstance(config);
  IMap<Integer,Integer> m4=h4.getMap(MAP_NAME);
  shutdownAndWait(h3);
  waitForSafeStateAndCheckSize(size,h4,m4);
}
Program: 48055
Project: 48055
Buggy source:
private void waitForTermination(final HazelcastInstance instance){
  final Node node=TestUtil.getNode(instance);
  if (node != null) {
    assertTrueEventually(new AssertTask(){
      public void run(){
        assertFalse(node.isActive());
      }
    }
);
  }
  sleepSeconds(3);
  for (  HazelcastInstance hz : HazelcastInstanceFactory.getAllHazelcastInstances()) {
    if (hz != instance) {
      waitForMigration(instance);
    }
  }
}

Fixed version (ground truth):
private void waitForTermination(final HazelcastInstance instance,final long migrationActivationDelay){
  final Node node=TestUtil.getNode(instance);
  if (node != null) {
    assertTrueEventually(new AssertTask(){
      public void run(){
        assertFalse(node.isActive());
      }
    }
);
  }
  sleepMillis((int)migrationActivationDelay);
  assertTrueEventually(new AssertTask(){
    public void run(){
      boolean allNodesAreInSafeState=true;
      for (      HazelcastInstance hz : HazelcastInstanceFactory.getAllHazelcastInstances()) {
        if (hz != instance) {
          if (!isInSafeState(hz)) {
            allNodesAreInSafeState=false;
            break;
          }
        }
      }
      assertTrue(allNodesAreInSafeState);
    }
  }
);
}
Program: 48056
Project: 48056
Buggy source:
private void doChunkedLoad(Map<Data,Object> loadedKeys,NodeEngine nodeEngine){
  final int mapLoadChunkSize=getLoadBatchSize();
  final Queue<Map> chunks=new LinkedList<Map>();
  Map<Data,Object> partitionKeys=new HashMap<Data,Object>();
  final int partitionId=this.partitionId;
  Iterator<Map.Entry<Data,Object>> iterator=loadedKeys.entrySet().iterator();
  while (iterator.hasNext()) {
    final Map.Entry<Data,Object> entry=iterator.next();
    final Data data=entry.getKey();
    if (partitionId == nodeEngine.getPartitionService().getPartitionId(data)) {
      partitionKeys.put(data,entry.getValue());
      if (partitionKeys.size() >= mapLoadChunkSize) {
        chunks.add(partitionKeys);
        partitionKeys=new HashMap<Data,Object>();
      }
      iterator.remove();
    }
  }
  if (!partitionKeys.isEmpty()) {
    chunks.add(partitionKeys);
  }
  if (chunks.isEmpty()) {
    setLoaded(true);
    return;
  }
  try {
    this.throwable=null;
    final AtomicInteger checkIfMapLoaded=new AtomicInteger(chunks.size());
    ExecutionService executionService=nodeEngine.getExecutionService();
    Map<Data,Object> chunkedKeys;
    while ((chunkedKeys=chunks.poll()) != null) {
      final Callback<Throwable> callback=createCallbackForThrowable();
      executionService.submit(ExecutionService.MAP_LOADER_EXECUTOR,new MapLoadAllTask(chunkedKeys,checkIfMapLoaded,callback));
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
}

Fixed version (ground truth):
private void doChunkedLoad(Map<Data,Object> loadedKeys,NodeEngine nodeEngine){
  final int mapLoadChunkSize=getLoadBatchSize();
  final Queue<Map> chunks=new LinkedList<Map>();
  Map<Data,Object> partitionKeys=new HashMap<Data,Object>();
  final int partitionId=this.partitionId;
  Iterator<Map.Entry<Data,Object>> iterator=loadedKeys.entrySet().iterator();
  while (iterator.hasNext()) {
    final Map.Entry<Data,Object> entry=iterator.next();
    final Data data=entry.getKey();
    if (partitionId == nodeEngine.getPartitionService().getPartitionId(data)) {
      partitionKeys.put(data,entry.getValue());
      if (partitionKeys.size() >= mapLoadChunkSize) {
        chunks.add(partitionKeys);
        partitionKeys=new HashMap<Data,Object>();
      }
      iterator.remove();
    }
  }
  if (!partitionKeys.isEmpty()) {
    chunks.add(partitionKeys);
  }
  if (chunks.isEmpty()) {
    setLoaded(true);
    return;
  }
  try {
    this.throwable=null;
    final AtomicInteger checkIfMapLoaded=new AtomicInteger(chunks.size());
    ExecutionService executionService=nodeEngine.getExecutionService();
    Map<Data,Object> chunkedKeys;
    while ((chunkedKeys=chunks.poll()) != null) {
      final Callback<Throwable> callback=createCallbackForThrowable();
      MapLoadAllTask task=new MapLoadAllTask(chunkedKeys,checkIfMapLoaded,callback);
      executionService.submit(ExecutionService.MAP_LOADER_EXECUTOR,task);
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
}
Program: 48057
Project: 48057
Buggy source:
/** 
 * Tests data safety when multiple nodes start and a non-master node is shutdown immediately after start and doing a partition based operation.
 */
@Test public void testGracefulShutdown_Issue2804(){
  Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_COUNT,"String_Node_Str");
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance h1=factory.newHazelcastInstance(config);
  HazelcastInstance h2=factory.newHazelcastInstance(config);
  Object key="String_Node_Str";
  Object value="String_Node_Str";
  IMap<Object,Object> map=h1.getMap(MAP_NAME);
  map.put(key,value);
  h2.shutdown();
  Assert.assertEquals(value,map.get(key));
}

Fixed version (ground truth):
/** 
 * Tests data safety when multiple nodes start and a non-master node is shutdown immediately after start and doing a partition based operation.
 */
@Test public void testGracefulShutdown_Issue2804(){
  Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_COUNT,"String_Node_Str");
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance h1=factory.newHazelcastInstance(config);
  HazelcastInstance h2=factory.newHazelcastInstance(config);
  String key="String_Node_Str";
  String value="String_Node_Str";
  IMap<String,String> map=h1.getMap(MAP_NAME);
  map.put(key,value);
  h2.shutdown();
  Assert.assertEquals(value,map.get(key));
}
Program: 48058
Project: 48058
Buggy source:
@Test public void testGracefulShutdown2() throws Exception {
  Config config=new Config();
  config.getMapConfig(MAP_NAME).setBackupCount(2);
  TestHazelcastInstanceFactory f=createHazelcastInstanceFactory(6);
  final HazelcastInstance hz=f.newHazelcastInstance(config);
  final IMap<Object,Object> map=hz.getMap(MAP_NAME);
  final int size=50000;
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  final HazelcastInstance hz2=f.newHazelcastInstance(config);
  final IMap<Object,Object> map2=hz2.getMap(MAP_NAME);
  assertEquals(size,map2.size());
  final HazelcastInstance hz3=f.newHazelcastInstance(config);
  final IMap<Object,Object> map3=hz3.getMap(MAP_NAME);
  final HazelcastInstance hz4=f.newHazelcastInstance(config);
  final IMap<Object,Object> map4=hz4.getMap(MAP_NAME);
  assertEquals(size,map3.size());
  assertEquals(size,map4.size());
  final HazelcastInstance hz5=f.newHazelcastInstance(config);
  final IMap<Object,Object> map5=hz5.getMap(MAP_NAME);
  final HazelcastInstance hz6=f.newHazelcastInstance(config);
  final IMap<Object,Object> map6=hz6.getMap(MAP_NAME);
  assertEquals(size,map5.size());
  assertEquals(size,map6.size());
  hz.shutdown();
  hz2.shutdown();
  assertEquals(size,map3.size());
  assertEquals(size,map4.size());
  assertEquals(size,map5.size());
  assertEquals(size,map6.size());
  hz3.shutdown();
  hz4.shutdown();
  assertEquals(size,map5.size());
  assertEquals(size,map6.size());
}

Fixed version (ground truth):
@Test public void testGracefulShutdown2() throws Exception {
  Config config=new Config();
  config.getMapConfig(MAP_NAME).setBackupCount(2);
  TestHazelcastInstanceFactory f=createHazelcastInstanceFactory(6);
  final HazelcastInstance hz=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map=hz.getMap(MAP_NAME);
  final int size=50000;
  for (int i=0; i < size; i++) {
    map.put(i,i);
  }
  final HazelcastInstance hz2=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map2=hz2.getMap(MAP_NAME);
  waitForMigrationAndCheckSize(size,hz2,map2);
  final HazelcastInstance hz3=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map3=hz3.getMap(MAP_NAME);
  final HazelcastInstance hz4=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map4=hz4.getMap(MAP_NAME);
  waitForMigrationAndCheckSize(size,hz3,map3);
  waitForMigrationAndCheckSize(size,hz4,map4);
  final HazelcastInstance hz5=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map5=hz5.getMap(MAP_NAME);
  final HazelcastInstance hz6=f.newHazelcastInstance(config);
  final IMap<Integer,Integer> map6=hz6.getMap(MAP_NAME);
  waitForMigrationAndCheckSize(size,hz5,map5);
  waitForMigrationAndCheckSize(size,hz6,map6);
  shutdownAndWait(hz);
  shutdownAndWait(hz2);
  waitForMigrationAndCheckSize(size,hz3,map3);
  waitForMigrationAndCheckSize(size,hz4,map4);
  waitForMigrationAndCheckSize(size,hz5,map5);
  waitForMigrationAndCheckSize(size,hz6,map6);
  shutdownAndWait(hz3);
  shutdownAndWait(hz4);
  waitForMigrationAndCheckSize(size,hz5,map5);
  waitForMigrationAndCheckSize(size,hz6,map6);
}
Program: 48060
Project: 48060
Buggy source:
private void testBackupMigrationAndRecovery(int nodeCount,int backupCount,int mapSize) throws Exception {
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(nodeCount);
  final String name=MAP_NAME;
  final Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_BACKUP_SYNC_INTERVAL,"String_Node_Str");
  config.getMapConfig(name).setBackupCount(backupCount).setStatisticsEnabled(true);
  final HazelcastInstance[] instances=new HazelcastInstance[nodeCount];
  HazelcastInstance hz=nodeFactory.newHazelcastInstance(config);
  instances[0]=hz;
  IMap map1=hz.getMap(name);
  for (int i=0; i < mapSize; i++) {
    map1.put(i,"String_Node_Str" + i);
  }
  checkMapSizes(mapSize,backupCount,instances);
  for (int i=1; i < nodeCount; i++) {
    instances[i]=nodeFactory.newHazelcastInstance(config);
    checkMapSizes(mapSize,backupCount,instances);
  }
  final Random rand=new Random();
  for (int i=1; i < nodeCount; i++) {
    int ix;
    do {
      ix=rand.nextInt(nodeCount);
    }
 while (instances[ix] == null);
    TestUtil.terminateInstance(instances[ix]);
    instances[ix]=null;
    checkMapSizes(mapSize,backupCount,instances);
  }
}

Fixed version (ground truth):
private void testBackupMigrationAndRecovery(int nodeCount,int backupCount,int mapSize) throws Exception {
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(nodeCount);
  final String name=MAP_NAME;
  final Config config=new Config();
  config.setProperty(GroupProperties.PROP_PARTITION_BACKUP_SYNC_INTERVAL,"String_Node_Str");
  config.getMapConfig(name).setBackupCount(backupCount).setStatisticsEnabled(true);
  final HazelcastInstance[] instances=new HazelcastInstance[nodeCount];
  HazelcastInstance hz=nodeFactory.newHazelcastInstance(config);
  instances[0]=hz;
  IMap<Integer,String> map1=hz.getMap(name);
  for (int i=0; i < mapSize; i++) {
    map1.put(i,"String_Node_Str" + i);
  }
  checkMapSizes(mapSize,backupCount,instances);
  for (int i=1; i < nodeCount; i++) {
    instances[i]=nodeFactory.newHazelcastInstance(config);
    checkMapSizes(mapSize,backupCount,instances);
  }
  final Random rand=new Random();
  for (int i=1; i < nodeCount; i++) {
    int ix;
    do {
      ix=rand.nextInt(nodeCount);
    }
 while (instances[ix] == null);
    TestUtil.terminateInstance(instances[ix]);
    instances[ix]=null;
    checkMapSizes(mapSize,backupCount,instances);
  }
}