DATAGEODE-6 - Fix up Lucene Integration tests and Region namespace test to improve reliability.
This commit is contained in:
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -26,33 +27,34 @@ import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* The InvalidRegionExpirationAttributesNamespaceTest class is a test suite of test cases testing the proper syntax
|
||||
* of declaring "custom" expiration attributes on a Region.
|
||||
* Unit test testing the proper syntax for declaring "custom" expiration attributes on a {@link Region}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
* @see org.springframework.context.support.GenericXmlApplicationContext
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor
|
||||
* @see org.apache.geode.cache.ExpirationAttributes
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class InvalidRegionExpirationAttributesNamespaceTest {
|
||||
|
||||
protected String contextConfigLocation() {
|
||||
private String contextConfigLocation() {
|
||||
return getClass().getName().replaceAll("\\.", "/").concat("-context.xml");
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext createApplicationContext() {
|
||||
private ConfigurableApplicationContext createApplicationContext() {
|
||||
return new GenericXmlApplicationContext();
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext configureContext(ConfigurableApplicationContext applicationContext) {
|
||||
private ConfigurableApplicationContext configureContext(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor());
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext initializeApplicationContext(ConfigurableApplicationContext applicationContext) {
|
||||
assertTrue(applicationContext instanceof GenericXmlApplicationContext);
|
||||
private ConfigurableApplicationContext initializeApplicationContext(ConfigurableApplicationContext applicationContext) {
|
||||
assertThat(applicationContext).isInstanceOf(GenericXmlApplicationContext.class);
|
||||
((GenericXmlApplicationContext) applicationContext).load(contextConfigLocation());
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.refresh();
|
||||
@@ -65,10 +67,8 @@ public class InvalidRegionExpirationAttributesNamespaceTest {
|
||||
initializeApplicationContext(configureContext(createApplicationContext()));
|
||||
}
|
||||
catch (XmlBeanDefinitionStoreException expected) {
|
||||
assertTrue(expected.getCause() instanceof SAXParseException);
|
||||
assertTrue(expected.getMessage().contains("Invalid content was found starting with element 'bean'"));
|
||||
assertThat(expected).hasCauseInstanceOf(SAXParseException.class);
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.time.Month;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -33,6 +34,7 @@ import javax.annotation.Resource;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.lucene.LuceneIndex;
|
||||
import org.apache.geode.cache.lucene.LuceneService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -80,18 +82,15 @@ public class LuceneOperationsIntegrationTests {
|
||||
private Person pieDoe;
|
||||
private Person sourDoe;
|
||||
|
||||
@Autowired
|
||||
private LuceneService luceneService;
|
||||
|
||||
@Autowired
|
||||
private ProjectingLuceneOperations template;
|
||||
|
||||
@Resource(name = "People")
|
||||
private Region<Long, Person> people;
|
||||
|
||||
protected Person save(Person person) {
|
||||
person.setId(IDENTIFIER.incrementAndGet());
|
||||
people.put(person.getId(), person);
|
||||
return person;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
jonDoe = save(Person.newPerson(LocalDate.of(1969, Month.JULY, 4), "Jon", "Doe").with("Master of Science"));
|
||||
@@ -101,13 +100,30 @@ public class LuceneOperationsIntegrationTests {
|
||||
hoDoe = save(Person.newPerson(LocalDate.of(1984, Month.NOVEMBER, 11), "Ho", "Doe").with("Doctor of Math"));
|
||||
pieDoe = save(Person.newPerson(LocalDate.of(1996, Month.JUNE, 4), "Pie", "Doe").with("Master of Astronomy"));
|
||||
sourDoe = save(Person.newPerson(LocalDate.of(1999, Month.DECEMBER, 1), "Sour", "Doe").with("Bachelor of Art"));
|
||||
|
||||
flushLuceneIndex();
|
||||
}
|
||||
|
||||
protected List<String> asNames(List<? extends Nameable> nameables) {
|
||||
protected Person save(Person person) {
|
||||
person.setId(IDENTIFIER.incrementAndGet());
|
||||
people.put(person.getId(), person);
|
||||
return person;
|
||||
}
|
||||
|
||||
protected void flushLuceneIndex() {
|
||||
try {
|
||||
this.luceneService.waitUntilFlushed("PersonTitleIndex", "/People",
|
||||
15L, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> asNames(List<? extends Nameable> nameables) {
|
||||
return nameables.stream().map(Nameable::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected List<User> asUsers(Person... people) {
|
||||
private List<User> asUsers(Person... people) {
|
||||
return Arrays.stream(people).map(User::from).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -118,7 +134,6 @@ public class LuceneOperationsIntegrationTests {
|
||||
assertThat(doctorDoes).isNotNull();
|
||||
assertThat(doctorDoes).hasSize(3);
|
||||
assertThat(doctorDoes).contains(janeDoe, froDoe, hoDoe);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,12 +163,20 @@ public class LuceneOperationsIntegrationTests {
|
||||
return peopleRegion;
|
||||
}
|
||||
|
||||
@Bean
|
||||
LuceneServiceFactoryBean luceneService(GemFireCache gemFireCache) {
|
||||
LuceneServiceFactoryBean luceneService = new LuceneServiceFactoryBean();
|
||||
luceneService.setCache(gemFireCache);
|
||||
return luceneService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
LuceneIndexFactoryBean personTitleIndex(GemFireCache gemFireCache) {
|
||||
LuceneIndexFactoryBean luceneIndex = new LuceneIndexFactoryBean();
|
||||
|
||||
luceneIndex.setCache(gemFireCache);
|
||||
luceneIndex.setFields("title");
|
||||
luceneIndex.setIndexName("PersonTitleIndex");
|
||||
luceneIndex.setRegionPath("/People");
|
||||
|
||||
return luceneIndex;
|
||||
|
||||
Reference in New Issue
Block a user