Implements JIRA feature request SGF-227 adding support for GemFire 8.0's auto-reconnect functionality on forced disconnects.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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
|
||||
*
|
||||
* 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.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
|
||||
/**
|
||||
* The CacheAutoReconnectIntegrationTests class is a tests suite of test cases testing Spring Data GemFire's support
|
||||
* of GemFire's Auto-Reconnect functionality release in 8.0.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class CacheAutoReconnectIntegrationTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
assumeNotNull(applicationContext);
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
protected Cache getCache(String configLocation) {
|
||||
String baseConfigLocation = File.separator.concat(
|
||||
getClass().getPackage().getName().replace('.', File.separatorChar));
|
||||
applicationContext = new ClassPathXmlApplicationContext(baseConfigLocation.concat(File.separator).concat(configLocation));
|
||||
return applicationContext.getBean(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME, Cache.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoReconnectDisabled() {
|
||||
Cache cache = getCache("cacheAutoReconnectDisabledIntegrationTests.xml");
|
||||
assertNotNull(cache.getDistributedSystem());
|
||||
assertNotNull(cache.getDistributedSystem().getProperties());
|
||||
assertTrue(Boolean.valueOf(cache.getDistributedSystem().getProperties().getProperty("disable-auto-reconnect")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoReconnectEnabled() {
|
||||
Cache cache = getCache("cacheAutoReconnectEnabledIntegrationTests.xml");
|
||||
assertNotNull(cache.getDistributedSystem());
|
||||
assertNotNull(cache.getDistributedSystem().getProperties());
|
||||
assertFalse(Boolean.valueOf(cache.getDistributedSystem().getProperties().getProperty("disable-auto-reconnect")));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,11 +19,14 @@ package org.springframework.data.gemfire.config;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -45,100 +48,179 @@ import com.gemstone.gemfire.cache.util.TimestampedEntryEvent;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="/org/springframework/data/gemfire/config/cache-ns.xml",
|
||||
initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@ContextConfiguration(locations = "cache-ns.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheNamespaceTest{
|
||||
@Autowired ApplicationContext ctx;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testBasicCache() throws Exception {
|
||||
assertTrue(ctx.containsBean("gemfireCache"));
|
||||
//Check alias is registered
|
||||
assertTrue(ctx.containsBean("gemfire-cache"));
|
||||
//
|
||||
CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&gemfireCache");
|
||||
assertNull(TestUtils.readField("cacheXml", cfb));
|
||||
assertNull(TestUtils.readField("properties", cfb));
|
||||
public void testNoNamedCache() throws Exception {
|
||||
assertTrue(context.containsBean("gemfireCache"));
|
||||
assertTrue(context.containsBean("gemfire-cache")); // assert alias is registered
|
||||
|
||||
Cache gemfireCache = context.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertNotNull(gemfireCache);
|
||||
assertNotNull(gemfireCache.getDistributedSystem());
|
||||
assertNotNull(gemfireCache.getDistributedSystem().getProperties());
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertNull(TestUtils.readField("cacheXml", cacheFactoryBean));
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.getProperties();
|
||||
|
||||
assertNotNull(gemfireProperties);
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(Boolean.parseBoolean(gemfireProperties.getProperty("disable-auto-reconnect")));
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedCache() throws Exception {
|
||||
assertTrue(ctx.containsBean("cache-with-name"));
|
||||
CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&cache-with-name");
|
||||
assertNull(TestUtils.readField("cacheXml", cfb));
|
||||
assertNull(TestUtils.readField("properties", cfb));
|
||||
assertTrue(context.containsBean("cache-with-name"));
|
||||
|
||||
Cache gemfireCache = context.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-name", CacheFactoryBean.class);
|
||||
|
||||
assertNull(TestUtils.readField("cacheXml", cacheFactoryBean));
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.getProperties();
|
||||
|
||||
assertNotNull(gemfireProperties);
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(Boolean.parseBoolean(gemfireProperties.getProperty("disable-auto-reconnect")));
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithXml() throws Exception {
|
||||
assertTrue(ctx.containsBean("cache-with-xml"));
|
||||
CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&cache-with-xml");
|
||||
Resource res = TestUtils.readField("cacheXml", cfb);
|
||||
assertEquals("gemfire-cache.xml", res.getFilename());
|
||||
assertEquals(ctx.getBean("props"), TestUtils.readField("properties", cfb));
|
||||
public void testCacheWithXmlAndProperties() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-xml-and-props"));
|
||||
|
||||
assertEquals(Boolean.FALSE, TestUtils.readField("pdxIgnoreUnreadFields", cfb));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxPersistent", cfb));
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-xml-and-props", CacheFactoryBean.class);
|
||||
Resource cacheXmlResource = TestUtils.readField("cacheXml", cacheFactoryBean);
|
||||
|
||||
assertEquals("gemfire-cache.xml", cacheXmlResource.getFilename());
|
||||
assertTrue(context.containsBean("gemfireProperties"));
|
||||
assertEquals(context.getBean("gemfireProperties"), TestUtils.readField("properties", cacheFactoryBean));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxReadSerialized", cacheFactoryBean));
|
||||
assertEquals(Boolean.FALSE, TestUtils.readField("pdxIgnoreUnreadFields", cacheFactoryBean));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxPersistent", cacheFactoryBean));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithGatewayConflictResolver() {
|
||||
Cache cache = ctx.getBean("cache-with-conflict-resolver", Cache.class);
|
||||
assertNotNull(cache.getGatewayConflictResolver());
|
||||
assertTrue(cache.getGatewayConflictResolver() instanceof TestConflictResolver);
|
||||
}
|
||||
Cache cache = context.getBean("cache-with-gateway-conflict-resolver", Cache.class);
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoBeanFactory() throws Exception {
|
||||
assertTrue(ctx.containsBean("no-bl"));
|
||||
CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&no-bl");
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(cfb, "factoryLocator"), is(nullValue()));
|
||||
|
||||
GemfireBeanFactoryLocator locator = new GemfireBeanFactoryLocator();
|
||||
try {
|
||||
assertNotNull(locator.useBeanFactory("cache-with-name"));
|
||||
locator.useBeanFactory("no-bl");
|
||||
}
|
||||
finally {
|
||||
locator.destroy();
|
||||
}
|
||||
assertTrue(cache.getGatewayConflictResolver() instanceof TestGatewayConflictResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicClientCache() throws Exception {
|
||||
assertTrue(ctx.containsBean("client-cache"));
|
||||
ClientCacheFactoryBean cfb = (ClientCacheFactoryBean) ctx.getBean("&client-cache");
|
||||
assertNull(TestUtils.readField("cacheXml", cfb));
|
||||
assertNull(TestUtils.readField("properties", cfb));
|
||||
public void testCacheWithAutoReconnectDisabled() {
|
||||
assertTrue(context.containsBean("cache-with-auto-reconnect-disabled"));
|
||||
|
||||
Cache gemfireCache = context.getBean("cache-with-auto-reconnect-disabled", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-auto-reconnect-disabled", CacheFactoryBean.class);
|
||||
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicClientCacheWithXml() throws Exception {
|
||||
assertTrue(ctx.containsBean("client-cache-with-xml"));
|
||||
ClientCacheFactoryBean cfb = (ClientCacheFactoryBean) ctx.getBean("&client-cache-with-xml");
|
||||
Resource res = TestUtils.readField("cacheXml", cfb);
|
||||
assertEquals("gemfire-client-cache.xml", res.getFilename());
|
||||
public void testCacheWithAutoReconnectEnabled() {
|
||||
assertTrue(context.containsBean("cache-with-auto-reconnect-enabled"));
|
||||
|
||||
Cache gemfireCache = context.getBean("cache-with-auto-reconnect-enabled", Cache.class);
|
||||
|
||||
assertFalse(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-auto-reconnect-enabled", CacheFactoryBean.class);
|
||||
|
||||
assertTrue(cacheFactoryBean.getEnableAutoReconnect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeapTunedCache() throws Exception {
|
||||
assertTrue(ctx.containsBean("heap-tuned-cache"));
|
||||
CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&heap-tuned-cache");
|
||||
Float chp = (Float) TestUtils.readField("criticalHeapPercentage", cfb);
|
||||
Float ehp = (Float) TestUtils.readField("evictionHeapPercentage", cfb);
|
||||
assertEquals(70, chp, 0.0001);
|
||||
assertEquals(60, ehp, 0.0001);
|
||||
assertTrue(context.containsBean("heap-tuned-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalHeapPercentage = (Float) TestUtils.readField("criticalHeapPercentage", cacheFactoryBean);
|
||||
Float evictionHeapPercentage = (Float) TestUtils.readField("evictionHeapPercentage", cacheFactoryBean);
|
||||
|
||||
assertEquals(70.0f, criticalHeapPercentage, 0.0001);
|
||||
assertEquals(60.0f, evictionHeapPercentage, 0.0001);
|
||||
}
|
||||
|
||||
public static class TestConflictResolver implements GatewayConflictResolver {
|
||||
@Override
|
||||
public void onEvent(TimestampedEntryEvent arg0, GatewayConflictHelper arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoBeanFactoryLocator() throws Exception {
|
||||
assertTrue(context.containsBean("no-bean-factory-locator"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&no-bean-factory-locator", CacheFactoryBean.class);
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(cacheFactoryBean, "factoryLocator"), is(nullValue()));
|
||||
|
||||
GemfireBeanFactoryLocator beanFactoryLocator = new GemfireBeanFactoryLocator();
|
||||
|
||||
try {
|
||||
assertNotNull(beanFactoryLocator.useBeanFactory("cache-with-name"));
|
||||
beanFactoryLocator.useBeanFactory("no-bean-factory-locator");
|
||||
}
|
||||
finally {
|
||||
beanFactoryLocator.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedClientCache() throws Exception {
|
||||
assertTrue(context.containsBean("client-cache-with-name"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = context.getBean("&client-cache-with-name", ClientCacheFactoryBean.class);
|
||||
|
||||
assertNull(TestUtils.readField("cacheXml", clientCacheFactoryBean));
|
||||
|
||||
Properties gemfireProperties = clientCacheFactoryBean.getProperties();
|
||||
|
||||
assertNotNull(gemfireProperties);
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientCacheWithXml() throws Exception {
|
||||
assertTrue(context.containsBean("client-cache-with-xml"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = context.getBean("&client-cache-with-xml", ClientCacheFactoryBean.class);
|
||||
Resource cacheXmlResource = TestUtils.readField("cacheXml", clientCacheFactoryBean);
|
||||
|
||||
assertEquals("gemfire-client-cache.xml", cacheXmlResource.getFilename());
|
||||
|
||||
Properties gemfireProperties = clientCacheFactoryBean.getProperties();
|
||||
|
||||
assertNotNull(gemfireProperties);
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
}
|
||||
|
||||
public static class TestGatewayConflictResolver implements GatewayConflictResolver {
|
||||
@Override
|
||||
public void onEvent(TimestampedEntryEvent arg0, GatewayConflictHelper arg1) {
|
||||
throw new UnsupportedOperationException("Not Implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,14 +37,17 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
this.factoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.lazyInitialize = cacheFactoryBean.isLazyInitialize();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = cacheFactoryBean.getBeanFactory();
|
||||
this.beanName = cacheFactoryBean.getBeanName();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.cacheXml = cacheFactoryBean.getCacheXml();
|
||||
this.properties = cacheFactoryBean.getProperties();
|
||||
this.copyOnRead = cacheFactoryBean.getCopyOnRead();
|
||||
this.criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
this.dynamicRegionSupport = cacheFactoryBean.getDynamicRegionSupport();
|
||||
this.evictionHeapPercentage = cacheFactoryBean.getEvictionHeapPercentage();
|
||||
this.dynamicRegionSupport = cacheFactoryBean.getDynamicRegionSupport();
|
||||
this.enableAutoReconnect = cacheFactoryBean.getEnableAutoReconnect();
|
||||
this.gatewayConflictResolver = cacheFactoryBean.getGatewayConflictResolver();
|
||||
this.jndiDataSources = cacheFactoryBean.getJndiDataSources();
|
||||
this.lockLease = cacheFactoryBean.getLockLease();
|
||||
@@ -55,23 +58,20 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
this.pdxPersistent = cacheFactoryBean.getPdxPersistent();
|
||||
this.pdxReadSerialized = cacheFactoryBean.getPdxReadSerialized();
|
||||
this.pdxSerializer = cacheFactoryBean.getPdxSerializer();
|
||||
this.properties = cacheFactoryBean.getProperties();
|
||||
this.searchTimeout = cacheFactoryBean.getSearchTimeout();
|
||||
this.transactionListeners = cacheFactoryBean.getTransactionListeners();
|
||||
this.transactionWriter = cacheFactoryBean.getTransactionWriter();
|
||||
this.properties = cacheFactoryBean.getProperties();
|
||||
this.lazyInitialize = cacheFactoryBean.isLazyInitialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties props) {
|
||||
setProperties(props);
|
||||
return new CacheFactory(props);
|
||||
protected Object createFactory(Properties gemfireProperties) {
|
||||
setProperties(gemfireProperties);
|
||||
return new CacheFactory(gemfireProperties);
|
||||
}
|
||||
|
||||
|
||||
protected GemFireCache fetchCache() {
|
||||
((StubCache)cache).setProperties(this.properties);
|
||||
((StubCache) cache).setProperties(this.properties);
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,8 +62,8 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties props) {
|
||||
((StubCache)cache).setProperties(props);
|
||||
return new ClientCacheFactory(props);
|
||||
protected Object createFactory(Properties gemfireProperties) {
|
||||
((StubCache)cache).setProperties(gemfireProperties);
|
||||
return new ClientCacheFactory(gemfireProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,23 +740,29 @@ public class StubCache implements Cache {
|
||||
}
|
||||
|
||||
DistributedSystem mockDistributedSystem() {
|
||||
DistributedSystem ds = mock(DistributedSystem.class);
|
||||
DistributedMember dm = mockDistributedMember();
|
||||
when(ds.getName()).thenAnswer(new Answer<String>() {
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
when(mockDistributedSystem.getName()).thenAnswer(new Answer<String>() {
|
||||
@Override
|
||||
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
});
|
||||
when(ds.getDistributedMember()).thenReturn(dm);
|
||||
return ds;
|
||||
|
||||
when(mockDistributedSystem.getProperties()).thenReturn(this.properties);
|
||||
|
||||
DistributedMember mockDistributedMember = mockDistributedMember();
|
||||
|
||||
when(mockDistributedSystem.getDistributedMember()).thenReturn(mockDistributedMember);
|
||||
|
||||
return mockDistributedSystem;
|
||||
}
|
||||
|
||||
DistributedMember mockDistributedMember() {
|
||||
DistributedMember dm = mock(DistributedMember.class);
|
||||
when(dm.getHost()).thenReturn("mockDistributedMember.host");
|
||||
when(dm.getName()).thenReturn("mockDistributedMember");
|
||||
return dm;
|
||||
DistributedMember mockDistributedMember = mock(DistributedMember.class);
|
||||
when(mockDistributedMember.getHost()).thenReturn("mockDistributedMember.host");
|
||||
when(mockDistributedMember.getName()).thenReturn("mockDistributedMember");
|
||||
return mockDistributedMember;
|
||||
}
|
||||
|
||||
CacheServer mockCacheServer() {
|
||||
@@ -764,84 +770,89 @@ public class StubCache implements Cache {
|
||||
}
|
||||
|
||||
GatewayHub mockGatewayHub() {
|
||||
final Gateway gw = mock(Gateway.class);
|
||||
final GatewayQueueAttributes queueAttributes= mock(GatewayQueueAttributes.class);
|
||||
when(gw.getQueueAttributes()).thenReturn(queueAttributes);
|
||||
GatewayHub gwh = mock(GatewayHub.class);
|
||||
when(gwh.addGateway(anyString(),anyInt())).thenAnswer(new Answer<Gateway>() {
|
||||
final Gateway gateway = mock(Gateway.class);
|
||||
|
||||
when(gateway.getQueueAttributes()).thenReturn(mock(GatewayQueueAttributes.class));
|
||||
|
||||
GatewayHub gatewayHub = mock(GatewayHub.class);
|
||||
|
||||
when(gatewayHub.addGateway(anyString(),anyInt())).thenAnswer(new Answer<Gateway>() {
|
||||
@Override
|
||||
public Gateway answer(InvocationOnMock invocation) throws Throwable {
|
||||
// TODO Auto-generated method stub
|
||||
return gw;
|
||||
return gateway;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
return gwh;
|
||||
|
||||
return gatewayHub;
|
||||
}
|
||||
|
||||
QueryService mockQueryService() throws RegionNotFoundException, IndexInvalidException, IndexNameConflictException, IndexExistsException, UnsupportedOperationException {
|
||||
|
||||
QueryService qs = mock(QueryService.class);
|
||||
|
||||
when(qs.getIndexes()).thenReturn(new ArrayList<Index>());
|
||||
|
||||
|
||||
when(qs.createIndex(anyString(), anyString(),anyString())).thenAnswer(new Answer<Index>(){
|
||||
QueryService queryService = mock(QueryService.class);
|
||||
|
||||
when(queryService.getIndexes()).thenReturn(new ArrayList<Index>());
|
||||
|
||||
when(queryService.createIndex(anyString(), anyString(),anyString())).thenAnswer(new Answer<Index>() {
|
||||
@Override
|
||||
public Index answer(InvocationOnMock invocation) throws Throwable {
|
||||
String indexName = (String)invocation.getArguments()[0];
|
||||
String indexedExpression = (String)invocation.getArguments()[1];
|
||||
String fromClause = (String)invocation.getArguments()[2];
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, indexedExpression, fromClause, null);
|
||||
String indexName = (String) invocation.getArguments()[0];
|
||||
String indexedExpression = (String) invocation.getArguments()[1];
|
||||
String fromClause = (String) invocation.getArguments()[2];
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, indexedExpression,
|
||||
fromClause, null);
|
||||
}
|
||||
});
|
||||
when(qs.createIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(new Answer<Index>(){
|
||||
|
||||
when(queryService.createIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(new Answer<Index>() {
|
||||
@Override
|
||||
public Index answer(InvocationOnMock invocation) throws Throwable {
|
||||
String indexName = (String)invocation.getArguments()[0];
|
||||
String indexedExpression = (String)invocation.getArguments()[1];
|
||||
String fromClause = (String)invocation.getArguments()[2];
|
||||
String imports = (String)invocation.getArguments()[3];
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, indexedExpression, fromClause, imports);
|
||||
String indexName = (String) invocation.getArguments()[0];
|
||||
String indexedExpression = (String) invocation.getArguments()[1];
|
||||
String fromClause = (String) invocation.getArguments()[2];
|
||||
String imports = (String) invocation.getArguments()[3];
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, indexedExpression,
|
||||
fromClause, imports);
|
||||
}
|
||||
});
|
||||
|
||||
when(qs.createKeyIndex(anyString(), anyString(),anyString())).thenAnswer(new Answer<Index>(){
|
||||
|
||||
when(queryService.createKeyIndex(anyString(), anyString(),anyString())).thenAnswer(new Answer<Index>() {
|
||||
@Override
|
||||
public Index answer(InvocationOnMock invocation) throws Throwable {
|
||||
String indexName = (String)invocation.getArguments()[0];
|
||||
String indexedExpression = (String)invocation.getArguments()[1];
|
||||
String fromClause = (String)invocation.getArguments()[2];
|
||||
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY, indexedExpression, fromClause, null);
|
||||
String indexName = (String) invocation.getArguments()[0];
|
||||
String indexedExpression = (String) invocation.getArguments()[1];
|
||||
String fromClause = (String) invocation.getArguments()[2];
|
||||
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY, indexedExpression,
|
||||
fromClause, null);
|
||||
}
|
||||
});
|
||||
|
||||
when(qs.createHashIndex(anyString(), anyString(),anyString())).thenAnswer(new Answer<Index>(){
|
||||
|
||||
when(queryService.createHashIndex(anyString(), anyString(),anyString())).thenAnswer(new Answer<Index>() {
|
||||
@Override
|
||||
public Index answer(InvocationOnMock invocation) throws Throwable {
|
||||
String indexName = (String)invocation.getArguments()[0];
|
||||
String indexedExpression = (String)invocation.getArguments()[1];
|
||||
String fromClause = (String)invocation.getArguments()[2];
|
||||
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.HASH, indexedExpression, fromClause, null);
|
||||
String indexName = (String) invocation.getArguments()[0];
|
||||
String indexedExpression = (String) invocation.getArguments()[1];
|
||||
String fromClause = (String) invocation.getArguments()[2];
|
||||
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.HASH, indexedExpression,
|
||||
fromClause, null);
|
||||
}
|
||||
});
|
||||
|
||||
when(qs.createHashIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(new Answer<Index>(){
|
||||
|
||||
when(queryService.createHashIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(new Answer<Index>() {
|
||||
@Override
|
||||
public Index answer(InvocationOnMock invocation) throws Throwable {
|
||||
String indexName = (String)invocation.getArguments()[0];
|
||||
String indexedExpression = (String)invocation.getArguments()[1];
|
||||
String fromClause = (String)invocation.getArguments()[2];
|
||||
String imports = (String)invocation.getArguments()[3];
|
||||
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.HASH, indexedExpression, fromClause, imports);
|
||||
String indexName = (String) invocation.getArguments()[0];
|
||||
String indexedExpression = (String) invocation.getArguments()[1];
|
||||
String fromClause = (String) invocation.getArguments()[2];
|
||||
String imports = (String) invocation.getArguments()[3];
|
||||
|
||||
return mockIndex(indexName, com.gemstone.gemfire.cache.query.IndexType.HASH, indexedExpression,
|
||||
fromClause, imports);
|
||||
}
|
||||
});
|
||||
|
||||
return qs;
|
||||
|
||||
return queryService;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
@@ -868,8 +879,8 @@ public class StubCache implements Cache {
|
||||
return this.allRegions;
|
||||
}
|
||||
|
||||
public void setProperties(Properties props) {
|
||||
this.properties = props;
|
||||
public void setProperties(Properties gemfireProperties) {
|
||||
this.properties = gemfireProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -882,13 +893,13 @@ public class StubCache implements Cache {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReconnecting() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waitUntilReconnected(final long l, final TimeUnit timeUnit) throws InterruptedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReconnecting() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user