DATAGEODE-168 - Fix failing tests.

Resolves gh-7.
This commit is contained in:
John Blum
2019-06-14 01:36:02 -07:00
parent 9eb38f1fe4
commit cf6a2e4757
7 changed files with 83 additions and 62 deletions

View File

@@ -58,10 +58,10 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
private Integer socketBufferSize;
private Integer startPort;
@Autowired
@Autowired(required = false)
private GatewayReceiverConfigurer gatewayReceiverConfigurer;
@Autowired
@Autowired(required = false)
private List<GatewayTransportFilter> transportFilters;
private String bindAddress;
@@ -105,8 +105,7 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
GatewayReceiverFactory gatewayReceiverFactory = cache.createGatewayReceiverFactory();
Optional.of(this.gatewayReceiverConfigurer)
.ifPresent(it -> it.configure(getName(),this));
Optional.ofNullable(this.gatewayReceiverConfigurer).ifPresent(it -> it.configure(getName(),this));
if (StringUtils.hasText(this.bindAddress)) {
gatewayReceiverFactory.setBindAddress(this.bindAddress);

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
@@ -22,14 +21,16 @@ import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;
/**
@@ -48,7 +49,7 @@ import org.springframework.util.StringUtils;
* @see org.apache.geode.cache.wan.GatewayReceiver
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@ActiveProfiles("autoStart")
@@ -60,10 +61,11 @@ public class GatewayReceiverAutoStartNamespaceTest {
@Test
public void testAuto() throws Exception {
assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!",
autoGatewayReceiverFactory);
GatewayReceiver autoGatewayReceiver = autoGatewayReceiverFactory.getObject();
assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!",
this.autoGatewayReceiverFactory);
GatewayReceiver autoGatewayReceiver = this.autoGatewayReceiverFactory.getObject();
try {
assertNotNull(autoGatewayReceiver);
@@ -79,5 +81,4 @@ public class GatewayReceiverAutoStartNamespaceTest {
autoGatewayReceiver.stop();
}
}
}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
@@ -22,14 +21,16 @@ import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;
/**
@@ -48,7 +49,7 @@ import org.springframework.util.StringUtils;
* @see org.apache.geode.cache.wan.GatewayReceiver
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@ActiveProfiles("defaultStart")
@@ -60,10 +61,11 @@ public class GatewayReceiverDefaultStartNamespaceTest {
@Test
public void testDefault() throws Exception {
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!",
defaultGatewayReceiverFactory);
GatewayReceiver defaultGatewayReceiver = defaultGatewayReceiverFactory.getObject();
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!",
this.defaultGatewayReceiverFactory);
GatewayReceiver defaultGatewayReceiver = this.defaultGatewayReceiverFactory.getObject();
try {
assertNotNull(defaultGatewayReceiver);
@@ -79,5 +81,4 @@ public class GatewayReceiverDefaultStartNamespaceTest {
defaultGatewayReceiver.stop();
}
}
}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
@@ -22,14 +21,16 @@ import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* The GatewayReceiverManualStartNamespaceTest class is a test suite of test cases testing the contract
@@ -47,7 +48,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @see org.apache.geode.cache.wan.GatewayReceiver
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@ActiveProfiles("manualStart")
@@ -59,10 +60,11 @@ public class GatewayReceiverManualStartNamespaceTest {
@Test
public void testManual() throws Exception {
assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!",
manualGatewayReceiverFactory);
GatewayReceiver manualGatewayReceiver = manualGatewayReceiverFactory.getObject();
assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!",
this.manualGatewayReceiverFactory);
GatewayReceiver manualGatewayReceiver = this.manualGatewayReceiverFactory.getObject();
assertNotNull(manualGatewayReceiver);
assertEquals("192.168.0.1", manualGatewayReceiver.getBindAddress());

View File

@@ -28,6 +28,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.junit.AfterClass;
import org.junit.Test;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.asyncqueue.AsyncEvent;
import org.apache.geode.cache.asyncqueue.AsyncEventListener;
@@ -38,11 +41,10 @@ import org.apache.geode.cache.wan.GatewayReceiver;
import org.apache.geode.cache.wan.GatewaySender;
import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.AfterClass;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
import org.springframework.data.gemfire.PeerRegionFactoryBean;
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
@@ -64,7 +66,9 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
@AfterClass
@SuppressWarnings("all")
public static void tearDown() {
for (String name : new File(".").list(new FilenameFilter() {
@Override
public boolean accept(File file, String filename) {
return filename.startsWith("BACKUP");
@@ -95,7 +99,9 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
@Test
public void testAsyncEventQueue() {
AsyncEventQueue asyncEventQueue = applicationContext.getBean("async-event-queue", AsyncEventQueue.class);
AsyncEventQueue asyncEventQueue =
this.applicationContext.getBean("async-event-queue", AsyncEventQueue.class);
assertNotNull(asyncEventQueue);
assertTrue(asyncEventQueue.isBatchConflationEnabled());
@@ -111,7 +117,9 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
@Test
public void testGatewaySender() throws Exception {
GatewaySenderFactoryBean gatewaySenderFactoryBean = applicationContext.getBean("&gateway-sender", GatewaySenderFactoryBean.class);
GatewaySenderFactoryBean gatewaySenderFactoryBean =
this.applicationContext.getBean("&gateway-sender", GatewaySenderFactoryBean.class);
assertNotNull(gatewaySenderFactoryBean);
assertNotNull(TestUtils.readField("cache", gatewaySenderFactoryBean));
@@ -139,7 +147,8 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
@Test
@SuppressWarnings("rawtypes")
public void testInnerGatewaySender() throws Exception {
Region<?, ?> region = applicationContext.getBean("region-inner-gateway-sender", Region.class);
Region<?, ?> region = this.applicationContext.getBean("region-inner-gateway-sender", Region.class);
assertNotNull(region.getAttributes().getGatewaySenderIds());
assertEquals(2, region.getAttributes().getGatewaySenderIds().size());
@@ -186,8 +195,10 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
@Test
public void testGatewaySenderWithEventTransportFilterRefs() throws Exception {
GatewaySenderFactoryBean gatewaySenderFactoryBean = applicationContext.getBean("&gateway-sender-with-event-transport-filter-refs",
GatewaySenderFactoryBean.class);
GatewaySenderFactoryBean gatewaySenderFactoryBean =
this.applicationContext.getBean("&gateway-sender-with-event-transport-filter-refs",
GatewaySenderFactoryBean.class);
assertNotNull(gatewaySenderFactoryBean);
assertNotNull(TestUtils.readField("cache", gatewaySenderFactoryBean));
@@ -214,7 +225,8 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
@Test
public void testGatewayReceiver() {
GatewayReceiver gatewayReceiver = applicationContext.getBean("gateway-receiver", GatewayReceiver.class);
GatewayReceiver gatewayReceiver = this.applicationContext.getBean("gateway-receiver", GatewayReceiver.class);
assertNotNull(gatewayReceiver);
assertEquals("192.168.0.1", gatewayReceiver.getBindAddress());
@@ -228,12 +240,10 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
public static class TestEventFilter implements GatewayEventFilter {
@Override
public void close() {
}
public void close() { }
@Override
public void afterAcknowledgement(GatewayQueueEvent arg0) {
}
public void afterAcknowledgement(GatewayQueueEvent arg0) { }
@Override
public boolean beforeEnqueue(GatewayQueueEvent arg0) {
@@ -249,8 +259,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
public static class TestTransportFilter implements GatewayTransportFilter {
@Override
public void close() {
}
public void close() { }
@Override
public InputStream getInputStream(InputStream arg0) {
@@ -267,8 +276,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
public static class TestAsyncEventListener implements AsyncEventListener {
@Override
public void close() {
}
public void close() { }
@Override
public boolean processEvents(List<AsyncEvent> arg0) {

View File

@@ -13,22 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.wan;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.wan.GatewayReceiverFactory;
import org.apache.geode.cache.wan.GatewayTransportFilter;
import org.junit.Test;
/**
* The GatewayReceiverFactoryBeanTest class is a test suite of test cases testing the contract and functionality
@@ -43,9 +43,14 @@ public class GatewayReceiverFactoryBeanTest {
@Test
public void testDoInit() throws Exception {
Cache mockCache = mock(Cache.class, "testDoInit.Cache");
GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class, "testDoInit.GatewayReceiverFactory");
GatewayTransportFilter mockGatewayTransportFilter = mock(GatewayTransportFilter.class, "testDoInit.GatewayTransportFilter");
GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class,
"testDoInit.GatewayReceiverFactory");
GatewayTransportFilter mockGatewayTransportFilter = mock(GatewayTransportFilter.class,
"testDoInit.GatewayTransportFilter");
when(mockCache.createGatewayReceiverFactory()).thenReturn(mockGatewayReceiverFactory);
@@ -59,7 +64,7 @@ public class GatewayReceiverFactoryBeanTest {
factoryBean.setMaximumTimeBetweenPings(5000);
factoryBean.setName("testDoInit");
factoryBean.setSocketBufferSize(16384);
factoryBean.setTransportFilters(Arrays.asList(mockGatewayTransportFilter));
factoryBean.setTransportFilters(Collections.singletonList(mockGatewayTransportFilter));
factoryBean.afterPropertiesSet();
verify(mockGatewayReceiverFactory).setBindAddress(eq("10.224.112.77"));
@@ -75,8 +80,11 @@ public class GatewayReceiverFactoryBeanTest {
@Test(expected = IllegalArgumentException.class)
public void testDoInitWithIllegalStartEndPorts() throws Exception {
try {
Cache mockCache = mock(Cache.class, "testDoInitWithIllegalStartEndPorts.Cache");
GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class,
"testDoInitWithIllegalStartEndPorts.GatewayReceiverFactory");
@@ -94,5 +102,4 @@ public class GatewayReceiverFactoryBeanTest {
throw expected;
}
}
}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.wan;
import static org.junit.Assert.assertEquals;
@@ -25,12 +24,14 @@ import java.io.IOException;
import javax.annotation.Resource;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* The ManualGatewayReceiverStartIntegrationTest class is a test suite of test cases testing the manual start capability
@@ -44,7 +45,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
@SuppressWarnings("unused")
public class ManualGatewayReceiverStartIntegrationTest {
@@ -55,19 +56,21 @@ public class ManualGatewayReceiverStartIntegrationTest {
@Resource(name = "Manual")
private GatewayReceiver manualGatewayReceiver;
protected void assertGreaterThanEqualToLessThanEqualTo(final String message,
final int actualValue, final int lowerBound, final int upperBound) {
protected void assertGreaterThanEqualToLessThanEqualTo(String message,
int actualValue, int lowerBound, int upperBound) {
assertTrue(message, actualValue >= lowerBound && actualValue <= upperBound);
}
@Test
public void testAutoGatewayReceiver() {
assertNotNull("The 'Auto' GatewayReceiver was not properly configured or initialized!", autoGatewayReceiver);
assertTrue(autoGatewayReceiver.isRunning());
assertEquals(7070, autoGatewayReceiver.getStartPort());
assertEquals(7700, autoGatewayReceiver.getEndPort());
final int gatewayReceiverPort = autoGatewayReceiver.getPort();
int gatewayReceiverPort = autoGatewayReceiver.getPort();
assertGreaterThanEqualToLessThanEqualTo(String.format(
"GatewayReceiver 'port' (%1$d) was not greater than equal to (%2$d) and less than equal to (%3$d)!",
@@ -81,6 +84,7 @@ public class ManualGatewayReceiverStartIntegrationTest {
@Test
public void testManualGatewayReceiverConfiguration() throws IOException {
assertNotNull("The 'Manual' GatewayReceiver was not properly configured or initialized!", manualGatewayReceiver);
assertFalse(manualGatewayReceiver.isRunning());
assertEquals(6060, manualGatewayReceiver.getStartPort());
@@ -90,7 +94,7 @@ public class ManualGatewayReceiverStartIntegrationTest {
assertTrue(manualGatewayReceiver.isRunning());
final int gatewayReceiverPort = manualGatewayReceiver.getPort();
int gatewayReceiverPort = manualGatewayReceiver.getPort();
assertGreaterThanEqualToLessThanEqualTo(String.format(
"GatewayReceiver 'port' (%1$d) was not greater than equal to (%2$d) and less than equal to (%3$d)!",
@@ -101,5 +105,4 @@ public class ManualGatewayReceiverStartIntegrationTest {
assertFalse(manualGatewayReceiver.isRunning());
}
}