hazelcast/hazelcast-stabilizer — pull request #239 by serkan-ozal (2014-08-26 11:50:17+00:00)
Title: stabilizer test fix for issue #3229

**"MapTransactionContextTest"** test has error in some cases.

~~~~ java
try{
context.beginTransaction();
final TransactionalMap map = context.getMap(basename);

Long current = map.getForUpdate(key);
Long update = current + increment;
map.put(key, update);

localIncrements[key]+=increment;
count.committed++;

context.commitTransaction();

}catch(Exception commitFailed){
try{
context.rollbackTransaction();
count.rolled++;
count.committed--;
localIncrements[key]-=increment;

System.out.println(basename+": commit fail key="+key+" inc="+increment+" "+commitFailed);
commitFailed.printStackTrace();

}catch(Exception rollBackFailed){
count.failedRoles++;
System.out.println(basename+": rollback fail key="+key+" inc="+increment+" "+rollBackFailed);
rollBackFailed.printStackTrace();
}
}
~~~~

**Error 1:** If **"context.getMap(basename);"** or **"map.getForUpdate(key);"** fails (such as Hazelcast instance not active exception),
local keys are **not increased** but **decreased** in **"catch"** block.

**Error 2:** If **"context.rollbackTransaction();"** fails,
local keys are **increased** but **not decreased** since key decrement is done after transaction rollback.

For this test case, we can see that there is **"90"** difference between expected (**"1680"**) and actual (**"1770"**) values of key **"430"**
And from the logs, we can see that
(**"txnCon: commit fail key=430 inc=90 com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!"**)
operation fails before commit transaction (since there is Hazelcast instance not active exception) and
local key **increments** were **not done**. But local key **decrements** were **done** after transaction rollback.
So local keys are **decreased without increased** and this explains the difference value **"90"** (**inc=90**)
between expected (**"1680"**) and actual (**"1770"**) values of key **"430"**.

I think, test should be like this

~~~~ java
try {
context.beginTransaction();
final TransactionalMap map = context.getMap(basename);

Long current = map.getForUpdate(key);
Long update = current + increment;
map.put(key, update);

context.commitTransaction();

// Do local increments if commit is successful, so there is no needed decrement operation
localIncrements[key] += increment;
count.committed++;
} catch(Exception commitFailed) {
try {
context.rollbackTransaction();
count.rolled++;

System.out.println(basename+": commit fail key="+key+" inc="+increment+" "+commitFailed);
commitFailed.printStackTrace();

} catch(Exception rollBackFailed) {
count.failedRoles++;

System.out.println(basename+": rollback fail key="+key+" inc="+increment+" "+rollBackFailed);
rollBackFailed.printStackTrace();
}
}
~~~~