Completes JIRA improvement SGF-294 allowing GemFire Gateway Receivers to be configured for manual start using the Spring Data GemFire XML namespace. This commit completes the improvement in the 1.4 XSD first in order to backport the feature to the SDG 1.4.2 release.

This commit is contained in:
John Blum
2014-07-07 18:25:33 -07:00
parent 1ed3ad4295
commit db066287b0
12 changed files with 499 additions and 191 deletions

View File

@@ -0,0 +1,84 @@
/*
* 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 javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverNamespaceTest class is a test suite of test cases testing the contract and functionality of
* Gateway Receiver configuration in Spring Data GemFire using the XML namespace and schema (XSD).
*
* @author John Blum
* @see org.junit.Test
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
@SuppressWarnings("unused")
public class GatewayReceiverNamespaceTest {
@Resource(name = "&Default")
private GatewayReceiverFactoryBean defaultFactoryBean;
@Resource(name = "&Auto")
private GatewayReceiverFactoryBean autoGatewayReceiver;
@Resource(name = "&Manual")
private GatewayReceiverFactoryBean manualGatewayReceiver;
@Test
public void testDefault() throws Exception {
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!", defaultFactoryBean);
assertTrue(defaultFactoryBean.isAutoStartup());
GatewayReceiver defaultGatewayReceiver = defaultFactoryBean.getObject();
assertNotNull(defaultGatewayReceiver);
assertEquals("192.168.0.1", defaultGatewayReceiver.getBindAddress());
assertEquals(12345, defaultGatewayReceiver.getStartPort());
assertEquals(54321, defaultGatewayReceiver.getEndPort());
assertEquals(5000, defaultGatewayReceiver.getMaximumTimeBetweenPings());
assertEquals(32768, defaultGatewayReceiver.getSocketBufferSize());
}
@Test
public void testAuto() {
assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!", autoGatewayReceiver);
assertTrue(autoGatewayReceiver.isAutoStartup());
}
@Test
public void testManual() {
assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!", manualGatewayReceiver);
assertFalse(manualGatewayReceiver.isAutoStartup());
}
}

View File

@@ -27,13 +27,15 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
*
*/
public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
private int startPort;
private int endPort;
private String bindAddress;
private List<GatewayTransportFilter> gatewayTransportFilters = new ArrayList<GatewayTransportFilter>();
private int maximumTimeBetweenPings;
private int socketBufferSize;
private int startPort;
private List<GatewayTransportFilter> gatewayTransportFilters = new ArrayList<GatewayTransportFilter>();
private String bindAddress;
private String hostnameForClients;
/* (non-Javadoc)
@@ -115,14 +117,15 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
@Override
public GatewayReceiver create() {
GatewayReceiver gatewayReceiver = mock(GatewayReceiver.class);
when(gatewayReceiver.getBindAddress()).thenReturn(this.bindAddress);
when(gatewayReceiver.getEndPort()).thenReturn(this.endPort);
when(gatewayReceiver.getGatewayTransportFilters()).thenReturn(this.gatewayTransportFilters);
when(gatewayReceiver.getHost()).thenReturn(this.hostnameForClients);
when(gatewayReceiver.getMaximumTimeBetweenPings()).thenReturn(this.maximumTimeBetweenPings);
when(gatewayReceiver.getSocketBufferSize()).thenReturn(this.socketBufferSize);
when(gatewayReceiver.getStartPort()).thenReturn(this.startPort);
when(gatewayReceiver.getHost()).thenReturn(this.hostnameForClients);
return gatewayReceiver;
}

View File

@@ -0,0 +1,94 @@
/*
* 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.wan;
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.io.IOException;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The ManualGatewayReceiverStartIntegrationTest class is a test suite of test cases testing the manual start capability
* of Gateway Receivers when configured with the Spring Data GemFire XML namespace.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class ManualGatewayReceiverStartIntegrationTest {
@Resource(name = "Auto")
private GatewayReceiver autoGatewayReceiver;
@Resource(name = "Manual")
private GatewayReceiver manualGatewayReceiver;
@Test
public void testAutoGatewayReceiver() {
assertNotNull("The 'Auto' GatewayReceiver was not properly configured or initialized!", autoGatewayReceiver);
assertEquals(7070, autoGatewayReceiver.getStartPort());
assertEquals(7700, autoGatewayReceiver.getEndPort());
assertTrue(autoGatewayReceiver.isRunning());
final int gatewayReceiverPort = autoGatewayReceiver.getPort();
assertTrue(gatewayReceiverPort >= autoGatewayReceiver.getStartPort()
&& gatewayReceiverPort <= autoGatewayReceiver.getEndPort());
autoGatewayReceiver.stop();
assertFalse(autoGatewayReceiver.isRunning());
}
@Test
public void testManualGatewayReceiverConfiguration() throws IOException {
assertNotNull("The 'Manual' GatewayReceiver was not properly configured or initialized!", manualGatewayReceiver);
assertFalse(manualGatewayReceiver.isRunning());
assertEquals(6060, manualGatewayReceiver.getStartPort());
assertEquals(6600, manualGatewayReceiver.getEndPort());
manualGatewayReceiver.start();
assertTrue(manualGatewayReceiver.isRunning());
final int gateReceiverPort = manualGatewayReceiver.getPort();
assertTrue(gateReceiverPort >= manualGatewayReceiver.getStartPort()
&& gateReceiverPort <= manualGatewayReceiver.getEndPort());
manualGatewayReceiver.stop();
assertFalse(manualGatewayReceiver.isRunning());
}
}