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

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

Comments

Projects
None yet
2 participants
@ben-bar
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 {

@Test
public void testUpdateCallbackNotCalled() throws Exception {

    Config config = new Config();
    config.getGroupConfig().setName("TestCluster");
    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();
    transaction.begin();

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

    transaction.commit();

    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());
            addedCallback.countDown();
        }
        public void entryRemoved(EntryEvent<String, Long> event) {
            System.out.println("Removed Key Received: " + event.getKey());
            removedCallback.countDown();
        }
        public void entryUpdated(EntryEvent<String, Long> event) {
            System.out.println("Updated Key Received: " + event.getKey());
            updateCallback.countDown();
        }
        public void entryEvicted(EntryEvent<String, Long> event) {
            System.out.println("Evicted Key Received: " + event.getKey());
            evictedCallback.countDown();
        }
    }, 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();
    transaction.begin();

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

    testMap.get("VALUE1");

    // commit the transaction
    transaction.commit();

    // 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));
}

}

@mdogan

This comment has been minimized.

Copy link
Member

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.