Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing a Read of a value not modifed in a transaction causes an update listener to fire for that entry #311

ben-bar opened this issue Oct 18, 2012 · 1 comment


None yet
2 participants
Copy link

commented Oct 18, 2012

Behaviour is confirmed to not happen in 1.9.4 but does happen 2.2.0 and 2.3.1. When doing a read within a transaction, an update listener is fired for the object on commit. Please see attached test case.

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import org.junit.Test;

import com.hazelcast.config.Config;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryListener;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.Transaction;

public class HazelcastUpdateListenerProblem {

public void testUpdateCallbackNotCalled() throws Exception {

    Config config = new Config();
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);

    IMap<String, Long> testMap = h2.getMap("TEST");

    // put a single value in one transaction and commit it
    Transaction transaction = h2.getTransaction();

    testMap.put("VALUE1", 1L);


    final CountDownLatch updateCallback = new CountDownLatch(1);
    final CountDownLatch evictedCallback = new CountDownLatch(1);
    final CountDownLatch removedCallback = new CountDownLatch(1);
    final CountDownLatch addedCallback = new CountDownLatch(1);

    testMap.addEntryListener(new EntryListener<String, Long>() {
        public void entryAdded(EntryEvent<String, Long> event) {
            System.out.println("Added Key Received: " + event.getKey());
        public void entryRemoved(EntryEvent<String, Long> event) {
            System.out.println("Removed Key Received: " + event.getKey());
        public void entryUpdated(EntryEvent<String, Long> event) {
            System.out.println("Updated Key Received: " + event.getKey());
        public void entryEvicted(EntryEvent<String, Long> event) {
            System.out.println("Evicted Key Received: " + event.getKey());
    }, true);

    // start a new transaction, putting a new value in the same map and also doing a 'get' on the original value
    transaction = h2.getTransaction();

    testMap.put("VALUE2", 2L);


    // commit the transaction

    // we are expecting a single 'added' listener callback, but also getting an update callback on the value that had 'get' call
    Assert.assertFalse("Evicted Listener Shouldnt be called", evictedCallback.await(2, TimeUnit.SECONDS));
    Assert.assertFalse("Remove Listener Shouldnt be called", removedCallback.await(2, TimeUnit.SECONDS));
    Assert.assertFalse("Update Listener Shouldnt be called for old value", updateCallback.await(2, TimeUnit.SECONDS));
    Assert.assertTrue("Add Listener Should be called for new value", addedCallback.await(2, TimeUnit.SECONDS));



This comment has been minimized.

Copy link

commented Aug 28, 2013

Fixed by commit 98b900c

@mdogan mdogan closed this Aug 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.