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

LocalMapStats doesn't record stats about locked entries in 3.x #2876

Closed
PierreCoquentin opened this issue Jul 2, 2014 · 5 comments
Closed
Assignees
Milestone

Comments

@PierreCoquentin
Copy link

The following test works with hazelcast 2.6.9 but fails with hazelcast 3.2.3 on the first assertEquals. The counter "lockedEntryCount" is always 0.
Moreover, the method getLockWaitCount has been removed but nothing indicates if this data is still accessible somewhere. We use in our project this two counters to monitor cluster-wide locks.

package test.hazelcast;

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.Assert.assertEquals;

public class LockTest {

    private static HazelcastInstance hazelcast;
    private IMap<String, String> map;

    @BeforeClass
    public static void beforeClass() {
        hazelcast = Hazelcast.newHazelcastInstance();
    }

    @Before
    public void before() {
        map = hazelcast.getMap("test");
    }

    @Test
    public void testLock() {
        AtomicBoolean lock = new AtomicBoolean(true);
        Runner locker = new Runner(lock);
        new Thread(locker).start();

        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {

        }

        assertEquals(1, map.getLocalMapStats().getLockedEntryCount());

        lock.set(false);

        try {
            TimeUnit.MILLISECONDS.sleep(600);
        } catch (InterruptedException e) {

        }

        assertEquals(0, map.getLocalMapStats().getLockedEntryCount());
    }

    private class Runner implements Runnable {

        private AtomicBoolean lock;

        private Runner(AtomicBoolean lock) {
            this.lock = lock;
        }

        @Override
        public void run() {
            map.lock("lock");
            try {
                // sleep
                while (lock.get() && !Thread.interrupted()) {
                    try {
                        TimeUnit.MILLISECONDS.sleep(500);
                    } catch (InterruptedException e) {

                    }
                }
            } finally {
                map.unlock("lock");
            }
        }
    }
}
@enesakar enesakar added this to the 3.3 milestone Jul 2, 2014
@ahmetmircik
Copy link
Member

Current behavior: First you should put an entry with the key "lock" then you can expect this will appear in the stats. AFAIS you are not putting an entry in your test.

@PierreCoquentin
Copy link
Author

Ok so the behavior has changed between 2.6.9 and 3.2.3.
And what about the removed method (getLockWaitCount), is there a way to get number of threads waiting for the locks ? Or is it no longer available ?
Thanks

@ahmetmircik
Copy link
Member

getLockWaitCount is not available in 3.x and no simple workaround seems can be done atm, If you want you can create a separate feature request issue for it.

@PierreCoquentin
Copy link
Author

Thank you for your time

@ahmetmircik
Copy link
Member

Ok then closing this issue now.

@ahmetmircik ahmetmircik self-assigned this Jul 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants