SGF-864 - Fix unreliable tests.

This commit is contained in:
John Blum
2019-07-17 02:22:07 -07:00
parent 0fe205acb8
commit 1245548566
9 changed files with 140 additions and 99 deletions

View File

@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
package org.springframework.data.gemfire.search.lucene; package org.springframework.data.gemfire.search.lucene;
import static java.util.stream.StreamSupport.stream; 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.LuceneService;
import org.apache.geode.cache.lucene.LuceneServiceProvider; import org.apache.geode.cache.lucene.LuceneServiceProvider;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@@ -423,8 +423,12 @@ public class LuceneIndexFactoryBean extends AbstractFactoryBeanSupport<LuceneInd
*/ */
@Override @Override
public void setBeanName(String name) { public void setBeanName(String name) {
super.setBeanName(name); super.setBeanName(name);
setIndexName(name);
if (!StringUtils.hasText(this.indexName)) {
setIndexName(name);
}
} }
/** /**

View File

@@ -147,6 +147,8 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr
List<String> arguments = new ArrayList<String>(); List<String> arguments = new ArrayList<String>();
arguments.add("-Dgemfire.name=" + locatorName); 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.enable-cluster-configuration=true");
arguments.add("-Dspring.data.gemfire.load-cluster-configuration=true"); arguments.add("-Dspring.data.gemfire.load-cluster-configuration=true");
arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL)); arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL));
@@ -266,6 +268,7 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr
public void localConfigurationTest() { public void localConfigurationTest() {
try { try {
newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml")); newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml"));
fail("Loading the 'cacheUsingLocalOnlyConfigurationIntegrationTest.xml' Spring ApplicationContext" fail("Loading the 'cacheUsingLocalOnlyConfigurationIntegrationTest.xml' Spring ApplicationContext"

View File

@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
package org.springframework.data.gemfire.search.lucene; package org.springframework.data.gemfire.search.lucene;
import static org.assertj.core.api.Assertions.assertThat; 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.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors; 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.GemFireCache;
import org.apache.geode.cache.Region; import org.apache.geode.cache.Region;
import org.apache.geode.cache.lucene.LuceneService; 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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn; 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.annotation.Id;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; 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.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@@ -71,62 +72,33 @@ public class LuceneOperationsIntegrationTests {
private static final AtomicLong IDENTIFIER = new AtomicLong(0L); private static final AtomicLong IDENTIFIER = new AtomicLong(0L);
protected static final String LOG_LEVEL = "none"; protected static final String GEMFIRE_LOG_LEVEL = "none";
private Person jonDoe; private static Person jonDoe = Person.newPerson(LocalDate.of(1969, Month.JULY, 4), "Jon", "Doe").with("Master of Science");
private Person janeDoe; private static Person janeDoe = Person.newPerson(LocalDate.of(1969, Month.AUGUST, 16), "Jane", "Doe").with("Doctor of Astrophysics");
private Person cookieDoe; private static Person cookieDoe = Person.newPerson(LocalDate.of(1991, Month.APRIL, 2), "Cookie", "Doe").with("Bachelor of Physics");
private Person froDoe; private static Person froDoe = Person.newPerson(LocalDate.of(1988, Month.MAY, 25), "Fro", "Doe").with("Doctor of Computer Science");
private Person hoDoe; private static Person hoDoe = Person.newPerson(LocalDate.of(1984, Month.NOVEMBER, 11), "Ho", "Doe").with("Doctor of Math");
private Person pieDoe; private static Person pieDoe = Person.newPerson(LocalDate.of(1996, Month.JUNE, 4), "Pie", "Doe").with("Master of Astronomy");
private Person sourDoe; private static Person sourDoe = Person.newPerson(LocalDate.of(1999, Month.DECEMBER, 1), "Sour", "Doe").with("Bachelor of Art");
@Autowired private static List<String> asNames(List<? extends Nameable> nameables) {
private LuceneService luceneService;
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 @Autowired
private ProjectingLuceneOperations template; 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 @Test
public void findsDoctorDoesAsTypePersonSuccessfully() { public void findsDoctorDoesAsTypePersonSuccessfully() {
@@ -150,7 +122,7 @@ public class LuceneOperationsIntegrationTests {
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@PeerCacheApplication(name = "LuceneOperationsIntegrationTests", logLevel = LOG_LEVEL) @PeerCacheApplication(name = "LuceneOperationsIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL)
static class TestConfiguration { static class TestConfiguration {
@Bean(name = "People") @Bean(name = "People")
@@ -192,7 +164,26 @@ public class LuceneOperationsIntegrationTests {
@Bean @Bean
@DependsOn("personTitleIndex") @DependsOn("personTitleIndex")
ProjectingLuceneOperations luceneTemplate() { 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);
SpringUtils.safeRunOperation(() ->
luceneService.waitUntilFlushed("PersonTitleIndex", "/People", 15L, TimeUnit.SECONDS));
} }
} }

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.snapshot; package org.springframework.data.gemfire.snapshot;
import static java.util.Arrays.stream; import static java.util.Arrays.stream;
@@ -31,12 +30,14 @@ import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.snapshot.SnapshotFilter;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.gemfire.repository.sample.Person; 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) { protected void wait(int seconds, int expectedDoeSize, int expectedEveryoneSize, int expectedHandySize) {
ThreadUtils.timedWait(TimeUnit.SECONDS.toMillis(seconds), 500, ThreadUtils.timedWait(TimeUnit.SECONDS.toMillis(seconds), 500,
() -> (doe.size() < expectedDoeSize && everyoneElse.size() < () -> doe.size() < expectedDoeSize
expectedEveryoneSize && handy.size() < expectedHandySize)); || everyoneElse.size() < expectedEveryoneSize
|| handy.size() < expectedHandySize);
} }
@Test @Test
@@ -178,7 +180,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest {
eventPublisher.publishEvent(event); eventPublisher.publishEvent(event);
wait(10, 5, 4, 3); wait(5, 5, 4, 3);
assertPeople(doe, jonDoe, janeDoe, cookieDoe, pieDoe, sourDoe); assertPeople(doe, jonDoe, janeDoe, cookieDoe, pieDoe, sourDoe);
assertPeople(everyoneElse, jackBlack, joeDirt, jackHill, jillHill); assertPeople(everyoneElse, jackBlack, joeDirt, jackHill, jillHill);
@@ -239,7 +241,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest {
@Autowired @Autowired
private ApplicationEventPublisher eventPublisher; 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) @Scheduled(fixedDelay = 1000)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.snapshot; package org.springframework.data.gemfire.snapshot;
import static org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat; import static org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat;
@@ -49,25 +48,28 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
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.After;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.slf4j.Logger;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
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.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent;
import org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent;
import org.springframework.data.gemfire.snapshot.event.SnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.SnapshotApplicationEvent;
import org.springframework.data.gemfire.test.support.FileSystemUtils; import org.springframework.data.gemfire.test.support.FileSystemUtils;
import org.slf4j.Logger;
/** /**
* The SnapshotServiceFactoryBeanTest class is a test suite of test cases testing the contract and functionality * The SnapshotServiceFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the SnapshotServiceFactoryBean class. * of the SnapshotServiceFactoryBean class.
@@ -177,12 +179,14 @@ public class SnapshotServiceFactoryBeanTest {
@Test @Test
public void nullSafeIsFileWithFile() { public void nullSafeIsFileWithFile() {
assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(FileSystemUtils.JAVA_EXE), assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(FileSystemUtils.JAVA_EXE),
is(FileSystemUtils.JAVA_EXE.isFile())); is(FileSystemUtils.JAVA_EXE.isFile()));
} }
@Test @Test
public void nullSafeIsFileWithNonFiles() { public void nullSafeIsFileWithNonFiles() {
assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File("/path/to/non-existing/file.ext")), is(false)); assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File("/path/to/non-existing/file.ext")), is(false));
assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File(System.getProperty("user.dir"))), is(false)); assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File(System.getProperty("user.dir"))), is(false));
} }
@@ -211,6 +215,7 @@ public class SnapshotServiceFactoryBeanTest {
public void setAndGetCacheSuccessfully() { public void setAndGetCacheSuccessfully() {
Cache mockCache = mock(Cache.class, "MockCache"); Cache mockCache = mock(Cache.class, "MockCache");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean(); SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean();
factoryBean.setCache(mockCache); factoryBean.setCache(mockCache);
@@ -312,7 +317,9 @@ public class SnapshotServiceFactoryBeanTest {
"MockSnapshotServiceAdapter"); "MockSnapshotServiceAdapter");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override protected SnapshotServiceAdapter create() {
@Override
protected SnapshotServiceAdapter create() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -332,7 +339,9 @@ public class SnapshotServiceFactoryBeanTest {
"MockSnapshotServiceAdapter"); "MockSnapshotServiceAdapter");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override protected SnapshotServiceAdapter create() {
@Override
protected SnapshotServiceAdapter create() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -349,6 +358,7 @@ public class SnapshotServiceFactoryBeanTest {
public void createCacheSnapshotService() { public void createCacheSnapshotService() {
Cache mockCache = mock(Cache.class, "MockCache"); Cache mockCache = mock(Cache.class, "MockCache");
CacheSnapshotService mockCacheSnapshotService = mock(CacheSnapshotService.class, "MockCacheSnapshotService"); CacheSnapshotService mockCacheSnapshotService = mock(CacheSnapshotService.class, "MockCacheSnapshotService");
when(mockCache.getSnapshotService()).thenReturn(mockCacheSnapshotService); when(mockCache.getSnapshotService()).thenReturn(mockCacheSnapshotService);
@@ -368,6 +378,7 @@ public class SnapshotServiceFactoryBeanTest {
public void createRegionSnapshotService() { public void createRegionSnapshotService() {
Region mockRegion = mock(Region.class, "MockRegion"); Region mockRegion = mock(Region.class, "MockRegion");
RegionSnapshotService mockRegionSnapshotService = mock(RegionSnapshotService.class, "MockRegionSnapshotService"); RegionSnapshotService mockRegionSnapshotService = mock(RegionSnapshotService.class, "MockRegionSnapshotService");
when(mockRegion.getSnapshotService()).thenReturn(mockRegionSnapshotService); when(mockRegion.getSnapshotService()).thenReturn(mockRegionSnapshotService);
@@ -412,7 +423,9 @@ public class SnapshotServiceFactoryBeanTest {
"MockSnapshotServiceAdapter"); "MockSnapshotServiceAdapter");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() {
@Override
public SnapshotServiceAdapter getObject() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -443,7 +456,9 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(toArray(eventSnapshotMetadata)); when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(toArray(eventSnapshotMetadata));
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() {
@Override
public SnapshotServiceAdapter getObject() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -478,7 +493,9 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null); when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null);
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() {
@Override
public SnapshotServiceAdapter getObject() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -510,7 +527,9 @@ public class SnapshotServiceFactoryBeanTest {
mock(SnapshotServiceAdapter.class, "MockSnapshotServiceAdapter"); mock(SnapshotServiceAdapter.class, "MockSnapshotServiceAdapter");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() {
@Override
public SnapshotServiceAdapter getObject() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -544,7 +563,9 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null); when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null);
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() { SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() {
@Override
public SnapshotServiceAdapter getObject() {
return mockSnapshotService; return mockSnapshotService;
} }
}; };
@@ -948,7 +969,9 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotOptions.setParallelMode(anyBoolean())).thenReturn(mockSnapshotOptions); when(mockSnapshotOptions.setParallelMode(anyBoolean())).thenReturn(mockSnapshotOptions);
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() { TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
@Override public SnapshotOptions<Object, Object> createOptions() {
@Override
public SnapshotOptions<Object, Object> createOptions() {
return mockSnapshotOptions; return mockSnapshotOptions;
} }
}; };
@@ -997,7 +1020,9 @@ public class SnapshotServiceFactoryBeanTest {
when(mockLog.isDebugEnabled()).thenReturn(true); when(mockLog.isDebugEnabled()).thenReturn(true);
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() { TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
@Override Logger createLog() {
@Override
Logger createLog() {
return mockLog; return mockLog;
} }
}; };
@@ -1018,7 +1043,9 @@ public class SnapshotServiceFactoryBeanTest {
when(mockLog.isDebugEnabled()).thenReturn(false); when(mockLog.isDebugEnabled()).thenReturn(false);
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() { TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
@Override Logger createLog() {
@Override
Logger createLog() {
return mockLog; return mockLog;
} }
}; };
@@ -1060,11 +1087,13 @@ public class SnapshotServiceFactoryBeanTest {
adapter.load(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE); adapter.load(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE);
} }
catch (ImportSnapshotException expected) { catch (ImportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to load snapshots from directory [%1$s] in format [GEMFIRE]", "Failed to load snapshots from directory [%1$s] in format [GEMFIRE]",
FileSystemUtils.WORKING_DIRECTORY)))); FileSystemUtils.WORKING_DIRECTORY))));
assertThat(expected.getCause(), is(instanceOf(IOException.class))); assertThat(expected.getCause(), is(instanceOf(IOException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {
@@ -1092,11 +1121,13 @@ public class SnapshotServiceFactoryBeanTest {
adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat); adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat);
} }
catch (ImportSnapshotException expected) { catch (ImportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to load snapshots [%1$s] in format [GEMFIRE] using options [%2$s]", "Failed to load snapshots [%1$s] in format [GEMFIRE] using options [%2$s]",
Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions)))); Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions))));
assertThat(expected.getCause(), is(instanceOf(ClassCastException.class))); assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {
@@ -1121,11 +1152,13 @@ public class SnapshotServiceFactoryBeanTest {
adapter.save(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE); adapter.save(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE);
} }
catch (ExportSnapshotException expected) { catch (ExportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to save snapshots to directory [%1$s] in format [GEMFIRE]", "Failed to save snapshots to directory [%1$s] in format [GEMFIRE]",
FileSystemUtils.WORKING_DIRECTORY)))); FileSystemUtils.WORKING_DIRECTORY))));
assertThat(expected.getCause(), is(instanceOf(IOException.class))); assertThat(expected.getCause(), is(instanceOf(IOException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {
@@ -1153,11 +1186,13 @@ public class SnapshotServiceFactoryBeanTest {
adapter.save(FileSystemUtils.USER_HOME, SnapshotFormat.GEMFIRE, mockSnapshotOptions); adapter.save(FileSystemUtils.USER_HOME, SnapshotFormat.GEMFIRE, mockSnapshotOptions);
} }
catch (ExportSnapshotException expected) { catch (ExportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to save snapshots to directory [%1$s] in format [GEMFIRE] using options [%2$s]", "Failed to save snapshots to directory [%1$s] in format [GEMFIRE] using options [%2$s]",
FileSystemUtils.USER_HOME, mockSnapshotOptions)))); FileSystemUtils.USER_HOME, mockSnapshotOptions))));
assertThat(expected.getCause(), is(instanceOf(ClassCastException.class))); assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {
@@ -1183,10 +1218,12 @@ public class SnapshotServiceFactoryBeanTest {
adapter.load(snapshotDat, SnapshotFormat.GEMFIRE); adapter.load(snapshotDat, SnapshotFormat.GEMFIRE);
} }
catch (ImportSnapshotException expected) { catch (ImportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to load snapshot from file [%1$s] in format [GEMFIRE]", snapshotDat)))); "Failed to load snapshot from file [%1$s] in format [GEMFIRE]", snapshotDat))));
assertThat(expected.getCause(), is(instanceOf(IOException.class))); assertThat(expected.getCause(), is(instanceOf(IOException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {
@@ -1213,11 +1250,13 @@ public class SnapshotServiceFactoryBeanTest {
adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat); adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat);
} }
catch (ImportSnapshotException expected) { catch (ImportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to load snapshots [%1$s] in format [GEMFIRE] using options [%2$s]", "Failed to load snapshots [%1$s] in format [GEMFIRE] using options [%2$s]",
Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions)))); Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions))));
assertThat(expected.getCause(), is(instanceOf(ClassCastException.class))); assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {
@@ -1243,10 +1282,12 @@ public class SnapshotServiceFactoryBeanTest {
adapter.save(snapshotDat, SnapshotFormat.GEMFIRE); adapter.save(snapshotDat, SnapshotFormat.GEMFIRE);
} }
catch (ExportSnapshotException expected) { catch (ExportSnapshotException expected) {
assertThat(expected.getMessage(), is(equalTo(String.format( assertThat(expected.getMessage(), is(equalTo(String.format(
"Failed to save snapshot to file [%1$s] in format [GEMFIRE]", snapshotDat)))); "Failed to save snapshot to file [%1$s] in format [GEMFIRE]", snapshotDat))));
assertThat(expected.getCause(), is(instanceOf(IOException.class))); assertThat(expected.getCause(), is(instanceOf(IOException.class)));
assertThat(expected.getCause().getMessage(), is(equalTo("TEST"))); assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
throw expected; throw expected;
} }
finally { finally {

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.test.support; package org.springframework.data.gemfire.test.support;
/** /**
@@ -49,6 +48,7 @@ public abstract class StackTraceUtils extends ThreadUtils {
} }
public static StackTraceElement getTestCaller(final Thread thread) { public static StackTraceElement getTestCaller(final Thread thread) {
for (StackTraceElement stackTraceElement : thread.getStackTrace()) { for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
if (isTestSuiteClass(stackTraceElement) && isTestCaseMethod(stackTraceElement)) { if (isTestSuiteClass(stackTraceElement) && isTestCaseMethod(stackTraceElement)) {
return stackTraceElement; return stackTraceElement;
@@ -59,6 +59,7 @@ public abstract class StackTraceUtils extends ThreadUtils {
} }
private static boolean isTestCaseMethod(final StackTraceElement element) { private static boolean isTestCaseMethod(final StackTraceElement element) {
boolean result = element.getMethodName().toLowerCase().startsWith("test"); boolean result = element.getMethodName().toLowerCase().startsWith("test");
try { try {
@@ -71,9 +72,11 @@ public abstract class StackTraceUtils extends ThreadUtils {
} }
private static boolean isTestSuiteClass(final StackTraceElement element) { private static boolean isTestSuiteClass(final StackTraceElement element) {
boolean result = element.getClass().getSimpleName().toLowerCase().endsWith("test"); boolean result = element.getClass().getSimpleName().toLowerCase().endsWith("test");
result |= element.getClass().isAssignableFrom(junit.framework.TestCase.class); result |= element.getClass().isAssignableFrom(junit.framework.TestCase.class);
return result; return result;
} }
} }

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.test.support; package org.springframework.data.gemfire.test.support;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -29,6 +28,7 @@ import java.util.concurrent.TimeUnit;
public abstract class ThreadUtils { public abstract class ThreadUtils {
public static boolean sleep(long milliseconds) { public static boolean sleep(long milliseconds) {
try { try {
Thread.sleep(milliseconds); Thread.sleep(milliseconds);
return true; return true;
@@ -44,11 +44,7 @@ public abstract class ThreadUtils {
} }
public static boolean timedWait(long duration, long interval) { public static boolean timedWait(long duration, long interval) {
return timedWait(duration, interval, new WaitCondition() { return timedWait(duration, interval, () -> true);
@Override public boolean waiting() {
return true;
}
});
} }
@SuppressWarnings("all") @SuppressWarnings("all")

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.gemfire.test.support; package org.springframework.data.gemfire.test.support;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -31,10 +30,12 @@ import java.io.StringWriter;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public abstract class ThrowableUtils { public abstract class ThrowableUtils {
public static String toString(final Throwable t) { public static String toString(Throwable cause) {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
cause.printStackTrace(new PrintWriter(writer));
return writer.toString(); return writer.toString();
} }
} }

View File

@@ -9,11 +9,11 @@
<Null name="nop"/> <Null name="nop"/>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Logger name="org.apache.geode" level="error"/> <Logger name="org.apache.geode" level="${sys:log4j.geode.log.level:-error}"/>
<Logger name="org.springframework" 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.listener.adapter.ContinuousQueryListenerAdapter" level="off" additivity="false"/>
<Logger name="org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer" 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="Console"/>
<!--AppenderRef ref="File" /--> <!--AppenderRef ref="File" /-->
</Root> </Root>