From 8668208f6a80f3a674dd589e752f269812f268c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramiz=20D=C3=BCndar?= Date: Tue, 19 Apr 2022 16:43:34 +0300 Subject: [PATCH 1/3] Refactor test --- .../DynamicConfigBouncingTest.java | 2 +- .../DynamicConfigPreJoinTest.java | 104 ++++++++++++++++++ .../DynamicConfigSlowPreJoinBouncingTest.java | 57 ---------- 3 files changed, 105 insertions(+), 58 deletions(-) create mode 100644 hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java delete mode 100644 hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java index 0388315eeea9..af27d7035590 100644 --- a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java +++ b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java @@ -84,7 +84,7 @@ public void doNotThrowExceptionWhenMemberIsGone() { assertEquals(createMapConfig(mapName), mapConfig); } - private static MapConfig createMapConfig(String mapName) { + static MapConfig createMapConfig(String mapName) { NearCacheConfig nearCacheConfig = new NearCacheConfig() .setCacheLocalEntries(true) .setInMemoryFormat(InMemoryFormat.NATIVE) diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java new file mode 100644 index 000000000000..1cf195dbdffe --- /dev/null +++ b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hazelcast.internal.dynamicconfig; + +import com.hazelcast.config.Config; +import com.hazelcast.config.ConfigAccessor; +import com.hazelcast.config.MapConfig; +import com.hazelcast.config.ServiceConfig; +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.internal.services.PreJoinAwareService; +import com.hazelcast.logging.ILogger; +import com.hazelcast.logging.Logger; +import com.hazelcast.spi.impl.operationservice.Operation; +import com.hazelcast.test.HazelcastSerialClassRunner; +import com.hazelcast.test.HazelcastTestSupport; +import com.hazelcast.test.TestHazelcastInstanceFactory; +import com.hazelcast.test.annotation.ParallelJVMTest; +import com.hazelcast.test.annotation.QuickTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import static com.hazelcast.internal.dynamicconfig.DynamicConfigBouncingTest.createMapConfig; +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(HazelcastSerialClassRunner.class) +@Category({QuickTest.class, ParallelJVMTest.class}) +public class DynamicConfigPreJoinTest extends HazelcastTestSupport { + + private static final CountDownLatch holdSlaveStart = new CountDownLatch(1); + private static final CountDownLatch canKillMaster = new CountDownLatch(1); + + private static final ILogger logger = Logger.getLogger(DynamicConfigPreJoinTest.class); + + @Test + public void testDynamicConfigIsAddedToTheNewMemberDuringPreJoin() throws InterruptedException, ExecutionException { + TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(); + + Config config = smallInstanceConfig(); + ServiceConfig serviceConfig = new ServiceConfig() + .setEnabled(true) + .setName(CountDownPreJoinAwareService.SERVICE_NAME) + .setImplementation(new CountDownPreJoinAwareService()); + ConfigAccessor.getServicesConfig(config).addServiceConfig(serviceConfig); + + HazelcastInstance master = factory.newHazelcastInstance(config); + MapConfig mapConfig = createMapConfig(randomMapName()); + master.getConfig().addMapConfig(mapConfig); + + Future spawn = spawn(() -> { + // factory.newHazelcastInstance(config) won't return before + // holdSlaveStart.countDown() + HazelcastInstance newSlave = factory.newHazelcastInstance(smallInstanceConfig()); + assertThat(newSlave.getConfig().getMapConfigs().values()).contains(mapConfig); + }); + + canKillMaster.await(); + master.getLifecycleService().terminate(); + + holdSlaveStart.countDown(); + spawn.get(); + } + + private static class CountDownPreJoinAwareService implements PreJoinAwareService { + static final String SERVICE_NAME = "count-down-pre-join-aware-service"; + + @Override + public Operation getPreJoinOperation() { + return new CountDownOperation(); + } + } + + private static class CountDownOperation extends Operation { + @Override + public void run() throws Exception { + canKillMaster.countDown(); + logger.info("Before await"); + // You should see [127.0.0.1]:5701 is SHUTDOWN log between before and + // after awaits. This is because we count down the canKillMaster latch + // here. + holdSlaveStart.await(); + logger.info("After await"); + throw new Exception("Expected Exception"); + } + } +} diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java deleted file mode 100644 index 26e818ef3359..000000000000 --- a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hazelcast.internal.dynamicconfig; - -import com.hazelcast.config.Config; -import com.hazelcast.config.ConfigAccessor; -import com.hazelcast.config.ServiceConfig; -import com.hazelcast.internal.services.PreJoinAwareService; -import com.hazelcast.spi.impl.operationservice.Operation; -import com.hazelcast.test.HazelcastParallelClassRunner; -import com.hazelcast.test.annotation.ParallelJVMTest; -import com.hazelcast.test.annotation.SlowTest; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - -@RunWith(HazelcastParallelClassRunner.class) -@Category({SlowTest.class, ParallelJVMTest.class}) -public class DynamicConfigSlowPreJoinBouncingTest extends DynamicConfigBouncingTest { - - public Config getConfig() { - DelaysPreparingPreJoinOpService service = new DelaysPreparingPreJoinOpService(); - Config config = new Config(); - ServiceConfig serviceConfig = new ServiceConfig().setEnabled(true) - .setName(DelaysPreparingPreJoinOpService.SERVICE_NAME) - .setImplementation(service); - ConfigAccessor.getServicesConfig(config).addServiceConfig(serviceConfig); - return config; - } - - private static class DelaysPreparingPreJoinOpService implements PreJoinAwareService { - - static final String SERVICE_NAME = "delaying-pre-join-op-prep-service"; - - DelaysPreparingPreJoinOpService() { - } - - @Override - public Operation getPreJoinOperation() { - sleepSeconds(1); - return null; - } - } -} From e43c7e9ef96ead1e9ac36b87717ccf3f9a11ba8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramiz=20D=C3=BCndar?= Date: Mon, 9 May 2022 15:44:36 +0300 Subject: [PATCH 2/3] Revert "Refactor test" This reverts commit 8668208f6a80f3a674dd589e752f269812f268c9. --- .../DynamicConfigBouncingTest.java | 2 +- .../DynamicConfigPreJoinTest.java | 104 ------------------ .../DynamicConfigSlowPreJoinBouncingTest.java | 57 ++++++++++ 3 files changed, 58 insertions(+), 105 deletions(-) delete mode 100644 hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java create mode 100644 hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java index af27d7035590..0388315eeea9 100644 --- a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java +++ b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigBouncingTest.java @@ -84,7 +84,7 @@ public void doNotThrowExceptionWhenMemberIsGone() { assertEquals(createMapConfig(mapName), mapConfig); } - static MapConfig createMapConfig(String mapName) { + private static MapConfig createMapConfig(String mapName) { NearCacheConfig nearCacheConfig = new NearCacheConfig() .setCacheLocalEntries(true) .setInMemoryFormat(InMemoryFormat.NATIVE) diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java deleted file mode 100644 index 1cf195dbdffe..000000000000 --- a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigPreJoinTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hazelcast.internal.dynamicconfig; - -import com.hazelcast.config.Config; -import com.hazelcast.config.ConfigAccessor; -import com.hazelcast.config.MapConfig; -import com.hazelcast.config.ServiceConfig; -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.internal.services.PreJoinAwareService; -import com.hazelcast.logging.ILogger; -import com.hazelcast.logging.Logger; -import com.hazelcast.spi.impl.operationservice.Operation; -import com.hazelcast.test.HazelcastSerialClassRunner; -import com.hazelcast.test.HazelcastTestSupport; -import com.hazelcast.test.TestHazelcastInstanceFactory; -import com.hazelcast.test.annotation.ParallelJVMTest; -import com.hazelcast.test.annotation.QuickTest; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import static com.hazelcast.internal.dynamicconfig.DynamicConfigBouncingTest.createMapConfig; -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(HazelcastSerialClassRunner.class) -@Category({QuickTest.class, ParallelJVMTest.class}) -public class DynamicConfigPreJoinTest extends HazelcastTestSupport { - - private static final CountDownLatch holdSlaveStart = new CountDownLatch(1); - private static final CountDownLatch canKillMaster = new CountDownLatch(1); - - private static final ILogger logger = Logger.getLogger(DynamicConfigPreJoinTest.class); - - @Test - public void testDynamicConfigIsAddedToTheNewMemberDuringPreJoin() throws InterruptedException, ExecutionException { - TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(); - - Config config = smallInstanceConfig(); - ServiceConfig serviceConfig = new ServiceConfig() - .setEnabled(true) - .setName(CountDownPreJoinAwareService.SERVICE_NAME) - .setImplementation(new CountDownPreJoinAwareService()); - ConfigAccessor.getServicesConfig(config).addServiceConfig(serviceConfig); - - HazelcastInstance master = factory.newHazelcastInstance(config); - MapConfig mapConfig = createMapConfig(randomMapName()); - master.getConfig().addMapConfig(mapConfig); - - Future spawn = spawn(() -> { - // factory.newHazelcastInstance(config) won't return before - // holdSlaveStart.countDown() - HazelcastInstance newSlave = factory.newHazelcastInstance(smallInstanceConfig()); - assertThat(newSlave.getConfig().getMapConfigs().values()).contains(mapConfig); - }); - - canKillMaster.await(); - master.getLifecycleService().terminate(); - - holdSlaveStart.countDown(); - spawn.get(); - } - - private static class CountDownPreJoinAwareService implements PreJoinAwareService { - static final String SERVICE_NAME = "count-down-pre-join-aware-service"; - - @Override - public Operation getPreJoinOperation() { - return new CountDownOperation(); - } - } - - private static class CountDownOperation extends Operation { - @Override - public void run() throws Exception { - canKillMaster.countDown(); - logger.info("Before await"); - // You should see [127.0.0.1]:5701 is SHUTDOWN log between before and - // after awaits. This is because we count down the canKillMaster latch - // here. - holdSlaveStart.await(); - logger.info("After await"); - throw new Exception("Expected Exception"); - } - } -} diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java new file mode 100644 index 000000000000..26e818ef3359 --- /dev/null +++ b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hazelcast.internal.dynamicconfig; + +import com.hazelcast.config.Config; +import com.hazelcast.config.ConfigAccessor; +import com.hazelcast.config.ServiceConfig; +import com.hazelcast.internal.services.PreJoinAwareService; +import com.hazelcast.spi.impl.operationservice.Operation; +import com.hazelcast.test.HazelcastParallelClassRunner; +import com.hazelcast.test.annotation.ParallelJVMTest; +import com.hazelcast.test.annotation.SlowTest; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@RunWith(HazelcastParallelClassRunner.class) +@Category({SlowTest.class, ParallelJVMTest.class}) +public class DynamicConfigSlowPreJoinBouncingTest extends DynamicConfigBouncingTest { + + public Config getConfig() { + DelaysPreparingPreJoinOpService service = new DelaysPreparingPreJoinOpService(); + Config config = new Config(); + ServiceConfig serviceConfig = new ServiceConfig().setEnabled(true) + .setName(DelaysPreparingPreJoinOpService.SERVICE_NAME) + .setImplementation(service); + ConfigAccessor.getServicesConfig(config).addServiceConfig(serviceConfig); + return config; + } + + private static class DelaysPreparingPreJoinOpService implements PreJoinAwareService { + + static final String SERVICE_NAME = "delaying-pre-join-op-prep-service"; + + DelaysPreparingPreJoinOpService() { + } + + @Override + public Operation getPreJoinOperation() { + sleepSeconds(1); + return null; + } + } +} From 56ea89eb14bebc9f549be2eadda041c4a3d5e783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramiz=20D=C3=BCndar?= Date: Mon, 9 May 2022 15:45:18 +0300 Subject: [PATCH 3/3] Delete DynamicConfigSlowPreJoinBouncingTest --- .../DynamicConfigSlowPreJoinBouncingTest.java | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java diff --git a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java b/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java deleted file mode 100644 index 26e818ef3359..000000000000 --- a/hazelcast/src/test/java/com/hazelcast/internal/dynamicconfig/DynamicConfigSlowPreJoinBouncingTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hazelcast.internal.dynamicconfig; - -import com.hazelcast.config.Config; -import com.hazelcast.config.ConfigAccessor; -import com.hazelcast.config.ServiceConfig; -import com.hazelcast.internal.services.PreJoinAwareService; -import com.hazelcast.spi.impl.operationservice.Operation; -import com.hazelcast.test.HazelcastParallelClassRunner; -import com.hazelcast.test.annotation.ParallelJVMTest; -import com.hazelcast.test.annotation.SlowTest; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - -@RunWith(HazelcastParallelClassRunner.class) -@Category({SlowTest.class, ParallelJVMTest.class}) -public class DynamicConfigSlowPreJoinBouncingTest extends DynamicConfigBouncingTest { - - public Config getConfig() { - DelaysPreparingPreJoinOpService service = new DelaysPreparingPreJoinOpService(); - Config config = new Config(); - ServiceConfig serviceConfig = new ServiceConfig().setEnabled(true) - .setName(DelaysPreparingPreJoinOpService.SERVICE_NAME) - .setImplementation(service); - ConfigAccessor.getServicesConfig(config).addServiceConfig(serviceConfig); - return config; - } - - private static class DelaysPreparingPreJoinOpService implements PreJoinAwareService { - - static final String SERVICE_NAME = "delaying-pre-join-op-prep-service"; - - DelaysPreparingPreJoinOpService() { - } - - @Override - public Operation getPreJoinOperation() { - sleepSeconds(1); - return null; - } - } -}