DATAGEODE-197 - Add integration tests testing the association of Region(s) to GatewaySender ID(s).
This commit is contained in:
@@ -13,51 +13,55 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* The InvalidRegionDataPolicyShortcutsIntegrationTest class is a test suite of test cases testing and setting up
|
||||
* some invalid, or illegal uses of the Region data-policy and/or shortcut XML namespace attributes.
|
||||
* Integration Tests testing and setting up some invalid, or illegal uses of the Region data-policy and shortcut
|
||||
* XML namespace attributes.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.context.support.ClassPathXmlApplicationContext
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class InvalidRegionDataPolicyShortcutsTest {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testInvalidRegionShortcutWithPersistentAttribute() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/data/gemfire/invalid-region-shortcut-with-persistent-attribute.xml");
|
||||
}
|
||||
catch (BeanCreationException expected) {
|
||||
//expected.printStackTrace(System.err);
|
||||
assertTrue(expected.getMessage().contains("Error creating bean with name 'InvalidReplicate'"));
|
||||
|
||||
assertThat(expected).hasMessageContaining("Error creating bean with name 'InvalidReplicate'");
|
||||
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testInvalidUseOfRegionDataPolicyAndShortcut() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/data/gemfire/invalid-use-of-region-datapolicy-and-shortcut.xml");
|
||||
}
|
||||
catch (BeanDefinitionParsingException expected) {
|
||||
//expected.printStackTrace(System.err);
|
||||
assertTrue(expected.getMessage().contains(
|
||||
"Only one of [data-policy, shortcut] may be specified with element 'gfe:partitioned-region'"));
|
||||
|
||||
assertThat(expected).hasMessageContaining(
|
||||
"Only one of [data-policy, shortcut] may be specified with element [gfe:partitioned-region]");
|
||||
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.test.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -28,10 +27,12 @@ import java.net.Socket;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.geode.cache.server.CacheServer;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.gemfire.process.ProcessWrapper;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
@@ -83,6 +84,10 @@ public class ClientServerIntegrationTestsSupport {
|
||||
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-ss")));
|
||||
}
|
||||
|
||||
protected static String block() {
|
||||
return new Scanner(System.in).nextLine();
|
||||
}
|
||||
|
||||
protected static File createDirectory(String pathname) {
|
||||
return createDirectory(new File(pathname));
|
||||
}
|
||||
@@ -141,7 +146,7 @@ public class ClientServerIntegrationTestsSupport {
|
||||
}
|
||||
|
||||
protected static int intValue(Number number) {
|
||||
return (number != null ? number.intValue() : 0);
|
||||
return number != null ? number.intValue() : 0;
|
||||
}
|
||||
|
||||
protected static String logFile() {
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* https://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.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.wan.GatewaySender;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLocator;
|
||||
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
|
||||
import org.springframework.data.gemfire.process.ProcessWrapper;
|
||||
import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration Tests testing the configuration of {@link GatewaySender GatewaySenders} on a cache {@link Region}
|
||||
* by {@literal identifier} using the SDG XML Namespace.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.wan.GatewaySender
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "GatewaySenderXmlConfigurationByIdIntegrationTests-context.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class GatewaySenderXmlConfigurationByIdIntegrationTests extends ClientServerIntegrationTestsSupport {
|
||||
|
||||
private static ProcessWrapper geodeServer;
|
||||
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
@BeforeClass
|
||||
public static void startGeodeServer() throws IOException {
|
||||
|
||||
int port = findAvailablePort();
|
||||
|
||||
System.setProperty("spring.data.gemfire.locator.port", String.valueOf(port));
|
||||
|
||||
geodeServer = run(GeodeServerConfiguration.class, "-Dspring.data.gemfire.locator.port=" + port);
|
||||
waitForServerToStart("localhost", port);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopGeodeServer() {
|
||||
|
||||
stop(geodeServer);
|
||||
|
||||
System.getProperties().stringPropertyNames().stream()
|
||||
.filter(propertyName -> propertyName.startsWith("spring.data.gemfire"))
|
||||
.forEach(System::clearProperty);
|
||||
}
|
||||
|
||||
@Resource(name = "Example")
|
||||
private Region<?, ?> example;
|
||||
|
||||
@Test
|
||||
public void regionGatewaySendersByIdConfiguredCorrectly() {
|
||||
|
||||
assertThat(this.example).isNotNull();
|
||||
assertThat(this.example.getName()).isEqualTo("Example");
|
||||
|
||||
RegionAttributes<?, ?> exampleAttributes = this.example.getAttributes();
|
||||
|
||||
assertThat(exampleAttributes).isNotNull();
|
||||
assertThat(exampleAttributes.getDataPolicy()).isEqualTo(DataPolicy.REPLICATE);
|
||||
assertThat(exampleAttributes.getGatewaySenderIds())
|
||||
.containsExactlyInAnyOrder("TestGatewaySenderOne", "TestGatewaySenderTwo");
|
||||
}
|
||||
|
||||
@EnableLocator
|
||||
@PeerCacheApplication(logLevel = GEMFIRE_LOG_LEVEL)
|
||||
static class GeodeServerConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.err.printf("Locator Port [%s]%n", System.getProperty("spring.data.gemfire.locator.port"));
|
||||
|
||||
runSpringApplication(GeodeServerConfiguration.class, args);
|
||||
block();
|
||||
}
|
||||
|
||||
@Bean("TestGatewaySenderOne")
|
||||
public GatewaySenderFactoryBean gatewaySenderOne(Cache cache) {
|
||||
|
||||
GatewaySenderFactoryBean gatewaySenderOne = new GatewaySenderFactoryBean(cache);
|
||||
|
||||
gatewaySenderOne.setRemoteDistributedSystemId(1);
|
||||
gatewaySenderOne.setManualStart(true);
|
||||
|
||||
return gatewaySenderOne;
|
||||
}
|
||||
|
||||
@Bean("TestGatewaySenderTwo")
|
||||
public GatewaySenderFactoryBean gatewaySenderTwo(Cache cache) {
|
||||
|
||||
GatewaySenderFactoryBean gatewaySenderTwo = new GatewaySenderFactoryBean(cache);
|
||||
|
||||
gatewaySenderTwo.setRemoteDistributedSystemId(1);
|
||||
gatewaySenderTwo.setManualStart(true);
|
||||
|
||||
return gatewaySenderTwo;
|
||||
}
|
||||
|
||||
@Bean("Example")
|
||||
public ReplicatedRegionFactoryBean<Object, Object> exampleRegion(GemFireCache gemfireCache,
|
||||
@Qualifier("TestGatewaySenderOne") GatewaySender gatewaySenderOne,
|
||||
@Qualifier("TestGatewaySenderTwo") GatewaySender gatewaySenderTwo) {
|
||||
|
||||
ReplicatedRegionFactoryBean<Object, Object> exampleRegion = new ReplicatedRegionFactoryBean<>();
|
||||
|
||||
exampleRegion.setCache(gemfireCache);
|
||||
exampleRegion.setGatewaySenders(ArrayUtils.asArray(gatewaySenderOne, gatewaySenderTwo));
|
||||
|
||||
return exampleRegion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
<logger name="ch.qos.logback" level="${logback.log.level:-ERROR}"/>
|
||||
|
||||
<logger name="org.apache.geode" level="${logback.log.level:-ERROR}"/>
|
||||
|
||||
<logger name="org.springframework" level="${logback.log.level:-ERROR}"/>
|
||||
|
||||
<logger name="org.springframework.data.gemfire.config.annotation.support.RegionDataAccessTracingAspect" level="trace" additivity="false">
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:gfe="http://www.springframework.org/schema/geode"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/geode http://www.springframework.org/schema/geode/spring-geode.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">GatewaySenderXmlConfigurationByIdIntegrationTests</prop>
|
||||
<prop key="log-level">error</prop>
|
||||
<prop key="locators">localhost[${spring.data.gemfire.locator.port}]</prop>
|
||||
<prop key="distributed-system-id">1</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<gfe:replicated-region id="Example" persistent="false"
|
||||
gateway-sender-ids="TestGatewaySenderOne, TestGatewaySenderTwo"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user