Skip to content

Instantly share code, notes, and snippets.

@emrahkocaman
Created February 9, 2016 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrahkocaman/92755f326c186fbf2579 to your computer and use it in GitHub Desktop.
Save emrahkocaman/92755f326c186fbf2579 to your computer and use it in GitHub Desktop.
package com.hazelcast.internal.jmx;
import com.hazelcast.core.IAtomicLong;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.TestHazelcastInstanceFactory;
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import java.util.concurrent.TimeUnit;
@RunWith(HazelcastParallelClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
public class InstanceShutdownTest extends HazelcastTestSupport {
private MBeanDataHolder holder;
private MBeanDataHolder holder2;
@Before
public void setUp() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
holder = new MBeanDataHolder(factory);
holder2 = new MBeanDataHolder(factory);
}
@Test
public void testInstanceShutdown() throws Exception {
IAtomicLong atomicLong = holder.getHz().getAtomicLong("atomiclong");
atomicLong.incrementAndGet();
holder.assertMBeanExistEventually("IAtomicLong", atomicLong.getName());
holder.getHz().shutdown();
holder2.assertMBeanExistEventually("IAtomicLong", atomicLong.getName());
}
}
@mirkosertic
Copy link

Hey,

thank you for your feedback.

Your testcase does not cover my case. shutdownAll is indeed called by HazelcastInstanceFactory.remove() which is called as part of the shutdown process. See the following code snippet:

    static void remove(HazelcastInstanceImpl instance) {
        OutOfMemoryErrorDispatcher.deregisterServer(instance);
        InstanceFuture future = INSTANCE_MAP.remove(instance.getName());
        if (future != null) {
            future.get().original = null;
        }
        if (INSTANCE_MAP.size() == 0) {
            ManagementService.shutdownAll();
        }
    }
´´´

This definitely unregisters ALL running Hazelcast instances in the same VM, even if they were created by different web applications and by different class loaders.

@emrahkocaman
Copy link
Author

@mirkosertic, but this happens only if INSTANCE_MAP size is 0. All instances are needed to be shutdown for this to work, am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment