Refactored and cleaned up deprecated and unchecked/unsafe Java and GemFire API usage.

This commit is contained in:
John Blum
2014-04-16 13:22:59 -07:00
parent 4ae0be7860
commit 7c354f59d6
25 changed files with 130 additions and 151 deletions

View File

@@ -79,6 +79,7 @@ public class CacheServerIntegrationTest {
}
@Test
@SuppressWarnings("deprecation")
public void testCacheServerRunningWithSubscription() {
assertNotNull(cacheServer);
assertTrue(cacheServer.isRunning());

View File

@@ -17,14 +17,13 @@
package org.springframework.data.gemfire;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import com.gemstone.gemfire.cache.util.ObjectSizerImpl;
/**
* @author Costin Leau
*/
public class SimpleObjectSizer implements ObjectSizer {
private static final ObjectSizer sizer = new ObjectSizerImpl();
private static final ObjectSizer sizer = ObjectSizer.DEFAULT;
@Override
public int sizeof(Object o) {

View File

@@ -55,6 +55,7 @@ public class CacheServerNamespaceTest {
private ApplicationContext context;
@Test
@SuppressWarnings("deprecation")
public void testBasicCacheServer() throws Exception {
CacheServer cacheServer = context.getBean("advanced-config", CacheServer.class);

View File

@@ -114,8 +114,8 @@ public class ClientRegionNamespaceTest {
assertEquals(5, attrs.getEvictionAttributes().getMaximum());
}
@SuppressWarnings("rawtypes")
@Test
@SuppressWarnings({ "deprecation", "rawtypes" })
public void testPersistent() throws Exception {
assertTrue(context.containsBean("persistent"));
Region region = context.getBean("persistent", Region.class);

View File

@@ -29,16 +29,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.IndexType;
/**
*
* @author Costin Leau
* @author David Turanski
*/
@ContextConfiguration(locations="index-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="index-ns.xml",
initializers=GemfireTestApplicationContextInitializer.class)
@SuppressWarnings("deprecation")
public class IndexNamespaceTest {
private final String name = "test-index";
@@ -49,6 +47,7 @@ public class IndexNamespaceTest {
@Before
public void setUp() throws Exception {
Cache cache = (Cache) context.getBean("gemfireCache");
if (cache.getRegion(name) == null) {
cache.createRegionFactory().create("test-index");
}
@@ -62,7 +61,7 @@ public class IndexNamespaceTest {
assertEquals("status", idx.getIndexedExpression());
assertEquals("simple", idx.getName());
assertEquals(name, idx.getRegion().getName());
assertEquals(IndexType.FUNCTIONAL, idx.getType());
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, idx.getType());
}
@Test
@@ -73,6 +72,7 @@ public class IndexNamespaceTest {
assertEquals("tsi.name", idx.getIndexedExpression());
assertEquals("complex-index", idx.getName());
assertEquals(name, idx.getRegion().getName());
assertEquals(IndexType.HASH, idx.getType());
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, idx.getType());
}
}

View File

@@ -58,8 +58,8 @@ public class LocalRegionNamespaceTest {
assertTrue(context.containsBean("simple"));
}
@SuppressWarnings("rawtypes")
@Test
@SuppressWarnings({ "deprecation", "rawtypes" })
public void testPublishingLocal() throws Exception {
assertTrue(context.containsBean("pub"));
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
@@ -117,4 +117,4 @@ public class LocalRegionNamespaceTest {
RegionAttributes attrs = region.getAttributes();
assertTrue(attrs.getDataPolicy().withPersistence());
}
}
}

View File

@@ -69,7 +69,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
return (array == null || array.length == 0);
}
protected static boolean isBeanType(final BeanDefinition beanDefinition, final Class beanType) {
protected static boolean isBeanType(final BeanDefinition beanDefinition, final Class<?> beanType) {
return (beanDefinition instanceof AbstractBeanDefinition
&& ((AbstractBeanDefinition) beanDefinition).hasBeanClass()
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass()));

View File

@@ -56,13 +56,13 @@ public class ReplicatedRegionNamespaceTest {
public void testBasicReplica() throws Exception {
assertTrue(context.containsBean("simple"));
RegionFactoryBean fb = context.getBean("&simple", RegionFactoryBean.class);
assertEquals(false ,(Boolean)TestUtils.readField("close", fb));
assertEquals(false, TestUtils.readField("close", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
assertFalse(attrs.getConcurrencyChecksEnabled());
}
@SuppressWarnings("rawtypes")
@Test
@SuppressWarnings({ "deprecation", "rawtypes" })
public void testPublishingReplica() throws Exception {
assertTrue(context.containsBean("pub"));
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
@@ -122,4 +122,4 @@ public class ReplicatedRegionNamespaceTest {
assertEquals(existing, context.getBean("lookup"));
}
}
}

View File

@@ -20,10 +20,8 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import org.springframework.data.gemfire.ForkUtil;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.DataPolicy;
@@ -31,11 +29,11 @@ import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionFactory;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.distributed.DistributedSystem;
/**
* @author Costin Leau
*/
@SuppressWarnings("unchecked")
public class CacheServerProcess {
public static void main(String[] args) throws Exception {
@@ -75,4 +73,5 @@ public class CacheServerProcess {
System.out.println("Waiting for shutdown");
bufferedReader.readLine();
}
}

View File

@@ -262,6 +262,7 @@ public class FunctionArgumentResolverTest {
}
@Test
@SuppressWarnings("unchecked")
public void testMethodWithFunctionContextAndResultSender() throws NoSuchMethodException {
FunctionContext functionContext = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);

View File

@@ -48,6 +48,7 @@ import com.gemstone.gemfire.cache.Region;
* @see org.springframework.data.gemfire.mapping.Regions
* @since 1.3.4
*/
@SuppressWarnings("unchecked")
public class RegionsTest {
private MappingContext mockMappingContext;
@@ -74,7 +75,6 @@ public class RegionsTest {
}
@Before
@SuppressWarnings("unchecked")
public void setup() {
mockMappingContext = mock(GemfireMappingContext.class, "GemfireMappingContext");

View File

@@ -20,7 +20,6 @@ import java.util.Properties;
import org.springframework.cache.Cache;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.DistributedSystem;
@@ -36,6 +35,7 @@ public class GemfireCacheTest extends AbstractNativeCacheTest<Region<Object, Obj
}
@Override
@SuppressWarnings({"deprecation", "unchecked" })
protected Region<Object, Object> createNativeCache() throws Exception {
com.gemstone.gemfire.cache.Cache instance = null;
try {
@@ -49,9 +49,10 @@ public class GemfireCacheTest extends AbstractNativeCacheTest<Region<Object, Obj
}
Region reg = instance.getRegion(CACHE_NAME);
if (reg == null) {
reg = instance.createRegion(CACHE_NAME, new AttributesFactory().create());
reg = instance.createRegion(CACHE_NAME, new com.gemstone.gemfire.cache.AttributesFactory().create());
}
return reg;
}
}

View File

@@ -19,11 +19,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,11 +35,12 @@ import com.gemstone.gemfire.cache.query.SelectResults;
/**
* @author David Turanski
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SuppressWarnings("unchecked")
public class JSONRegionAdviceTest {
@SuppressWarnings("rawtypes")
@Resource(name="someRegion")
private Region region;
@@ -75,14 +73,14 @@ public class JSONRegionAdviceTest {
map.put("key1", "{\"hello1\":\"world1\"}");
map.put("key2", "{\"hello2\":\"world2\"}");
region.putAll(map);
List<String> keys = Arrays.asList(new String[]{"key1","key2"});
List<String> keys = Arrays.asList("key1", "key2");
Map<String,String> results = region.getAll(keys);
assertEquals("{\"hello1\":\"world1\"}",results.get("key1"));
assertEquals("{\"hello2\":\"world2\"}",results.get("key2"));
}
@Test
public void testObjectToJSon() throws JsonGenerationException, JsonMappingException, IOException {
public void testObjectToJSon() throws IOException {
Person dave = new Person(1L,"Dave","Turanski");
region.put("dave",dave);
String json = (String)region.get("dave");

View File

@@ -24,13 +24,11 @@ import java.io.File;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.CacheLoader;
import com.gemstone.gemfire.cache.CacheWriter;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskWriteAttributes;
import com.gemstone.gemfire.cache.EvictionAttributes;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.MembershipAttributes;
@@ -53,7 +51,7 @@ public class MockRegionFactory<K,V> {
private static QueryService queryService = mock(QueryService.class);
private static RegionService regionService = mock(RegionService.class);
private AttributesFactory<K,V> attributesFactory;
private com.gemstone.gemfire.cache.AttributesFactory<K,V> attributesFactory;
private final StubCache cache;
@@ -65,10 +63,10 @@ public class MockRegionFactory<K,V> {
return createMockRegionFactory(null);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "deprecation", "rawtypes", "unchecked" })
public RegionFactory<K, V> createMockRegionFactory(RegionAttributes<K,V> attributes) {
attributesFactory = (attributes != null ? new AttributesFactory<K,V>(attributes)
: new AttributesFactory<K,V>());
attributesFactory = (attributes != null ? new com.gemstone.gemfire.cache.AttributesFactory<K,V>(attributes)
: new com.gemstone.gemfire.cache.AttributesFactory<K,V>());
//Workaround for GemFire bug
if (attributes !=null) {
@@ -340,10 +338,12 @@ public class MockRegionFactory<K,V> {
}
});
when(regionFactory.setDiskWriteAttributes(any(DiskWriteAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
when(regionFactory.setDiskWriteAttributes(any(com.gemstone.gemfire.cache.DiskWriteAttributes.class)))
.thenAnswer(new Answer<RegionFactory>(){
@Override
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
DiskWriteAttributes val = (DiskWriteAttributes)invocation.getArguments()[0];
com.gemstone.gemfire.cache.DiskWriteAttributes val =
(com.gemstone.gemfire.cache.DiskWriteAttributes) invocation.getArguments()[0];
attributesFactory.setDiskWriteAttributes(val);
return regionFactory;
}
@@ -505,8 +505,7 @@ public class MockRegionFactory<K,V> {
when(region.getAttributes()).thenAnswer(new Answer<RegionAttributes>() {
@Override
public RegionAttributes answer(InvocationOnMock invocation) throws Throwable {
RegionAttributes attributes = attributesFactory.create();
return attributes;
return attributesFactory.create();
}
});
@@ -523,9 +522,7 @@ public class MockRegionFactory<K,V> {
String subRegionPath = (parentRegionName.startsWith("/") ? parentRegionName+"/"+subRegionName
: "/"+parentRegionName+"/"+subRegionName);
Region region = cache.getRegion(subRegionPath);
return region;
return cache.getRegion(subRegionPath);
}
});

View File

@@ -1,6 +1,10 @@
package org.springframework.data.gemfire.test;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
@@ -10,7 +14,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import javax.naming.Context;
import org.mockito.invocation.InvocationOnMock;
@@ -38,12 +41,10 @@ import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.IndexExistsException;
import com.gemstone.gemfire.cache.query.IndexInvalidException;
import com.gemstone.gemfire.cache.query.IndexNameConflictException;
import com.gemstone.gemfire.cache.query.IndexType;
import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.cache.query.RegionNotFoundException;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.cache.snapshot.CacheSnapshotService;
import com.gemstone.gemfire.cache.util.BridgeServer;
import com.gemstone.gemfire.cache.util.Gateway;
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
import com.gemstone.gemfire.cache.util.GatewayHub;
@@ -58,6 +59,8 @@ import com.gemstone.gemfire.i18n.LogWriterI18n;
import com.gemstone.gemfire.pdx.PdxInstance;
import com.gemstone.gemfire.pdx.PdxInstanceFactory;
import com.gemstone.gemfire.pdx.PdxSerializer;
@SuppressWarnings("deprecation")
public class StubCache implements Cache {
private Properties properties;
@@ -390,7 +393,7 @@ public class StubCache implements Cache {
*/
@Override
@Deprecated
public BridgeServer addBridgeServer() {
public com.gemstone.gemfire.cache.util.BridgeServer addBridgeServer() {
throw new UnsupportedOperationException();
}
@@ -462,8 +465,7 @@ public class StubCache implements Cache {
@SuppressWarnings("unchecked")
@Override
public <K, V> RegionFactory<K, V> createRegionFactory() {
RegionFactory<K, V> regionFactory = new MockRegionFactory<K,V>(this).createRegionFactory();
return regionFactory;
return new MockRegionFactory<K,V>(this).createRegionFactory();
}
/* (non-Javadoc)
@@ -472,8 +474,7 @@ public class StubCache implements Cache {
@SuppressWarnings("unchecked")
@Override
public <K, V> RegionFactory<K, V> createRegionFactory(RegionShortcut shortCut) {
RegionFactory<K, V> regionFactory = new MockRegionFactory<K,V>(this).createRegionFactory();
return regionFactory;
return new MockRegionFactory<K,V>(this).createRegionFactory();
}
/* (non-Javadoc)
@@ -482,8 +483,7 @@ public class StubCache implements Cache {
@SuppressWarnings("unchecked")
@Override
public <K, V> RegionFactory<K, V> createRegionFactory(String arg0) {
RegionFactory<K, V> regionFactory = new MockRegionFactory<K,V>(this).createRegionFactory();
return regionFactory;
return new MockRegionFactory<K,V>(this).createRegionFactory();
}
/* (non-Javadoc)
@@ -491,8 +491,7 @@ public class StubCache implements Cache {
*/
@Override
public <K, V> RegionFactory<K, V> createRegionFactory(RegionAttributes<K, V> regionAttributes) {
RegionFactory<K, V> regionFactory = new MockRegionFactory<K,V>(this).createMockRegionFactory(regionAttributes);
return regionFactory;
return new MockRegionFactory<K,V>(this).createMockRegionFactory(regionAttributes);
}
/* (non-Javadoc)
@@ -754,9 +753,6 @@ public class StubCache implements Cache {
this.searchTimeout = arg0;
}
/**
* @return
*/
DistributedSystem mockDistributedSystem() {
DistributedSystem ds = mock(DistributedSystem.class);
DistributedMember dm = mockDistributedMember();
@@ -777,10 +773,7 @@ public class StubCache implements Cache {
return dm;
}
/**
* @return
*/
CacheServer mockCacheServer() {
CacheServer mockCacheServer() {
return new StubCacheServer();
}
@@ -814,7 +807,7 @@ public class StubCache implements Cache {
String indexName = (String)invocation.getArguments()[0];
String indexedExpression = (String)invocation.getArguments()[1];
String fromClause = (String)invocation.getArguments()[2];
return mockIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause, null);
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, indexedExpression, fromClause, null);
}
});
when(qs.createIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(new Answer<Index>(){
@@ -824,7 +817,7 @@ public class StubCache implements Cache {
String indexedExpression = (String)invocation.getArguments()[1];
String fromClause = (String)invocation.getArguments()[2];
String imports = (String)invocation.getArguments()[3];
return mockIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause, imports);
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, indexedExpression, fromClause, imports);
}
});
@@ -835,7 +828,7 @@ public class StubCache implements Cache {
String indexedExpression = (String)invocation.getArguments()[1];
String fromClause = (String)invocation.getArguments()[2];
return mockIndex(indexName, IndexType.PRIMARY_KEY, indexedExpression, fromClause, null);
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY, indexedExpression, fromClause, null);
}
});
@@ -846,7 +839,7 @@ public class StubCache implements Cache {
String indexedExpression = (String)invocation.getArguments()[1];
String fromClause = (String)invocation.getArguments()[2];
return mockIndex(indexName, IndexType.HASH, indexedExpression, fromClause, null);
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.HASH, indexedExpression, fromClause, null);
}
});
@@ -858,15 +851,16 @@ public class StubCache implements Cache {
String fromClause = (String)invocation.getArguments()[2];
String imports = (String)invocation.getArguments()[3];
return mockIndex(indexName, IndexType.HASH, indexedExpression, fromClause, imports);
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.HASH, indexedExpression, fromClause, imports);
}
});
return qs;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
Index mockIndex(String indexName, IndexType indexType,String indexedExpression, String fromClause, String imports){
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
Index mockIndex(String indexName, com.gemstone.gemfire.cache.query.IndexType indexType, String indexedExpression,
String fromClause, String imports){
Index idx = mock(Index.class);
when(idx.getFromClause()).thenReturn(fromClause);
when(idx.getIndexedExpression()).thenReturn(indexedExpression);
@@ -888,18 +882,8 @@ public class StubCache implements Cache {
return this.allRegions;
}
GatewaySender mockGatewaySender(String id, int remoteId) {
GatewaySender gwSender = mock(GatewaySender.class);
when(gwSender.getId()).thenReturn(id);
when(gwSender.getRemoteDSId()).thenReturn(remoteId);
return gwSender;
}
/**
* @param props
*/
public void setProperties(Properties props) {
this.properties = props;
}
}
}

View File

@@ -26,6 +26,7 @@ import com.gemstone.gemfire.distributed.DistributedMember;
* @author David Turanski
* @author John Blum
*/
@SuppressWarnings("deprecation")
public class StubCacheServer implements CacheServer {
private boolean isRunning;

View File

@@ -12,7 +12,6 @@
*/
package org.springframework.data.gemfire.test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -20,19 +19,20 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import com.gemstone.gemfire.cache.Region;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.gemstone.gemfire.cache.util.Gateway.OrderPolicy;
import com.gemstone.gemfire.cache.wan.GatewayEventFilter;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import com.gemstone.gemfire.cache.wan.GatewaySenderFactory;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
* The StubGatewaySenderFactory class for testing purposes.
* <p/>
* @author David Turanski
*
* @see com.gemstone.gemfire.cache.wan.GatewaySenderFactory
*/
public class StubGatewaySenderFactory implements GatewaySenderFactory {
@@ -210,4 +210,5 @@ public class StubGatewaySenderFactory implements GatewaySenderFactory {
// TODO Auto-generated method stub
return null;
}
}