Fix bug with DistributedSystem Properties handling in mock object configuration.

This commit is contained in:
John Blum
2021-09-13 14:34:18 -07:00
parent a6fa87638e
commit 87a7bc8e49
3 changed files with 114 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ import org.springframework.lang.Nullable;
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.client.ClientCacheFactory
* @see org.apache.geode.cache.client.PoolFactory
* @see org.apache.geode.distributed.DistributedSystem
* @see org.springframework.beans.factory.config.BeanPostProcessor
* @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
@@ -116,7 +117,14 @@ public class GemFireMockObjectsBeanPostProcessor implements BeanPostProcessor {
DistributedSystem distributedSystem = gemfireCache.getDistributedSystem();
doReturn(getGemFireProperties()).when(distributedSystem).getProperties();
Properties distributedSystemProperties = distributedSystem.getProperties();
if (distributedSystemProperties != null) {
distributedSystemProperties.putAll(getGemFireProperties());
}
else {
doReturn(getGemFireProperties()).when(distributedSystem).getProperties();
}
}
return bean;

View File

@@ -0,0 +1,84 @@
/*
* Copyright 2019 the original author or authors.
*
* 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
*
* https://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.springframework.data.gemfire.tests;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.distributed.DistributedSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for an Apache Geode mock peer {@link Cache} application.
*
* @author John Blum
* @see java.util.Properties
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.distributed.DistributedSystem
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer
* @since 0.0.26
*/
@RunWith(SpringRunner.class)
@GemFireUnitTest
@SuppressWarnings("unused")
public class MockPeerCacheApplicationXmlConfigurationIntegrationTests extends IntegrationTestsSupport {
@Autowired
private GemFireCache cache;
@Resource(name = "Example")
private Region<Object, Object> example;
@Test
public void gemfireCacheConfigurationIsCorrect() {
assertThat(this.cache).isNotNull();
assertThat(this.cache.getName())
.isEqualTo(MockPeerCacheApplicationXmlConfigurationIntegrationTests.class.getSimpleName());
assertThat(this.example).isNotNull();
assertThat(this.example.getName()).isEqualTo("Example");
assertThat(this.cache.getRegion(this.example.getFullPath())).isEqualTo(this.example);
DistributedSystem distributedSystem = this.cache.getDistributedSystem();
assertThat(distributedSystem).isNotNull();
assertThat(distributedSystem.getName()).isEqualTo(this.cache.getName());
Properties distributedSystemProperties = distributedSystem.getProperties();
assertThat(distributedSystemProperties).isNotNull();
assertThat(distributedSystemProperties.containsKey("disable-auto-reconnect")).isTrue();
assertThat(Boolean.parseBoolean(distributedSystemProperties.getProperty("disable-auto-reconnect"))).isTrue();
assertThat(distributedSystemProperties.containsKey("use-cluster-configuration")).isTrue();
assertThat(Boolean.parseBoolean(distributedSystemProperties.getProperty("use-cluster-configuration"))).isFalse();
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/geode"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/geode https://www.springframework.org/schema/geode/spring-geode.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"
default-lazy-init="true">
<util:properties id="gemfireProperties">
<prop key="name">MockPeerCacheApplicationXmlConfigurationIntegrationTests</prop>
<prop key="log-level">error</prop>
</util:properties>
<gfe:cache properties-ref="gemfireProperties"/>
<gfe:local-region id="Example" persistent="false"/>
</beans>