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

Map EntryListener not working correctly if one master is restarted #269

Closed
notz opened this issue Sep 10, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@notz
Copy link
Contributor

commented Sep 10, 2012

For example is have a cluster running with 2 master instances and 1 lite member. I start the 2 master and then connect with my super client where if have added a map entry listener. Then i shutdown one master and restart it. From now on i get only entry's from older master. The problem occurs not always but it seems in about 50% of trials.
Hazelcast Version used 2.3.1.

Here is a small testing code:

I have updated the testing code in 1st comment.

@notz

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2012

Here is a newer test script, which runs until the error occurs:

import com.hazelcast.config.Config;
import com.hazelcast.config.GroupConfig;
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;


public class LiteMemberListenerTest {

    private static int adds = 0;

    public static void main(String[] args) throws InterruptedException {

        Config config = new Config();
        config.setGroupConfig(new GroupConfig("test", "test"));
        config.getNetworkConfig().setPort(6701);

        HazelcastInstance hazelcastInstance1 = Hazelcast.newHazelcastInstance(config);

        Hazelcast.newHazelcastInstance(config);

        Config liteMemberConfig = new Config();
        liteMemberConfig.setGroupConfig(new GroupConfig("test", "test"));
        liteMemberConfig.getNetworkConfig().setPort(6711);
        liteMemberConfig.setLiteMember(true);
        HazelcastInstance liteMember = Hazelcast.newHazelcastInstance(liteMemberConfig);

        IMap<Integer, String> map = liteMember.getMap("test");
        map.addEntryListener(new EntryListener<Integer, String>() {

            public void entryAdded(EntryEvent<Integer, String> event) {
                adds++;
            }

            public void entryRemoved(EntryEvent<Integer, String> event) {}

            public void entryUpdated(EntryEvent<Integer, String> event) {}

            public void entryEvicted(EntryEvent<Integer, String> event) {}
        }, true);

        adds = 0;

        map.put(1, "1");
        map.put(2, "2");
        map.put(3, "3");
        map.put(4, "4");
        map.put(5, "5");
        map.put(6, "6");
        map.put(7, "7");

        Thread.sleep(2000);

        if (adds != 7) {
            System.out.println("ERROR: only got " + adds + " adds out of 7 - without restart");
            System.exit(0);
        } else {
            System.out.println("OK: got " + adds + " adds out of 7 - without restart");
        }

        while (true) {

            map.clear();

            hazelcastInstance1.getLifecycleService().shutdown();

            Thread.sleep(5000);

            hazelcastInstance1 = Hazelcast.newHazelcastInstance(config);

            Thread.sleep(10000);

            adds = 0;

            map.put(1, "1");
            map.put(2, "2");
            map.put(3, "3");
            map.put(4, "4");
            map.put(5, "5");
            map.put(6, "6");
            map.put(7, "7");

            Thread.sleep(2000);

            if (adds != 7) {
                System.out.println("ERROR: only got " + adds + " adds out of 7");
                System.exit(0);
            } else {
                System.out.println("OK: got " + adds + " adds out of 7");
            }
        }
    }
}
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.