DATAGEODE-180 - Fix test failures.

This commit is contained in:
John Blum
2019-04-10 18:27:44 -07:00
parent ad8195a1a2
commit fcafb4d540
4 changed files with 45 additions and 23 deletions

View File

@@ -796,7 +796,9 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
@Override
@SuppressWarnings("all")
public GemFireCache getObject() throws Exception {
return Optional.<GemFireCache>ofNullable(getCache()).orElseGet(this::init);
return Optional.<GemFireCache>ofNullable(getCache())
.orElseGet(this::init);
}
/**

View File

@@ -63,8 +63,7 @@ public class DefinedIndexesApplicationListener implements ApplicationListener<Co
queryService.createDefinedIndexes();
}
catch (MultiIndexCreationException cause) {
logger.warn("Failed to create pre-defined Indexes: {}", cause.getMessage(), cause);
logger.warn(String.format("Failed to create pre-defined Indexes: %s", cause.getMessage()), cause);
}
});
}

View File

@@ -29,10 +29,10 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import java.io.InputStream;
import java.util.Collections;
@@ -74,7 +75,8 @@ import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
* Unit tests for {@link CacheFactoryBean}.
*
* @author John Blum
* @see org.junit.Rule
* @see java.io.InputStream
* @see java.util.Properties
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.mockito.Mock
@@ -84,10 +86,13 @@ import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
* @see org.apache.geode.cache.CacheFactory
* @see org.apache.geode.cache.CacheTransactionManager
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.control.ResourceManager
* @see org.apache.geode.cache.util.GatewayConflictResolver
* @see org.apache.geode.distributed.DistributedMember
* @see org.apache.geode.distributed.DistributedSystem
* @see org.apache.geode.pdx.PdxSerializer
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.core.io.Resource
* @see org.springframework.data.gemfire.CacheFactoryBean
* @since 1.7.0
*/
@@ -236,15 +241,25 @@ public class CacheFactoryBeanTest {
public void init() throws Exception {
BeanFactory mockBeanFactory = mock(BeanFactory.class);
Cache mockCache = mock(Cache.class);
CacheTransactionManager mockCacheTransactionManager = mock(CacheTransactionManager.class);
DistributedMember mockDistributedMember = mock(DistributedMember.class);
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
DistributedMember mockDistributedMember = mock(DistributedMember.class, withSettings().lenient());
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, withSettings().lenient());
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class);
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class);
Resource mockCacheXml = mock(Resource.class);
ResourceManager mockResourceManager = mock(ResourceManager.class);
TransactionListener mockTransactionLister = mock(TransactionListener.class);
TransactionWriter mockTransactionWriter = mock(TransactionWriter.class);
CacheFactory mockCacheFactory = mock(CacheFactory.class);
@@ -263,14 +278,14 @@ public class CacheFactoryBeanTest {
when(mockDistributedMember.getHost()).thenReturn("skullbox");
when(mockDistributedMember.getProcessId()).thenReturn(12345);
final ClassLoader expectedThreadContextClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader expectedThreadContextClassLoader = Thread.currentThread().getContextClassLoader();
final Properties gemfireProperties = new Properties();
Properties gemfireProperties = new Properties();
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
@Override
protected Object createFactory(final Properties actualGemfireProperties) {
protected Object createFactory(Properties actualGemfireProperties) {
assertThat(actualGemfireProperties, is(equalTo(gemfireProperties)));
assertThat(getBeanClassLoader(), is(equalTo(ClassLoader.getSystemClassLoader())));
@@ -335,12 +350,12 @@ public class CacheFactoryBeanTest {
verify(mockCache, times(1)).setMessageSyncInterval(eq(20000));
verify(mockCache, times(4)).getResourceManager();
verify(mockCache, times(1)).setSearchTimeout(eq(45000));
verify(mockCacheTransactionManager, times(1)).addListener(same(mockTransactionLister));
verify(mockCacheTransactionManager, times(1)).setWriter(same(mockTransactionWriter));
verify(mockResourceManager, times(1)).setCriticalHeapPercentage(eq(0.90f));
verify(mockResourceManager, times(1)).setCriticalOffHeapPercentage(eq(0.95f));
verify(mockResourceManager, times(1)).setEvictionHeapPercentage(eq(0.75f));
verify(mockResourceManager, times(1)).setEvictionOffHeapPercentage(eq(0.90f));
verify(mockCacheTransactionManager, times(1)).addListener(same(mockTransactionLister));
verify(mockCacheTransactionManager, times(1)).setWriter(same(mockTransactionWriter));
}
@Test
@@ -388,7 +403,7 @@ public class CacheFactoryBeanTest {
}
@Test
public void fetchExistingCache() throws Exception {
public void fetchExistingCache() {
Cache mockCache = mock(Cache.class);
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
@@ -572,7 +587,7 @@ public class CacheFactoryBeanTest {
}
@Test(expected = IllegalArgumentException.class)
public void postProcessCacheWithInvalidCriticalHeapPercentage() throws Exception {
public void postProcessCacheWithInvalidCriticalHeapPercentage() {
try {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
@@ -592,7 +607,7 @@ public class CacheFactoryBeanTest {
}
@Test(expected = IllegalArgumentException.class)
public void postProcessCacheWithInvalidCriticalOffHeapPercentage() throws Exception {
public void postProcessCacheWithInvalidCriticalOffHeapPercentage() {
try {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
@@ -612,7 +627,7 @@ public class CacheFactoryBeanTest {
}
@Test(expected = IllegalArgumentException.class)
public void postProcessCacheWithInvalidEvictionHeapPercentage() throws Exception {
public void postProcessCacheWithInvalidEvictionHeapPercentage() {
try {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
@@ -632,7 +647,7 @@ public class CacheFactoryBeanTest {
}
@Test(expected = IllegalArgumentException.class)
public void postProcessCacheWithInvalidEvictionOffHeapPercentage() throws Exception {
public void postProcessCacheWithInvalidEvictionOffHeapPercentage() {
try {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
@@ -747,13 +762,19 @@ public class CacheFactoryBeanTest {
}
@Test
@SuppressWarnings("all")
public void setAndGetCacheFactoryBeanProperties() throws Exception {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "SpringBeanFactory");
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class, "GemFireGatewayConflictResolver");
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class, "GemFirePdxSerializer");
Resource mockCacheXml = mock(Resource.class, "GemFireCacheXml");
TransactionListener mockTransactionListener = mock(TransactionListener.class, "GemFireTransactionListener");
TransactionWriter mockTransactionWriter = mock(TransactionWriter.class, "GemFireTransactionWriter");
Properties gemfireProperties = new Properties();

View File

@@ -119,11 +119,11 @@ public class DefinedIndexesApplicationListenerUnitTests {
when(mockQueryService.createDefinedIndexes())
.thenThrow(newMultiIndexCreationException("TestKey", new RuntimeException("TEST")));
Logger mockLog = mock(Logger.class);
Logger mockLogger = mock(Logger.class);
DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener() {
@Override Logger initLogger() {
return mockLog;
return mockLogger;
}
};
@@ -133,7 +133,7 @@ public class DefinedIndexesApplicationListenerUnitTests {
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class));
verify(mockQueryService, times(1)).createDefinedIndexes();
verify(mockLog, times(1)).warn(startsWith("Failed to create pre-defined Indexes:"),
verify(mockLogger, times(1)).warn(startsWith("Failed to create pre-defined Indexes:"),
isA(MultiIndexCreationException.class));
}
}