s/in on instance/in one instance/g IMO we need to terminate the instance notifier event receiver Runnable and cancel the ScheduledFuture of health stat notifier. Please see the below fix:
/** @@ -51,6 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=fda1bf0fade708667188261eb30f33185e8fed79#l51> +52,8 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=1a7d93f8c3315435c8387bdf232808688e104a61;hb=b7840d8ee912a2c6bc7a084eeb1879a65625617a#l52> @@ public class MockInstance implements Runnable, Serializable { private final MockInstanceContext mockMemberContext; private boolean terminated; + private ScheduledFuture<?> healthStatNotifierScheduledFuture; + private InstanceNotifierEventReceiver instanceNotifierEventReceiver; public MockInstance(MockInstanceContext mockMemberContext) { this.mockMemberContext = mockMemberContext; @@ -88,7 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=fda1bf0fade708667188261eb30f33185e8fed79#l88> +91,7 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=1a7d93f8c3315435c8387bdf232808688e104a61;hb=b7840d8ee912a2c6bc7a084eeb1879a65625617a#l91> @@ public class MockInstance implements Runnable, Serializable { log.debug("Starting instance notifier event message receiver"); } - final InstanceNotifierEventReceiver instanceNotifierEventReceiver = new InstanceNotifierEventReceiver(); + instanceNotifierEventReceiver = new InstanceNotifierEventReceiver(); instanceNotifierEventReceiver.addEventListener(new InstanceCleanupClusterEventListener() { @Override protected void onEvent(Event event) { @@ -134,7 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=fda1bf0fade708667188261eb30f33185e8fed79#l134> +137,7 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=1a7d93f8c3315435c8387bdf232808688e104a61;hb=b7840d8ee912a2c6bc7a084eeb1879a65625617a#l137> @@ public class MockInstance implements Runnable, Serializable { log.debug(String.format("Starting health statistics notifier: [member-id] %s", mockMemberContext.getMemberId())); } - healthStatNotifierExecutorService.scheduleAtFixedRate(new MockHealthStatisticsNotifier(mockMemberContext), + healthStatNotifierScheduledFuture = healthStatNotifier ExecutorService.scheduleAtFixedRate(new MockHealthStatisticsNotifier(mockMemberContext), 0, HEALTH_STAT_INTERVAL, TimeUnit.SECONDS); if (log.isDebugEnabled()) { @@ -143,11 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=fda1bf0fade708667188261eb30f33185e8fed79#l143> +146,11 <https://git-wip-us.apache.org/repos/asf?p=stratos.git;a=blob;f=components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java;h=1a7d93f8c3315435c8387bdf232808688e104a61;hb=b7840d8ee912a2c6bc7a084eeb1879a65625617a#l146> @@ public class MockInstance implements Runnable, Serializable { } private void stopHealthStatisticsPublisher() { - healthStatNotifierExecutorService.shutdownNow(); + healthStatNotifierScheduledFuture.cancel(true); } private void stopInstanceNotifierReceiver() { - eventListenerExecutorService.shutdownNow(); + instanceNotifierEventReceiver.terminate(); } On Sun, Mar 8, 2015 at 10:35 PM, Imesh Gunaratne <im...@apache.org> wrote: > A good finding Raj! I can see a slight issue with your fix. > > The executor service and the scheduled executor service in MockInstance > class are shared among all the mock instances. If we shutdown them in on > instance it will affect all other instances. > > > > On Sun, Mar 8, 2015 at 7:55 PM, Rajkumar Rajaratnam <rajkum...@wso2.com> > wrote: > >> Same applies to eventListenerExecutorService. >> >> Fixed both in 8def69fc17125fd6b854a6f114672b8f5f427929 >> >> Thanks. >> >> On Sun, Mar 8, 2015 at 7:53 PM, Rajkumar Rajaratnam <rajkum...@wso2.com> >> wrote: >> >>> Hi Devs, >>> >>> If you enable debug logs, you will experience $Subject. The reason is >>> that we don't shutdown the healthStatNotifierExecutorService when we >>> terminate the mock member. This should be the fix. >>> >>> >>> diff --git >>> a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java >>> b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/Mock >>> index ab3d319..43fcf7d 100644 >>> --- >>> a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java >>> +++ >>> b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java >>> @@ -75,6 +75,8 @@ public class MockInstance implements Runnable, >>> Serializable { >>> sleep(1000); >>> } >>> >>> + stopHealthStatisticsPublisher(); >>> + >>> if (log.isInfoEnabled()) { >>> log.info(String.format("Mock member terminated: >>> [member-id] %s", mockMemberContext.getMemberId())); >>> } >>> @@ -139,6 +141,10 @@ public class MockInstance implements Runnable, >>> Serializable { >>> } >>> } >>> >>> + private void stopHealthStatisticsPublisher() { >>> + healthStatNotifierExecutorService.shutdownNow(); >>> + } >>> >>> Thanks. >>> >>> -- >>> Rajkumar Rajaratnam >>> Committer & PMC Member, Apache Stratos >>> Software Engineer, WSO2 >>> >>> Mobile : +94777568639 >>> Blog : rajkumarr.com >>> >> >> >> >> -- >> Rajkumar Rajaratnam >> Committer & PMC Member, Apache Stratos >> Software Engineer, WSO2 >> >> Mobile : +94777568639 >> Blog : rajkumarr.com >> > > > > -- > Imesh Gunaratne > > Technical Lead, WSO2 > Committer & PMC Member, Apache Stratos > -- Imesh Gunaratne Technical Lead, WSO2 Committer & PMC Member, Apache Stratos