SGF-864 - Fix unreliable tests.
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static java.util.stream.StreamSupport.stream;
|
||||
@@ -40,6 +39,7 @@ import org.apache.geode.cache.lucene.LuceneSerializer;
|
||||
import org.apache.geode.cache.lucene.LuceneService;
|
||||
import org.apache.geode.cache.lucene.LuceneServiceProvider;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -423,8 +423,12 @@ public class LuceneIndexFactoryBean extends AbstractFactoryBeanSupport<LuceneInd
|
||||
*/
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
|
||||
super.setBeanName(name);
|
||||
setIndexName(name);
|
||||
|
||||
if (!StringUtils.hasText(this.indexName)) {
|
||||
setIndexName(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -142,6 +142,8 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr
|
||||
List<String> arguments = new ArrayList<String>();
|
||||
|
||||
arguments.add("-Dgemfire.name=" + locatorName);
|
||||
arguments.add("-Dlog4j.geode.log.level=info");
|
||||
arguments.add("-Dlogback.log.level=info");
|
||||
arguments.add("-Dspring.data.gemfire.enable-cluster-configuration=true");
|
||||
arguments.add("-Dspring.data.gemfire.load-cluster-configuration=true");
|
||||
arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL));
|
||||
@@ -259,6 +261,7 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr
|
||||
public void localConfigurationTest() {
|
||||
|
||||
try {
|
||||
|
||||
newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml"));
|
||||
|
||||
fail("Loading the 'cacheUsingLocalOnlyConfigurationIntegrationTest.xml' Spring ApplicationContext"
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -29,20 +28,22 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.lucene.LuceneService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -71,62 +72,33 @@ public class LuceneOperationsIntegrationTests {
|
||||
|
||||
private static final AtomicLong IDENTIFIER = new AtomicLong(0L);
|
||||
|
||||
protected static final String LOG_LEVEL = "error";
|
||||
protected static final String GEMFIRE_LOG_LEVEL = "none";
|
||||
|
||||
private Person jonDoe;
|
||||
private Person janeDoe;
|
||||
private Person cookieDoe;
|
||||
private Person froDoe;
|
||||
private Person hoDoe;
|
||||
private Person pieDoe;
|
||||
private Person sourDoe;
|
||||
private static Person jonDoe = Person.newPerson(LocalDate.of(1969, Month.JULY, 4), "Jon", "Doe").with("Master of Science");
|
||||
private static Person janeDoe = Person.newPerson(LocalDate.of(1969, Month.AUGUST, 16), "Jane", "Doe").with("Doctor of Astrophysics");
|
||||
private static Person cookieDoe = Person.newPerson(LocalDate.of(1991, Month.APRIL, 2), "Cookie", "Doe").with("Bachelor of Physics");
|
||||
private static Person froDoe = Person.newPerson(LocalDate.of(1988, Month.MAY, 25), "Fro", "Doe").with("Doctor of Computer Science");
|
||||
private static Person hoDoe = Person.newPerson(LocalDate.of(1984, Month.NOVEMBER, 11), "Ho", "Doe").with("Doctor of Math");
|
||||
private static Person pieDoe = Person.newPerson(LocalDate.of(1996, Month.JUNE, 4), "Pie", "Doe").with("Master of Astronomy");
|
||||
private static Person sourDoe = Person.newPerson(LocalDate.of(1999, Month.DECEMBER, 1), "Sour", "Doe").with("Bachelor of Art");
|
||||
|
||||
@Autowired
|
||||
private LuceneService luceneService;
|
||||
private static List<String> asNames(List<? extends Nameable> nameables) {
|
||||
|
||||
return nameables.stream()
|
||||
.map(Nameable::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<User> asUsers(Person... people) {
|
||||
|
||||
return Arrays.stream(people)
|
||||
.map(User::from)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ProjectingLuceneOperations template;
|
||||
|
||||
@Resource(name = "People")
|
||||
private Region<Long, Person> people;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
jonDoe = save(Person.newPerson(LocalDate.of(1969, Month.JULY, 4), "Jon", "Doe").with("Master of Science"));
|
||||
janeDoe = save(Person.newPerson(LocalDate.of(1969, Month.AUGUST, 16), "Jane", "Doe").with("Doctor of Astrophysics"));
|
||||
cookieDoe = save(Person.newPerson(LocalDate.of(1991, Month.APRIL, 2), "Cookie", "Doe").with("Bachelor of Physics"));
|
||||
froDoe = save(Person.newPerson(LocalDate.of(1988, Month.MAY, 25), "Fro", "Doe").with("Doctor of Computer Science"));
|
||||
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();
|
||||
}
|
||||
|
||||
private Person save(Person person) {
|
||||
person.setId(IDENTIFIER.incrementAndGet());
|
||||
people.put(person.getId(), person);
|
||||
return person;
|
||||
}
|
||||
|
||||
private 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());
|
||||
}
|
||||
|
||||
private List<User> asUsers(Person... people) {
|
||||
return Arrays.stream(people).map(User::from).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsDoctorDoesAsTypePersonSuccessfully() {
|
||||
|
||||
@@ -150,7 +122,7 @@ public class LuceneOperationsIntegrationTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@PeerCacheApplication(name = "LuceneOperationsIntegrationTests", logLevel = LOG_LEVEL)
|
||||
@PeerCacheApplication(name = "LuceneOperationsIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL)
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean(name = "People")
|
||||
@@ -192,7 +164,34 @@ public class LuceneOperationsIntegrationTests {
|
||||
@Bean
|
||||
@DependsOn("personTitleIndex")
|
||||
ProjectingLuceneOperations luceneTemplate() {
|
||||
return new ProjectingLuceneTemplate("personTitleIndex", "/People");
|
||||
return new ProjectingLuceneTemplate("PersonTitleIndex", "/People");
|
||||
}
|
||||
|
||||
@EventListener(ContextRefreshedEvent.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadPeople(ContextRefreshedEvent event) {
|
||||
|
||||
Region<Long, Person> people = event.getApplicationContext().getBean("People", Region.class);
|
||||
|
||||
Arrays.asList(jonDoe, janeDoe, cookieDoe, froDoe, hoDoe, pieDoe, sourDoe)
|
||||
.forEach(person -> {
|
||||
person.setId(IDENTIFIER.incrementAndGet());
|
||||
people.put(person.getId(), person);
|
||||
});
|
||||
|
||||
LuceneService luceneService =
|
||||
event.getApplicationContext().getBean("luceneService", LuceneService.class);
|
||||
|
||||
boolean flushed = SpringUtils.safeGetValue(() -> {
|
||||
try {
|
||||
return luceneService.waitUntilFlushed("PersonTitleIndex", "/People", 15L, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(flushed).describedAs("LuceneIndex not flushed!").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.snapshot;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
@@ -31,12 +30,14 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.snapshot.SnapshotFilter;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.snapshot.SnapshotFilter;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.gemfire.repository.sample.Person;
|
||||
@@ -143,8 +144,9 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest {
|
||||
protected void wait(int seconds, int expectedDoeSize, int expectedEveryoneSize, int expectedHandySize) {
|
||||
|
||||
ThreadUtils.timedWait(TimeUnit.SECONDS.toMillis(seconds), 500,
|
||||
() -> (doe.size() < expectedDoeSize && everyoneElse.size() <
|
||||
expectedEveryoneSize && handy.size() < expectedHandySize));
|
||||
() -> doe.size() < expectedDoeSize
|
||||
|| everyoneElse.size() < expectedEveryoneSize
|
||||
|| handy.size() < expectedHandySize);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +180,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest {
|
||||
|
||||
eventPublisher.publishEvent(event);
|
||||
|
||||
wait(10, 5, 4, 3);
|
||||
wait(5, 5, 4, 3);
|
||||
|
||||
assertPeople(doe, jonDoe, janeDoe, cookieDoe, pieDoe, sourDoe);
|
||||
assertPeople(everyoneElse, jackBlack, joeDirt, jackHill, jillHill);
|
||||
@@ -239,7 +241,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest {
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
private static final Map<File, Long> snapshotFileLastModifiedMap = new ConcurrentHashMap<File, Long>(2);
|
||||
private static final Map<File, Long> snapshotFileLastModifiedMap = new ConcurrentHashMap<>(2);
|
||||
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.snapshot;
|
||||
|
||||
import static org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat;
|
||||
@@ -30,7 +29,6 @@ import static org.junit.Assume.assumeThat;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -49,6 +47,13 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.Region;
|
||||
@@ -56,12 +61,7 @@ import org.apache.geode.cache.snapshot.CacheSnapshotService;
|
||||
import org.apache.geode.cache.snapshot.RegionSnapshotService;
|
||||
import org.apache.geode.cache.snapshot.SnapshotFilter;
|
||||
import org.apache.geode.cache.snapshot.SnapshotOptions;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent;
|
||||
import org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent;
|
||||
@@ -149,7 +149,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupBeforeClass() throws Exception {
|
||||
public static void setupBeforeClass() {
|
||||
snapshotDat = mockFile("snapshot.dat");
|
||||
}
|
||||
|
||||
@@ -190,12 +190,14 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void nullSafeIsFileWithFile() {
|
||||
|
||||
assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(FileSystemUtils.JAVA_EXE),
|
||||
is(FileSystemUtils.JAVA_EXE.isFile()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSafeIsFileWithNonFiles() {
|
||||
|
||||
assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File("/path/to/non-existing/file.ext")), is(false));
|
||||
assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File(System.getProperty("user.dir"))), is(false));
|
||||
}
|
||||
@@ -224,6 +226,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
public void setAndGetCacheSuccessfully() {
|
||||
|
||||
Cache mockCache = mock(Cache.class, "MockCache");
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean();
|
||||
|
||||
factoryBean.setCache(mockCache);
|
||||
@@ -325,7 +328,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
"MockSnapshotServiceAdapter");
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override protected SnapshotServiceAdapter create() {
|
||||
|
||||
@Override
|
||||
protected SnapshotServiceAdapter create() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -345,7 +350,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
"MockSnapshotServiceAdapter");
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override protected SnapshotServiceAdapter create() {
|
||||
|
||||
@Override
|
||||
protected SnapshotServiceAdapter create() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -362,6 +369,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
public void createCacheSnapshotService() {
|
||||
|
||||
Cache mockCache = mock(Cache.class, "MockCache");
|
||||
|
||||
CacheSnapshotService mockCacheSnapshotService = mock(CacheSnapshotService.class, "MockCacheSnapshotService");
|
||||
|
||||
when(mockCache.getSnapshotService()).thenReturn(mockCacheSnapshotService);
|
||||
@@ -381,6 +389,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
public void createRegionSnapshotService() {
|
||||
|
||||
Region mockRegion = mock(Region.class, "MockRegion");
|
||||
|
||||
RegionSnapshotService mockRegionSnapshotService = mock(RegionSnapshotService.class, "MockRegionSnapshotService");
|
||||
|
||||
when(mockRegion.getSnapshotService()).thenReturn(mockRegionSnapshotService);
|
||||
@@ -425,7 +434,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
"MockSnapshotServiceAdapter");
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override public SnapshotServiceAdapter getObject() throws Exception {
|
||||
|
||||
@Override
|
||||
public SnapshotServiceAdapter getObject() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -439,7 +450,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onApplicationEventWhenMatchUsingEventSnapshotMetadataPerformsExport() throws Exception {
|
||||
public void onApplicationEventWhenMatchUsingEventSnapshotMetadataPerformsExport() {
|
||||
|
||||
Region mockRegion = mock(Region.class, "MockRegion");
|
||||
|
||||
@@ -456,7 +467,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(toArray(eventSnapshotMetadata));
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override public SnapshotServiceAdapter getObject() throws Exception {
|
||||
|
||||
@Override
|
||||
public SnapshotServiceAdapter getObject() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -476,7 +489,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onApplicationEventWhenMatchUsingFactorySnapshotMetadataPerformsImport() throws Exception {
|
||||
public void onApplicationEventWhenMatchUsingFactorySnapshotMetadataPerformsImport() {
|
||||
|
||||
SnapshotApplicationEvent mockSnapshotEvent = mock(ImportSnapshotApplicationEvent.class,
|
||||
"MockImportSnapshotApplicationEvent");
|
||||
@@ -491,7 +504,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null);
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override public SnapshotServiceAdapter getObject() throws Exception {
|
||||
|
||||
@Override
|
||||
public SnapshotServiceAdapter getObject() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -510,7 +525,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onApplicationEventWhenNoMatchDoesNotPerformExport() throws Exception {
|
||||
public void onApplicationEventWhenNoMatchDoesNotPerformExport() {
|
||||
|
||||
SnapshotApplicationEvent mockSnapshotEvent = mock(ExportSnapshotApplicationEvent.class,
|
||||
"MockExportSnapshotApplicationEvent");
|
||||
@@ -523,7 +538,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
mock(SnapshotServiceAdapter.class, "MockSnapshotServiceAdapter");
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override public SnapshotServiceAdapter getObject() throws Exception {
|
||||
|
||||
@Override
|
||||
public SnapshotServiceAdapter getObject() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -536,13 +553,13 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
factoryBean.onApplicationEvent(mockSnapshotEvent);
|
||||
|
||||
verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent();
|
||||
verify(mockSnapshotEvent, times(1)).matches(isNull(Region.class));
|
||||
verify(mockSnapshotEvent, times(1)).matches(ArgumentMatchers.<Region>isNull());
|
||||
verify(mockSnapshotEvent, never()).getSnapshotMetadata();
|
||||
verify(mockSnapshotService, never()).doExport(any(SnapshotMetadata.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onApplicationEventWhenNoMatchDoesNotPerformImport() throws Exception {
|
||||
public void onApplicationEventWhenNoMatchDoesNotPerformImport() {
|
||||
|
||||
Region mockRegion = mock(Region.class, "MockRegion");
|
||||
|
||||
@@ -557,7 +574,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null);
|
||||
|
||||
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
|
||||
@Override public SnapshotServiceAdapter getObject() throws Exception {
|
||||
|
||||
@Override
|
||||
public SnapshotServiceAdapter getObject() {
|
||||
return mockSnapshotService;
|
||||
}
|
||||
};
|
||||
@@ -668,7 +687,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
assertThat(factoryBean.isMatch(mockSnapshotEvent), is(false));
|
||||
|
||||
verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent();
|
||||
verify(mockSnapshotEvent, times(1)).matches(isNull(Region.class));
|
||||
verify(mockSnapshotEvent, times(1)).matches(ArgumentMatchers.<Region>isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -961,7 +980,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
when(mockSnapshotOptions.setParallelMode(anyBoolean())).thenReturn(mockSnapshotOptions);
|
||||
|
||||
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
|
||||
@Override public SnapshotOptions<Object, Object> createOptions() {
|
||||
|
||||
@Override
|
||||
public SnapshotOptions<Object, Object> createOptions() {
|
||||
return mockSnapshotOptions;
|
||||
}
|
||||
};
|
||||
@@ -1010,7 +1031,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
when(mockLog.isDebugEnabled()).thenReturn(true);
|
||||
|
||||
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
|
||||
@Override Log createLog() {
|
||||
|
||||
@Override
|
||||
Log createLog() {
|
||||
return mockLog;
|
||||
}
|
||||
};
|
||||
@@ -1031,7 +1054,9 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
when(mockLog.isDebugEnabled()).thenReturn(false);
|
||||
|
||||
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
|
||||
@Override Log createLog() {
|
||||
|
||||
@Override
|
||||
Log createLog() {
|
||||
return mockLog;
|
||||
}
|
||||
};
|
||||
@@ -1073,11 +1098,13 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.load(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE);
|
||||
}
|
||||
catch (ImportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to load snapshots from directory [%1$s] in format [GEMFIRE]",
|
||||
FileSystemUtils.WORKING_DIRECTORY))));
|
||||
assertThat(expected.getCause(), is(instanceOf(IOException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1105,11 +1132,13 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat);
|
||||
}
|
||||
catch (ImportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to load snapshots [%1$s] in format [GEMFIRE] using options [%2$s]",
|
||||
Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions))));
|
||||
assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1134,11 +1163,13 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.save(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE);
|
||||
}
|
||||
catch (ExportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to save snapshots to directory [%1$s] in format [GEMFIRE]",
|
||||
FileSystemUtils.WORKING_DIRECTORY))));
|
||||
assertThat(expected.getCause(), is(instanceOf(IOException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1166,11 +1197,13 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.save(FileSystemUtils.USER_HOME, SnapshotFormat.GEMFIRE, mockSnapshotOptions);
|
||||
}
|
||||
catch (ExportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to save snapshots to directory [%1$s] in format [GEMFIRE] using options [%2$s]",
|
||||
FileSystemUtils.USER_HOME, mockSnapshotOptions))));
|
||||
assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1196,10 +1229,12 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.load(snapshotDat, SnapshotFormat.GEMFIRE);
|
||||
}
|
||||
catch (ImportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to load snapshot from file [%1$s] in format [GEMFIRE]", snapshotDat))));
|
||||
assertThat(expected.getCause(), is(instanceOf(IOException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1226,11 +1261,13 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat);
|
||||
}
|
||||
catch (ImportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to load snapshots [%1$s] in format [GEMFIRE] using options [%2$s]",
|
||||
Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions))));
|
||||
assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1256,10 +1293,12 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
adapter.save(snapshotDat, SnapshotFormat.GEMFIRE);
|
||||
}
|
||||
catch (ExportSnapshotException expected) {
|
||||
|
||||
assertThat(expected.getMessage(), is(equalTo(String.format(
|
||||
"Failed to save snapshot to file [%1$s] in format [GEMFIRE]", snapshotDat))));
|
||||
assertThat(expected.getCause(), is(instanceOf(IOException.class)));
|
||||
assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
@@ -1313,7 +1352,7 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSnapshotMetadataWithFileGemFireFormatAndNullFilter() throws Exception {
|
||||
public void createSnapshotMetadataWithFileGemFireFormatAndNullFilter() {
|
||||
|
||||
SnapshotMetadata snapshotMetadata = new SnapshotMetadata(snapshotDat, SnapshotFormat.GEMFIRE, null);
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.test.support;
|
||||
|
||||
/**
|
||||
@@ -49,6 +48,7 @@ public abstract class StackTraceUtils extends ThreadUtils {
|
||||
}
|
||||
|
||||
public static StackTraceElement getTestCaller(final Thread thread) {
|
||||
|
||||
for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
|
||||
if (isTestSuiteClass(stackTraceElement) && isTestCaseMethod(stackTraceElement)) {
|
||||
return stackTraceElement;
|
||||
@@ -59,6 +59,7 @@ public abstract class StackTraceUtils extends ThreadUtils {
|
||||
}
|
||||
|
||||
private static boolean isTestCaseMethod(final StackTraceElement element) {
|
||||
|
||||
boolean result = element.getMethodName().toLowerCase().startsWith("test");
|
||||
|
||||
try {
|
||||
@@ -71,9 +72,11 @@ public abstract class StackTraceUtils extends ThreadUtils {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* 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.TimeUnit;
|
||||
@@ -30,6 +29,7 @@ public abstract class ThreadUtils {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public static boolean sleep(long milliseconds) {
|
||||
|
||||
try {
|
||||
Thread.sleep(milliseconds);
|
||||
return true;
|
||||
@@ -45,11 +45,7 @@ public abstract class ThreadUtils {
|
||||
}
|
||||
|
||||
public static boolean timedWait(long duration, long interval) {
|
||||
return timedWait(duration, interval, new WaitCondition() {
|
||||
@Override public boolean waiting() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return timedWait(duration, interval, () -> true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.test.support;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -31,10 +30,12 @@ import java.io.StringWriter;
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class ThrowableUtils {
|
||||
|
||||
public static String toString(final Throwable t) {
|
||||
public static String toString(Throwable cause) {
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(writer));
|
||||
|
||||
cause.printStackTrace(new PrintWriter(writer));
|
||||
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
<Null name="nop"/>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="org.apache.geode" level="error"/>
|
||||
<Logger name="org.springframework" level="error"/>
|
||||
<Logger name="org.apache.geode" level="${sys:log4j.geode.log.level:-error}"/>
|
||||
<Logger name="org.springframework" level="${sys:log4j.spring.log.level:-error}"/>
|
||||
<Logger name="org.springframework.data.gemfire.listener.adapter.ContinuousQueryListenerAdapter" level="off" additivity="false"/>
|
||||
<Logger name="org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer" level="off" additivity="false"/>
|
||||
<Root level="error">
|
||||
<Root level="${sys:log4j.log.level:-error}">
|
||||
<AppenderRef ref="Console"/>
|
||||
<!--AppenderRef ref="File" /-->
|
||||
</Root>
|
||||
|
||||
Reference in New Issue
Block a user