You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/10/05 17:46:34 UTC
[GitHub] [geode] mhansonp opened a new pull request #6935: Geode 9645 unit test
mhansonp opened a new pull request #6935:
URL: https://github.com/apache/geode/pull/6935
Draft PR to work on unit tests specifically which seem to only crash in the PR pipeline.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #6935:
URL: https://github.com/apache/geode/pull/6935#discussion_r726337634
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
Review comment:
I will do that. I am actually not a fan of that style, but I think that is the style guide and I am usually better about making sure they are ordered that way. Sorry.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #6935:
URL: https://github.com/apache/geode/pull/6935#discussion_r726338881
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(true);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(0))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(false);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(1))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ public static class TestSocketFactory implements SocketFactory, Declarable2 {
+ @Override
+ public Socket createSocket() throws IOException {
+ return new Socket();
+ }
+
+ @Override
+ public Properties getConfig() {
+ return new Properties();
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+
+ }
+ }
+
+ private PoolImpl setupPool(boolean multiUserAuthEnabled) throws UnknownHostException {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ Properties properties = new Properties();
+ properties.setProperty(DURABLE_CLIENT_ID, "1");
+ DistributionConfig distributionConfig = new DistributionConfigImpl(properties);
+ InternalDistributedSystem.BuilderForTesting builderForTesting =
+ new InternalDistributedSystem.BuilderForTesting(properties);
+
+ InternalDistributedSystem mockSystem = spy(builderForTesting.build());
+ doReturn(distributionConfig).when(mockSystem).getConfig();
+ InternalDistributedMember mockMember =
+ new InternalDistributedMember(InetAddress.getByName("localhost"), 50505, false,
+ false);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ PoolFactory poolFactory = poolManagerImpl.createFactory();
+ poolFactory.setMultiuserAuthentication(multiUserAuthEnabled);
+ SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+ poolFactory.setSocketFactory(new TestSocketFactory());
+ poolFactory.addLocator("localhost", clusterStartupRule.getMember(0).getPort());
+ return (PoolImpl) poolFactory.create("test_pool");
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskNotStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(true);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isFalse();
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskIsStarted()
Review comment:
Thanks for catching that!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #6935:
URL: https://github.com/apache/geode/pull/6935#discussion_r726333353
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
Review comment:
Actually it no longer throws, I decided to start a real locator and that fixed it if I remember correctly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] DonalEvans commented on a change in pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
DonalEvans commented on a change in pull request #6935:
URL: https://github.com/apache/geode/pull/6935#discussion_r725168900
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(true);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(0))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(false);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(1))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ public static class TestSocketFactory implements SocketFactory, Declarable2 {
+ @Override
+ public Socket createSocket() throws IOException {
+ return new Socket();
+ }
+
+ @Override
+ public Properties getConfig() {
+ return new Properties();
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+
+ }
+ }
+
+ private PoolImpl setupPool(boolean multiUserAuthEnabled) throws UnknownHostException {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ Properties properties = new Properties();
+ properties.setProperty(DURABLE_CLIENT_ID, "1");
+ DistributionConfig distributionConfig = new DistributionConfigImpl(properties);
+ InternalDistributedSystem.BuilderForTesting builderForTesting =
+ new InternalDistributedSystem.BuilderForTesting(properties);
+
+ InternalDistributedSystem mockSystem = spy(builderForTesting.build());
+ doReturn(distributionConfig).when(mockSystem).getConfig();
+ InternalDistributedMember mockMember =
+ new InternalDistributedMember(InetAddress.getByName("localhost"), 50505, false,
+ false);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ PoolFactory poolFactory = poolManagerImpl.createFactory();
+ poolFactory.setMultiuserAuthentication(multiUserAuthEnabled);
+ SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+ poolFactory.setSocketFactory(new TestSocketFactory());
+ poolFactory.addLocator("localhost", clusterStartupRule.getMember(0).getPort());
+ return (PoolImpl) poolFactory.create("test_pool");
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskNotStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(true);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isFalse();
Review comment:
This can be simplified to:
```
assertThat(listeners).allSatisfy(listener -> assertThat(listener).isNotInstanceOf(DataSerializerRecoveryListener.class));
```
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
Review comment:
Just personal preference, but could the methods in this class be reordered so that the tests are all at the top and the helper methods are at the bottom, as it makes it easier to keep track of what all the tests are.
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(true);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(0))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(false);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(1))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ public static class TestSocketFactory implements SocketFactory, Declarable2 {
+ @Override
+ public Socket createSocket() throws IOException {
+ return new Socket();
+ }
+
+ @Override
+ public Properties getConfig() {
+ return new Properties();
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+
+ }
+ }
+
+ private PoolImpl setupPool(boolean multiUserAuthEnabled) throws UnknownHostException {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ Properties properties = new Properties();
+ properties.setProperty(DURABLE_CLIENT_ID, "1");
+ DistributionConfig distributionConfig = new DistributionConfigImpl(properties);
+ InternalDistributedSystem.BuilderForTesting builderForTesting =
+ new InternalDistributedSystem.BuilderForTesting(properties);
+
+ InternalDistributedSystem mockSystem = spy(builderForTesting.build());
+ doReturn(distributionConfig).when(mockSystem).getConfig();
+ InternalDistributedMember mockMember =
+ new InternalDistributedMember(InetAddress.getByName("localhost"), 50505, false,
+ false);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ PoolFactory poolFactory = poolManagerImpl.createFactory();
+ poolFactory.setMultiuserAuthentication(multiUserAuthEnabled);
+ SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+ poolFactory.setSocketFactory(new TestSocketFactory());
+ poolFactory.addLocator("localhost", clusterStartupRule.getMember(0).getPort());
+ return (PoolImpl) poolFactory.create("test_pool");
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskNotStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(true);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isFalse();
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskIsStarted()
Review comment:
This test name is incorrect, I think. It should be "when not using multi user auth mode"
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
Review comment:
This method can be removed.
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
Review comment:
Rather than just having a comment here which could be easily missed, wouldn't it be better to explicitly add an expected exception, or to assert that the exception is thrown at the point it's expected to be seen?
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
Review comment:
These test names could be a little more descriptive by including the conditions being tested as well as the expected behaviour. The "test_That" part is also redundant, since we expect that all tests are testing that (something). So in this case, `dataSerializerSynchronizationMessagesAreNotSentWhenMulitUserAuthenticationIsEnabled`
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(true);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(0))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(false);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(1))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ public static class TestSocketFactory implements SocketFactory, Declarable2 {
+ @Override
+ public Socket createSocket() throws IOException {
+ return new Socket();
+ }
+
+ @Override
+ public Properties getConfig() {
+ return new Properties();
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+
+ }
+ }
+
+ private PoolImpl setupPool(boolean multiUserAuthEnabled) throws UnknownHostException {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ Properties properties = new Properties();
+ properties.setProperty(DURABLE_CLIENT_ID, "1");
+ DistributionConfig distributionConfig = new DistributionConfigImpl(properties);
+ InternalDistributedSystem.BuilderForTesting builderForTesting =
+ new InternalDistributedSystem.BuilderForTesting(properties);
+
+ InternalDistributedSystem mockSystem = spy(builderForTesting.build());
+ doReturn(distributionConfig).when(mockSystem).getConfig();
+ InternalDistributedMember mockMember =
+ new InternalDistributedMember(InetAddress.getByName("localhost"), 50505, false,
+ false);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ PoolFactory poolFactory = poolManagerImpl.createFactory();
+ poolFactory.setMultiuserAuthentication(multiUserAuthEnabled);
+ SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+ poolFactory.setSocketFactory(new TestSocketFactory());
+ poolFactory.addLocator("localhost", clusterStartupRule.getMember(0).getPort());
+ return (PoolImpl) poolFactory.create("test_pool");
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskNotStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(true);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isFalse();
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskIsStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(false);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isTrue();
Review comment:
This can be simplified to:
```
assertThat(listeners).anySatisfy(listener -> assertThat(listener).isInstanceOf(DataSerializerRecoveryListener.class));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #6935:
URL: https://github.com/apache/geode/pull/6935#discussion_r726333686
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
Review comment:
Yup.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp merged pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp merged pull request #6935:
URL: https://github.com/apache/geode/pull/6935
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp commented on pull request #6935:
URL: https://github.com/apache/geode/pull/6935#issuecomment-938242497
This time we moved the tests to be integration tests and things are happier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #6935:
URL: https://github.com/apache/geode/pull/6935#discussion_r726544814
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(true);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(0))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(false);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(1))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ public static class TestSocketFactory implements SocketFactory, Declarable2 {
+ @Override
+ public Socket createSocket() throws IOException {
+ return new Socket();
+ }
+
+ @Override
+ public Properties getConfig() {
+ return new Properties();
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+
+ }
+ }
+
+ private PoolImpl setupPool(boolean multiUserAuthEnabled) throws UnknownHostException {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ Properties properties = new Properties();
+ properties.setProperty(DURABLE_CLIENT_ID, "1");
+ DistributionConfig distributionConfig = new DistributionConfigImpl(properties);
+ InternalDistributedSystem.BuilderForTesting builderForTesting =
+ new InternalDistributedSystem.BuilderForTesting(properties);
+
+ InternalDistributedSystem mockSystem = spy(builderForTesting.build());
+ doReturn(distributionConfig).when(mockSystem).getConfig();
+ InternalDistributedMember mockMember =
+ new InternalDistributedMember(InetAddress.getByName("localhost"), 50505, false,
+ false);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ PoolFactory poolFactory = poolManagerImpl.createFactory();
+ poolFactory.setMultiuserAuthentication(multiUserAuthEnabled);
+ SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+ poolFactory.setSocketFactory(new TestSocketFactory());
+ poolFactory.addLocator("localhost", clusterStartupRule.getMember(0).getPort());
+ return (PoolImpl) poolFactory.create("test_pool");
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskNotStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(true);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isFalse();
Review comment:
Yup. Nice simplification!
##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PoolManagerIntegrationTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.SocketFactory;
+import org.apache.geode.cache.client.internal.DataSerializerRecoveryListener;
+import org.apache.geode.cache.client.internal.EndpointManager;
+import org.apache.geode.cache.client.internal.EndpointManagerImpl;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.RegisterDataSerializersOp;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.xmlcache.Declarable2;
+import org.apache.geode.internal.net.SocketCreatorFactory;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+
+
+/*
+ * A java.net.ConnectException is expected to be thrown by these tests. It is not a problem.
+ */
+public class PoolManagerIntegrationTest {
+
+ private PoolImpl pool;
+ private PoolManagerImpl poolManager;
+
+ @ClassRule
+ public static ClusterStartupRule clusterStartupRule = new ClusterStartupRule();;
+
+ @BeforeClass
+ public static void classSetup() {
+ clusterStartupRule.startLocatorVM(0, 10334);
+ }
+
+ @Before
+ public void setUp() {
+
+ pool = mock(PoolImpl.class);
+ poolManager = spy(new PoolManagerImpl(true));
+
+ assertThat(poolManager.getMap()).isEmpty();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ private InternalDistributedSystem setupFakeSystem(boolean mulitUserAuthentication) {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ InternalDistributedMember mockMember = mock(InternalDistributedMember.class);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ PoolFactory poolFactory = mock(PoolFactory.class);
+ when(poolManagerImpl.createFactory()).thenReturn(poolFactory);
+ when(poolFactory.create(any())).thenReturn(pool);
+
+ assertThat(poolManagerImpl.createFactory().create("test")).isEqualTo(pool);
+ doReturn(mulitUserAuthentication).when(pool).getMultiuserAuthentication();
+ doReturn(null).when(pool).execute(any());
+ PoolManagerImpl.setImpl(poolManagerImpl);
+ Map<String, Pool> map = new HashMap<>();
+ map.put("test_pool", pool);
+ when(poolManagerImpl.getMap()).thenReturn(map);
+ return mockSystem;
+ }
+
+ private DataSerializer setupFakeEventAndDataSerializer(InternalDistributedSystem mockSystem) {
+ DataSerializer dataSerializer = mock(DataSerializer.class);
+ EventID eventID = new EventID(mockSystem);
+ doReturn(eventID).when(dataSerializer).getEventId();
+ return dataSerializer;
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreNotSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(true);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(0))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ @Test
+ public void test_ThatDataSerializerSynchronizationMessagesAreSent() {
+ InternalDistributedSystem mockSystem = setupFakeSystem(false);
+ DataSerializer dataSerializer = setupFakeEventAndDataSerializer(mockSystem);
+ PoolManagerImpl.allPoolsRegisterDataSerializers(dataSerializer);
+ verify(pool, times(1))
+ .execute(any(RegisterDataSerializersOp.RegisterDataSerializersOpImpl.class));
+ }
+
+ public static class TestSocketFactory implements SocketFactory, Declarable2 {
+ @Override
+ public Socket createSocket() throws IOException {
+ return new Socket();
+ }
+
+ @Override
+ public Properties getConfig() {
+ return new Properties();
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+
+ }
+ }
+
+ private PoolImpl setupPool(boolean multiUserAuthEnabled) throws UnknownHostException {
+ PoolManagerImpl poolManagerImpl = poolManager;
+ Properties properties = new Properties();
+ properties.setProperty(DURABLE_CLIENT_ID, "1");
+ DistributionConfig distributionConfig = new DistributionConfigImpl(properties);
+ InternalDistributedSystem.BuilderForTesting builderForTesting =
+ new InternalDistributedSystem.BuilderForTesting(properties);
+
+ InternalDistributedSystem mockSystem = spy(builderForTesting.build());
+ doReturn(distributionConfig).when(mockSystem).getConfig();
+ InternalDistributedMember mockMember =
+ new InternalDistributedMember(InetAddress.getByName("localhost"), 50505, false,
+ false);
+ doReturn(mockMember).when(mockSystem).getDistributedMember();
+
+ InternalDistributedSystem.addTestSystem(mockSystem);
+ PoolFactory poolFactory = poolManagerImpl.createFactory();
+ poolFactory.setMultiuserAuthentication(multiUserAuthEnabled);
+ SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+ poolFactory.setSocketFactory(new TestSocketFactory());
+ poolFactory.addLocator("localhost", clusterStartupRule.getMember(0).getPort());
+ return (PoolImpl) poolFactory.create("test_pool");
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskNotStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(true);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isFalse();
+ }
+
+
+ @Test
+ public void test_ThatWhenUsingMultiUserAuthModeDataSerializerRecoveryTaskIsStarted()
+ throws UnknownHostException {
+
+ PoolImpl poolImpl = setupPool(false);
+ EndpointManagerImpl endpointManager = (EndpointManagerImpl) poolImpl.getEndpointManager();
+ Set<EndpointManager.EndpointListener> listeners = endpointManager.getListeners();
+ boolean foundDataStoreRecoveryListener = false;
+ for (EndpointManager.EndpointListener endpointListener : listeners) {
+ if (endpointListener instanceof DataSerializerRecoveryListener) {
+ foundDataStoreRecoveryListener = true;
+ break;
+ }
+ }
+ assertThat(foundDataStoreRecoveryListener).isTrue();
Review comment:
Yup. Nice simplification!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp merged pull request #6935: Geode 9645 unit test
Posted by GitBox <gi...@apache.org>.
mhansonp merged pull request #6935:
URL: https://github.com/apache/geode/pull/6935
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org