From 362eafde2fece67b445b6cca5a512d0d59bfc959 Mon Sep 17 00:00:00 2001 From: Jaromir Hamala Date: Thu, 18 Aug 2016 23:26:38 +0300 Subject: [PATCH] Fix wrong client defaults when configured via Spring Fix #8746 It would be great to just use equals() on the config objects, however a lot of our *Config(s) do not override equals()/hashcode() and moreover the config objects are mutated in some cases - e.g. https://github.com/hazelcast/hazelcast/blob/eef987b9920f3f7b4c506e433b0d067cab9ba93c/hazelcast-client/src/main/java/com/hazelcast/client/config/ClientNetworkConfig.java#L207-L207 --- .../main/resources/hazelcast-spring-3.8.xsd | 4 +- .../TestClientConfigAndSpringDefaults.java | 64 +++++++++++++++++++ .../spring/client-defaults-context.xml | 31 +++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 hazelcast-spring/src/test/java/com/hazelcast/spring/TestClientConfigAndSpringDefaults.java create mode 100644 hazelcast-spring/src/test/resources/com/hazelcast/spring/client-defaults-context.xml diff --git a/hazelcast-spring/src/main/resources/hazelcast-spring-3.8.xsd b/hazelcast-spring/src/main/resources/hazelcast-spring-3.8.xsd index 1c5b1cd2fb974..ce0deb1871987 100644 --- a/hazelcast-spring/src/main/resources/hazelcast-spring-3.8.xsd +++ b/hazelcast-spring/src/main/resources/hazelcast-spring-3.8.xsd @@ -2119,9 +2119,9 @@ - + - + diff --git a/hazelcast-spring/src/test/java/com/hazelcast/spring/TestClientConfigAndSpringDefaults.java b/hazelcast-spring/src/test/java/com/hazelcast/spring/TestClientConfigAndSpringDefaults.java new file mode 100644 index 0000000000000..5105306ff3ebb --- /dev/null +++ b/hazelcast-spring/src/test/java/com/hazelcast/spring/TestClientConfigAndSpringDefaults.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2008-2016, 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.spring; + +import com.hazelcast.client.config.ClientConfig; +import com.hazelcast.client.impl.HazelcastClientProxy; +import com.hazelcast.core.Hazelcast; +import com.hazelcast.test.annotation.QuickTest; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; + +import javax.annotation.Resource; + +import static org.junit.Assert.assertEquals; + +@RunWith(CustomSpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"client-defaults-context.xml"}) +@Category(QuickTest.class) +public class TestClientConfigAndSpringDefaults { + + private ClientConfig clientConfig; + + @Resource(name = "client") + private HazelcastClientProxy client; + + @BeforeClass + @AfterClass + public static void start() { + Hazelcast.shutdownAll(); + } + + @Before + public void before() throws IllegalAccessException { + clientConfig = client.getClientConfig(); + } + + @Test + public void testDefaults() { + ClientConfig defaults = new ClientConfig(); + + assertEquals(defaults.isSmartRouting(), clientConfig.isSmartRouting()); + assertEquals(defaults.getNetworkConfig().isSmartRouting(), clientConfig.getNetworkConfig().isSmartRouting()); + assertEquals(defaults.getNetworkConfig().getConnectionTimeout(), clientConfig.getNetworkConfig().getConnectionTimeout()); + } +} diff --git a/hazelcast-spring/src/test/resources/com/hazelcast/spring/client-defaults-context.xml b/hazelcast-spring/src/test/resources/com/hazelcast/spring/client-defaults-context.xml new file mode 100644 index 0000000000000..2368324afa5a8 --- /dev/null +++ b/hazelcast-spring/src/test/resources/com/hazelcast/spring/client-defaults-context.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file