SGF-374 - Specifying a disk-store on a GatewayHub forces the GatewayHub to be persistent.
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
import com.gemstone.gemfire.cache.util.GatewayEvent;
|
||||
import com.gemstone.gemfire.cache.util.GatewayEventListener;
|
||||
import com.gemstone.gemfire.cache.util.GatewayHub;
|
||||
import com.gemstone.gemfire.cache.util.GatewayQueueAttributes;
|
||||
|
||||
/**
|
||||
* The GatewayHubNamespaceTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the GatewayHub SDG XML namespace (XSD) configuration meta-data.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.data.gemfire.wan.GatewayHubFactoryBean
|
||||
* @see org.springframework.data.gemfire.wan.GatewayProxy
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayHub
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings({"deprecation", "unused" })
|
||||
public class GatewayHubNamespaceTest {
|
||||
|
||||
@Resource(name = "Example")
|
||||
private Region<?, ?> example;
|
||||
|
||||
@Autowired
|
||||
private GatewayHub gatewayHub;
|
||||
|
||||
@Test
|
||||
public void testRegionConfiguration() {
|
||||
assertNotNull("The '/Example' Region was not properly initialized!", example);
|
||||
assertEquals("Example", example.getName());
|
||||
assertEquals("/Example", example.getFullPath());
|
||||
assertNotNull(example.getAttributes());
|
||||
assertEquals(DataPolicy.REPLICATE, example.getAttributes().getDataPolicy());
|
||||
assertTrue(example.getAttributes().getEnableGateway());
|
||||
assertEquals("testGatewayHub", example.getAttributes().getGatewayHubId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayConfiguration() {
|
||||
assertNotNull("The 'testGatewayHub' GatewayHub was not properly initialized!", gatewayHub);
|
||||
assertEquals("localhost", gatewayHub.getBindAddress());
|
||||
assertEquals("testGatewayHub", gatewayHub.getId());
|
||||
assertTrue(gatewayHub.getManualStart());
|
||||
//assertEquals(GatewayHub.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, gatewayHub.getMaximumTimeBetweenPings());
|
||||
assertEquals(45123, gatewayHub.getPort());
|
||||
assertEquals(16384, gatewayHub.getSocketBufferSize());
|
||||
assertEquals("primary", gatewayHub.getStartupPolicy());
|
||||
|
||||
List<Gateway> gateways = gatewayHub.getGateways();
|
||||
|
||||
assertNotNull(gateways);
|
||||
assertFalse(gateways.isEmpty());
|
||||
assertEquals(2, gateways.size());
|
||||
|
||||
Gateway gatewayOne = gateways.get(0);
|
||||
|
||||
assertEquals("gateway1", gatewayOne.getId());
|
||||
assertEquals(8, gatewayOne.getConcurrencyLevel());
|
||||
assertEquals(Gateway.OrderPolicy.THREAD, gatewayOne.getOrderPolicy());
|
||||
assertEquals(65536, gatewayOne.getSocketBufferSize());
|
||||
//assertEquals(120, gatewayOne.getSocketReadTimeout());
|
||||
assertNotNull(gatewayOne.getListeners());
|
||||
assertFalse(gatewayOne.getListeners().isEmpty());
|
||||
assertEquals(1, gatewayOne.getListeners().size());
|
||||
assertTrue(gatewayOne.getListeners().get(0) instanceof TestGatewayListener);
|
||||
|
||||
GatewayQueueAttributes gatewayQueueAttributes = gatewayOne.getQueueAttributes();
|
||||
|
||||
assertNotNull(gatewayQueueAttributes);
|
||||
assertEquals(99, gatewayQueueAttributes.getAlertThreshold());
|
||||
assertTrue(gatewayQueueAttributes.getBatchConflation());
|
||||
assertEquals(3, gatewayQueueAttributes.getBatchSize());
|
||||
assertEquals(10, gatewayQueueAttributes.getBatchTimeInterval());
|
||||
assertEquals(5, gatewayQueueAttributes.getMaximumQueueMemory());
|
||||
assertFalse(gatewayQueueAttributes.getEnablePersistence());
|
||||
|
||||
Gateway gatewayTwo = gateways.get(1);
|
||||
|
||||
assertEquals("gateway2", gatewayTwo.getId());
|
||||
|
||||
List gatewayEndpoints = gatewayTwo.getEndpoints();
|
||||
|
||||
assertNotNull(gatewayEndpoints);
|
||||
assertFalse(gatewayEndpoints.isEmpty());
|
||||
assertEquals(2, gatewayEndpoints.size());
|
||||
|
||||
Gateway.Endpoint gatewayEndpointOne = (Gateway.Endpoint) gatewayEndpoints.get(0);
|
||||
|
||||
assertEquals("endpoint1", gatewayEndpointOne.getId());
|
||||
assertEquals("localhost", gatewayEndpointOne.getHost());
|
||||
assertEquals(1234, gatewayEndpointOne.getPort());
|
||||
|
||||
Gateway.Endpoint gatewayEndpointTwo = (Gateway.Endpoint) gatewayEndpoints.get(1);
|
||||
|
||||
assertEquals("endpoint2", gatewayEndpointTwo.getId());
|
||||
assertEquals("localhost", gatewayEndpointTwo.getHost());
|
||||
assertEquals(4321, gatewayEndpointTwo.getPort());
|
||||
}
|
||||
|
||||
public static final class TestGatewayListener implements GatewayEventListener {
|
||||
|
||||
@Override
|
||||
public boolean processEvents(final List<GatewayEvent> events) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import org.springframework.data.gemfire.test.support.IdentifierSequence;
|
||||
import org.springframework.data.gemfire.test.support.StackTraceUtils;
|
||||
|
||||
/**
|
||||
* The AbstractMockery class is an abstract base class supporting the creation and use of mock objects in unit tests.
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class AbstractMockerySupport {
|
||||
|
||||
protected static final String NOT_IMPLEMENTED = "Not Implemented";
|
||||
|
||||
protected Object getMockId() {
|
||||
StackTraceElement element = StackTraceUtils.getTestCaller();
|
||||
return (element != null ? StackTraceUtils.getCallerSimpleName(element): IdentifierSequence.nextId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
import com.gemstone.gemfire.cache.util.GatewayEventListener;
|
||||
import com.gemstone.gemfire.cache.util.GatewayQueueAttributes;
|
||||
|
||||
/**
|
||||
* The MockGatewayFactory class is a factory for creating mock GemFire Gateways, GatewayQueueAttributes
|
||||
* and Gateway.Endpoints.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.wan.GatewayHubFactoryBean
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayHub
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class MockGatewayFactory extends AbstractMockerySupport {
|
||||
|
||||
private Boolean batchConflation = GatewayQueueAttributes.DEFAULT_BATCH_CONFLATION;
|
||||
private Boolean persistence = GatewayQueueAttributes.DEFAULT_ENABLE_PERSISTENCE;
|
||||
|
||||
private Gateway.OrderPolicy orderPolicy;
|
||||
|
||||
private GatewayQueueAttributes queueAttributes;
|
||||
|
||||
private Integer alertThreshold = GatewayQueueAttributes.DEFAULT_ALERT_THRESHOLD;
|
||||
private Integer batchSize = GatewayQueueAttributes.DEFAULT_BATCH_SIZE;
|
||||
private Integer batchTimeInterval = GatewayQueueAttributes.DEFAULT_BATCH_TIME_INTERVAL;
|
||||
private Integer maxQueueMemory = GatewayQueueAttributes.DEFAULT_MAXIMUM_QUEUE_MEMORY;
|
||||
private Integer socketBufferSize = Gateway.DEFAULT_SOCKET_BUFFER_SIZE;
|
||||
private Integer socketReadTimeout = Gateway.DEFAULT_SOCKET_READ_TIMEOUT;
|
||||
|
||||
private List<Gateway.Endpoint> endpoints;
|
||||
private List<GatewayEventListener> listeners;
|
||||
|
||||
private String diskStoreName;
|
||||
|
||||
public MockGatewayFactory() {
|
||||
endpoints = new ArrayList<Gateway.Endpoint>();
|
||||
listeners = new ArrayList<GatewayEventListener>();
|
||||
queueAttributes = mockGatewayQueueAttributes();
|
||||
}
|
||||
|
||||
public Gateway mockGateway(final String id, final int concurrencyLevel) {
|
||||
Gateway mockGateway = mock(Gateway.class, String.format("%1$s.MockGateway", getMockId()));
|
||||
|
||||
when(mockGateway.getConcurrencyLevel()).thenReturn(concurrencyLevel);
|
||||
when(mockGateway.getEndpoints()).thenReturn(endpoints);
|
||||
when(mockGateway.getId()).thenReturn(id);
|
||||
when(mockGateway.getListeners()).thenReturn(listeners);
|
||||
when(mockGateway.getQueueSize()).thenThrow(new UnsupportedOperationException(NOT_IMPLEMENTED));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
orderPolicy = invocation.getArgumentAt(0, Gateway.OrderPolicy.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGateway).setOrderPolicy(any(Gateway.OrderPolicy.class));
|
||||
|
||||
when(mockGateway.getOrderPolicy()).thenAnswer(new Answer<Gateway.OrderPolicy>() {
|
||||
@Override public Gateway.OrderPolicy answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return orderPolicy;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
queueAttributes = invocation.getArgumentAt(0, GatewayQueueAttributes.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGateway).setQueueAttributes(any(GatewayQueueAttributes.class));
|
||||
|
||||
when(mockGateway.getQueueAttributes()).thenAnswer(new Answer<GatewayQueueAttributes>() {
|
||||
@Override public GatewayQueueAttributes answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return queueAttributes;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
socketBufferSize = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGateway).setSocketBufferSize(anyInt());
|
||||
|
||||
when(mockGateway.getSocketBufferSize()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return socketBufferSize;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
socketReadTimeout = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGateway).setSocketReadTimeout(anyInt());
|
||||
|
||||
when(mockGateway.getSocketReadTimeout()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return socketReadTimeout;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String id = invocation.getArgumentAt(0, String.class);
|
||||
String host = invocation.getArgumentAt(1, String.class);
|
||||
int port = invocation.getArgumentAt(2, Integer.class);
|
||||
endpoints.add(mockGatewayEndpoint(id, host, port));
|
||||
return null;
|
||||
}
|
||||
}).when(mockGateway).addEndpoint(anyString(), anyString(), anyInt());
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
listeners.add(invocation.getArgumentAt(0, GatewayEventListener.class));
|
||||
return null;
|
||||
}
|
||||
}).when(mockGateway).addListener(any(GatewayEventListener.class));
|
||||
|
||||
return mockGateway;
|
||||
}
|
||||
|
||||
public Gateway.Endpoint mockGatewayEndpoint(final String id, final String host, final int port) {
|
||||
Gateway.Endpoint mockEndpoint = mock(Gateway.Endpoint.class,
|
||||
String.format("%1$s.MockGatewayEndpoint", getMockId()));
|
||||
|
||||
when(mockEndpoint.getId()).thenReturn(id);
|
||||
when(mockEndpoint.getHost()).thenReturn(host);
|
||||
when(mockEndpoint.getPort()).thenReturn(port);
|
||||
|
||||
return mockEndpoint;
|
||||
}
|
||||
|
||||
public GatewayQueueAttributes mockGatewayQueueAttributes() {
|
||||
GatewayQueueAttributes mockQueueAttributes = mock(GatewayQueueAttributes.class,
|
||||
String.format("%1$s.MockGatewayQueueAttributes", getMockId()));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
alertThreshold = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setAlertThreshold(anyInt());
|
||||
|
||||
when(mockQueueAttributes.getAlertThreshold()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return alertThreshold;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
batchConflation = invocation.getArgumentAt(0, Boolean.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setBatchConflation(anyBoolean());
|
||||
|
||||
when(mockQueueAttributes.getBatchConflation()).thenAnswer(new Answer<Boolean>() {
|
||||
@Override public Boolean answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return batchConflation;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
batchSize = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setBatchSize(anyInt());
|
||||
|
||||
when(mockQueueAttributes.getBatchSize()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return batchSize;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
batchTimeInterval = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setBatchTimeInterval(anyInt());
|
||||
|
||||
when(mockQueueAttributes.getBatchTimeInterval()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return batchTimeInterval;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
diskStoreName = invocation.getArgumentAt(0, String.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setDiskStoreName(anyString());
|
||||
|
||||
when(mockQueueAttributes.getDiskStoreName()).thenAnswer(new Answer<String>() {
|
||||
@Override public String answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return diskStoreName;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
persistence = invocation.getArgumentAt(0, Boolean.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setEnablePersistence(anyBoolean());
|
||||
|
||||
when(mockQueueAttributes.getEnablePersistence()).thenAnswer(new Answer<Boolean>() {
|
||||
@Override public Boolean answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return persistence;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
maxQueueMemory = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockQueueAttributes).setMaximumQueueMemory(anyInt());
|
||||
|
||||
when(mockQueueAttributes.getMaximumQueueMemory()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return maxQueueMemory;
|
||||
}
|
||||
});
|
||||
|
||||
return mockQueueAttributes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.test;
|
||||
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
import com.gemstone.gemfire.cache.util.GatewayHub;
|
||||
|
||||
/**
|
||||
* The MockGatewayHubFactory class is a factory for creating mock GemFire GatewayHubs.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.test.AbstractMockerySupport
|
||||
* @see org.springframework.data.gemfire.wan.GatewayHubFactoryBean
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayHub
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class MockGatewayHubFactory extends AbstractMockerySupport {
|
||||
|
||||
private static final AtomicLong ID_SEQUENCE = new AtomicLong(System.currentTimeMillis());
|
||||
|
||||
private Boolean manualStart = GatewayHub.DEFAULT_MANUAL_START;
|
||||
|
||||
private Integer maximumTimeBetweenPings = GatewayHub.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS;
|
||||
private Integer socketBufferSize = GatewayHub.DEFAULT_SOCKET_BUFFER_SIZE;
|
||||
|
||||
private List<Gateway> gateways = new ArrayList<Gateway>();
|
||||
|
||||
private String bindAddress = GatewayHub.DEFAULT_BIND_ADDRESS;
|
||||
private String startupPolicy = GatewayHub.DEFAULT_STARTUP_POLICY;
|
||||
|
||||
public GatewayHub mockGatewayHub(final String id, final int port) {
|
||||
final GatewayHub mockGatewayHub = mock(GatewayHub.class, String.format("%1$s.MockGatewayHub", getMockId()));
|
||||
|
||||
when(mockGatewayHub.getGateways()).thenReturn(gateways);
|
||||
when(mockGatewayHub.getGatewayIds()).thenReturn(getGatewayIds(gateways));
|
||||
when(mockGatewayHub.getId()).thenReturn(id);
|
||||
when(mockGatewayHub.getPort()).thenReturn(port);
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
bindAddress = invocation.getArgumentAt(0, String.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGatewayHub).setBindAddress(anyString());
|
||||
|
||||
when(mockGatewayHub.getBindAddress()).thenAnswer(new Answer<String>() {
|
||||
@Override public String answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return bindAddress;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
manualStart = invocation.getArgumentAt(0, Boolean.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGatewayHub).setManualStart(anyBoolean());
|
||||
|
||||
when(mockGatewayHub.getManualStart()).thenAnswer(new Answer<Boolean>() {
|
||||
@Override public Boolean answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return manualStart;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
maximumTimeBetweenPings = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGatewayHub).setMaximumTimeBetweenPings(anyInt());
|
||||
|
||||
when(mockGatewayHub.getMaximumTimeBetweenPings()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return maximumTimeBetweenPings;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
socketBufferSize = invocation.getArgumentAt(0, Integer.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGatewayHub).setSocketBufferSize(anyInt());
|
||||
|
||||
when(mockGatewayHub.getSocketBufferSize()).thenAnswer(new Answer<Integer>() {
|
||||
@Override public Integer answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return socketBufferSize;
|
||||
}
|
||||
});
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
startupPolicy = invocation.getArgumentAt(0, String.class);
|
||||
return null;
|
||||
}
|
||||
}).when(mockGatewayHub).setStartupPolicy(anyString());
|
||||
|
||||
when(mockGatewayHub.getStartupPolicy()).thenAnswer(new Answer<String>() {
|
||||
@Override public String answer(final InvocationOnMock invocation) throws Throwable {
|
||||
return startupPolicy;
|
||||
}
|
||||
});
|
||||
|
||||
when(mockGatewayHub.addGateway(anyString())).thenAnswer(new Answer<Gateway>() {
|
||||
@Override public Gateway answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String id = invocation.getArgumentAt(0, String.class);
|
||||
return mockGatewayHub.addGateway(id, Gateway.DEFAULT_CONCURRENCY_LEVEL);
|
||||
}
|
||||
});
|
||||
|
||||
when(mockGatewayHub.addGateway(anyString(), anyInt())).thenAnswer(new Answer<Gateway>() {
|
||||
@Override public Gateway answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String id = invocation.getArgumentAt(0, String.class);
|
||||
Integer concurrencyLevel = invocation.getArgumentAt(1, Integer.class);
|
||||
Gateway mockGateway = new MockGatewayFactory().mockGateway(id, concurrencyLevel);
|
||||
when(mockGateway.getGatewayHubId()).thenReturn(id);
|
||||
gateways.add(mockGateway);
|
||||
return mockGateway;
|
||||
}
|
||||
});
|
||||
|
||||
return mockGatewayHub;
|
||||
}
|
||||
|
||||
private List<String> getGatewayIds(final List<Gateway> gateways) {
|
||||
List<String> gatewayIds = new ArrayList<String>(gateways.size());
|
||||
|
||||
for (Gateway gateway : gateways) {
|
||||
gatewayIds.add(gateway.getId());
|
||||
}
|
||||
|
||||
return gatewayIds;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.springframework.data.gemfire.test;
|
||||
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -46,10 +45,8 @@ 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.Gateway;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
|
||||
import com.gemstone.gemfire.cache.util.GatewayHub;
|
||||
import com.gemstone.gemfire.cache.util.GatewayQueueAttributes;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
@@ -64,9 +61,7 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class StubCache implements Cache {
|
||||
|
||||
protected static final String NOT_IMPLEMENTED = "Not Implemented!";
|
||||
|
||||
private CacheTransactionManager cacheTransactionManager;
|
||||
protected static final String NOT_IMPLEMENTED = "Not Implemented";
|
||||
|
||||
private boolean closed;
|
||||
private boolean copyOnRead;
|
||||
@@ -80,6 +75,8 @@ public class StubCache implements Cache {
|
||||
private int messageSyncInterval;
|
||||
private int searchTimeout;
|
||||
|
||||
private CacheTransactionManager cacheTransactionManager;
|
||||
|
||||
private Context jndiContext;
|
||||
|
||||
private Declarable initializer;
|
||||
@@ -108,7 +105,8 @@ public class StubCache implements Cache {
|
||||
private String name;
|
||||
|
||||
public StubCache(){
|
||||
this.allRegions = new HashMap<String,Region>();
|
||||
allRegions = new HashMap<String,Region>();
|
||||
gatewayHubs = new ArrayList<GatewayHub>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -135,6 +133,7 @@ public class StubCache implements Cache {
|
||||
if (cacheTransactionManager == null) {
|
||||
cacheTransactionManager = new StubCacheTransactionMananger();
|
||||
}
|
||||
|
||||
return cacheTransactionManager;
|
||||
}
|
||||
|
||||
@@ -401,8 +400,11 @@ public class StubCache implements Cache {
|
||||
* @see com.gemstone.gemfire.cache.Cache#addGatewayHub(java.lang.String, int)
|
||||
*/
|
||||
@Override
|
||||
public GatewayHub addGatewayHub(String name, int port) {
|
||||
return mockGatewayHub();
|
||||
public GatewayHub addGatewayHub(final String id, final int port) {
|
||||
GatewayHub gatewayHub = getGatewayHub(id);
|
||||
gatewayHub = (gatewayHub != null ? gatewayHub : new MockGatewayHubFactory().mockGatewayHub(id, port));
|
||||
gatewayHubs.add(gatewayHub);
|
||||
return gatewayHub;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -547,15 +549,21 @@ public class StubCache implements Cache {
|
||||
@Override
|
||||
@Deprecated
|
||||
public GatewayHub getGatewayHub() {
|
||||
return mockGatewayHub();
|
||||
return (gatewayHubs.isEmpty() ? null : gatewayHubs.get(0));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.Cache#getGatewayHub(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public GatewayHub getGatewayHub(String name) {
|
||||
return mockGatewayHub();
|
||||
public GatewayHub getGatewayHub(final String id) {
|
||||
for (GatewayHub gatewayHub : gatewayHubs) {
|
||||
if (gatewayHub.getId().equals(id)) {
|
||||
return gatewayHub;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -769,24 +777,6 @@ public class StubCache implements Cache {
|
||||
return new StubCacheServer();
|
||||
}
|
||||
|
||||
GatewayHub mockGatewayHub() {
|
||||
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 {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return gatewayHub;
|
||||
}
|
||||
|
||||
QueryService mockQueryService() throws RegionNotFoundException, IndexInvalidException, IndexNameConflictException, IndexExistsException, UnsupportedOperationException {
|
||||
QueryService queryService = mock(QueryService.class);
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.test.support;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* The IdentifierSequence class is an Identifier (ID) generator generating unique IDs in sequence.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.lang.System#currentTimeMillis()
|
||||
* @see java.util.concurrent.atomic.AtomicLong
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class IdentifierSequence {
|
||||
|
||||
private static final AtomicLong ID_SEQUENCE = new AtomicLong(System.currentTimeMillis());
|
||||
|
||||
public static long nextId() {
|
||||
return ID_SEQUENCE.incrementAndGet();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.test.support;
|
||||
|
||||
/**
|
||||
* The StackTraceUtils class is a utility class for working with stack trace frames (elements) of the current Thread.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.lang.StackTraceElement
|
||||
* @see java.lang.Thread
|
||||
* @see org.springframework.data.gemfire.test.support.ThreadUtils
|
||||
* @since 1.5.3
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class StackTraceUtils extends ThreadUtils {
|
||||
|
||||
public static StackTraceElement getCaller() {
|
||||
return getCaller(Thread.currentThread());
|
||||
}
|
||||
|
||||
public static StackTraceElement getCaller(final Thread thread) {
|
||||
return thread.getStackTrace()[2];
|
||||
}
|
||||
|
||||
public static String getCallerName(final StackTraceElement element) {
|
||||
return String.format("%1$%s.%2$s", element.getClass().getName(), element.getMethodName());
|
||||
}
|
||||
|
||||
public static String getCallerSimpleName(final StackTraceElement element) {
|
||||
return String.format("%1$%s.%2$s", element.getClass().getSimpleName(), element.getMethodName());
|
||||
}
|
||||
|
||||
public static StackTraceElement getTestCaller() {
|
||||
return getTestCaller(Thread.currentThread());
|
||||
}
|
||||
|
||||
public static StackTraceElement getTestCaller(final Thread thread) {
|
||||
for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
|
||||
if (isTestSuiteClass(stackTraceElement) && isTestCaseMethod(stackTraceElement)) {
|
||||
return stackTraceElement;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isTestCaseMethod(final StackTraceElement element) {
|
||||
boolean result = element.getMethodName().toLowerCase().startsWith("test");
|
||||
|
||||
try {
|
||||
result |= element.getClass().getMethod(element.getMethodName()).isAnnotationPresent(org.junit.Test.class);
|
||||
}
|
||||
catch (NoSuchMethodException ignore) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isTestSuiteClass(final StackTraceElement element) {
|
||||
boolean result = element.getClass().getSimpleName().toLowerCase().endsWith("test");
|
||||
result |= element.getClass().isAssignableFrom(junit.framework.TestCase.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* The ExceptionUtils class is a utility class for working with Throwable, Exception and Error objects.
|
||||
* The ThrowableUtils class is a utility class for working with Throwable, Exception and Error objects.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.lang.Error
|
||||
@@ -31,7 +31,7 @@ import java.io.StringWriter;
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class ThrowableUtils {
|
||||
|
||||
public static String toString(Throwable t) {
|
||||
public static String toString(final Throwable t) {
|
||||
StringWriter writer = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(writer));
|
||||
return writer.toString();
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
@@ -261,7 +260,6 @@ public class GatewayHubFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGatewayQueueWithOverflowNoPersistence() throws Exception {
|
||||
String gatewayHubName = "testGatewayQueueWithOverflowNoPersistence";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user