Program: 48429
Project: 48429
Buggy source:
@Test @Category(ProblematicTest.class) public void testIssue859And863() throws Exception {
  final int numberOfMessages=20000;
  final AtomicInteger count=new AtomicInteger();
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance instance1=factory.newHazelcastInstance();
  HazelcastInstance instance2=factory.newHazelcastInstance();
  String inQueueName="String_Node_Str";
  String outQueueName="String_Node_Str";
  for (int i=0; i < numberOfMessages; i++) {
    if (!instance1.getQueue(inQueueName).offer(new byte[1024])) {
      throw new RuntimeException("String_Node_Str");
    }
  }
class MoveMessage extends Thread {
    private final HazelcastInstance hazelcastInstance;
    private final String inQueueName;
    private final String outQueueName;
    private volatile boolean active=true;
    public MoveMessage(    HazelcastInstance hazelcastInstance,    String inQueueName,    String outQueueName){
      this.hazelcastInstance=hazelcastInstance;
      this.inQueueName=inQueueName;
      this.outQueueName=outQueueName;
    }
    public void run(){
      while (active && count.get() != numberOfMessages && hazelcastInstance.getLifecycleService().isRunning()) {
        TransactionContext transactionContext=hazelcastInstance.newTransactionContext();
        try {
          transactionContext.beginTransaction();
        }
 catch (        HazelcastInstanceNotActiveException ignored) {
          break;
        }
        try {
          TransactionalQueue<Object> queue=transactionContext.getQueue(inQueueName);
          Object value=queue.poll();
          if (value != null) {
            TransactionalQueue<Object> outQueue=transactionContext.getQueue(outQueueName);
            if (!outQueue.offer(value)) {
              throw new RuntimeException();
            }
          }
          transactionContext.commitTransaction();
          if (value != null) {
            count.incrementAndGet();
          }
        }
 catch (        Exception e) {
          try {
            transactionContext.rollbackTransaction();
          }
 catch (          HazelcastInstanceNotActiveException ignored) {
          }
        }
      }
    }
  }
  MoveMessage moveMessage1=new MoveMessage(instance1,inQueueName,outQueueName);
  MoveMessage moveMessage2=new MoveMessage(instance2,inQueueName,outQueueName);
  moveMessage1.start();
  moveMessage2.start();
  while (count.get() < numberOfMessages / 2) {
    Thread.sleep(10);
  }
  instance2.getLifecycleService().terminate();
  moveMessage2.active=false;
  moveMessage2.join(10000);
  moveMessage1.join(30000);
  try {
    assertEquals(numberOfMessages,instance1.getQueue(outQueueName).size());
    assertTrue(instance1.getQueue(inQueueName).isEmpty());
  }
  finally {
    moveMessage1.active=false;
  }
}

Fixed version (ground truth):
/** 
 * Moved from   {@link com.hazelcast.test.annotation.ProblematicTest}
 * @throws Exception
 */
@Test public void testIssue859And863() throws Exception {
  final int numberOfMessages=2000;
  final AtomicInteger count=new AtomicInteger();
  TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(2);
  HazelcastInstance instance1=factory.newHazelcastInstance();
  HazelcastInstance instance2=factory.newHazelcastInstance();
  String inQueueName="String_Node_Str";
  String outQueueName="String_Node_Str";
  for (int i=0; i < numberOfMessages; i++) {
    if (!instance1.getQueue(inQueueName).offer(i)) {
      throw new RuntimeException("String_Node_Str");
    }
  }
class MoveMessage extends Thread {
    private final HazelcastInstance hazelcastInstance;
    private final String inQueueName;
    private final String outQueueName;
    private volatile boolean active=true;
    public MoveMessage(    HazelcastInstance hazelcastInstance,    String inQueueName,    String outQueueName){
      this.hazelcastInstance=hazelcastInstance;
      this.inQueueName=inQueueName;
      this.outQueueName=outQueueName;
    }
    public void run(){
      while (active && count.get() != numberOfMessages && hazelcastInstance.getLifecycleService().isRunning()) {
        TransactionContext transactionContext=hazelcastInstance.newTransactionContext();
        try {
          transactionContext.beginTransaction();
        }
 catch (        HazelcastInstanceNotActiveException ignored) {
          break;
        }
        try {
          TransactionalQueue<Object> queue=transactionContext.getQueue(inQueueName);
          Object value=queue.poll();
          if (value != null) {
            TransactionalQueue<Object> outQueue=transactionContext.getQueue(outQueueName);
            if (!outQueue.offer(value)) {
              throw new RuntimeException();
            }
          }
          transactionContext.commitTransaction();
          if (value != null) {
            count.incrementAndGet();
          }
        }
 catch (        Exception e) {
          try {
            transactionContext.rollbackTransaction();
          }
 catch (          HazelcastInstanceNotActiveException ignored) {
          }
        }
      }
    }
  }
  MoveMessage moveMessage1=new MoveMessage(instance1,inQueueName,outQueueName);
  MoveMessage moveMessage2=new MoveMessage(instance2,inQueueName,outQueueName);
  moveMessage1.start();
  moveMessage2.start();
  while (count.get() < numberOfMessages / 2) {
    sleepMillis(1);
  }
  instance2.getLifecycleService().terminate();
  moveMessage2.active=false;
  moveMessage2.join(10000);
  moveMessage1.join(10000);
  try {
    assertEquals(numberOfMessages,instance1.getQueue(outQueueName).size());
    assertTrue(instance1.getQueue(inQueueName).isEmpty());
  }
  finally {
    moveMessage1.active=false;
  }
}