Refactor remaining SDG test classes to run on Java 16.

Resolves gh-497.
This commit is contained in:
John Blum
2021-05-10 16:16:44 -07:00
parent 1875deeafe
commit f110354540
5 changed files with 76 additions and 60 deletions

View File

@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
package org.springframework.data.gemfire; package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@@ -27,20 +26,16 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.Data; import org.junit.AfterClass;
import lombok.NonNull; import org.junit.BeforeClass;
import lombok.RequiredArgsConstructor; import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.Cache; import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool; import org.apache.geode.cache.client.Pool;
import org.junit.AfterClass;
import org.junit.BeforeClass;
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.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -52,7 +47,6 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.client.PoolFactoryBean; import org.springframework.data.gemfire.client.PoolFactoryBean;
import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.gemfire.mapping.annotation.Region;
import org.springframework.data.gemfire.process.ProcessExecutor;
import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.process.ProcessWrapper;
import org.springframework.data.gemfire.server.CacheServerFactoryBean; import org.springframework.data.gemfire.server.CacheServerFactoryBean;
import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpoint;
@@ -62,10 +56,14 @@ import org.springframework.data.gemfire.util.PropertiesBuilder;
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;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
/** /**
* Integrations tests for {@link GemfireTemplate} testing proper function and behavior of executing (OQL) queries * Integrations Tests for {@link GemfireTemplate} testing the proper function and behavior of executing (OQL) queries
* from a cache client application using the {@link GemfireTemplate} to a cluster of GemFire servers that have * from a cache client application using the {@link GemfireTemplate} to a cluster of GemFire servers that have
* been grouped according to business function and data access, primarily to distribute the load. * been grouped according to business function and data access in order to distribute the load.
* *
* Each GemFire {@link Pool} is configured to target a specific server group. Each group of servers in the cluster * Each GemFire {@link Pool} is configured to target a specific server group. Each group of servers in the cluster
* defines specific {@link Region Regions} to manage data independently and separately from other data that might * defines specific {@link Region Regions} to manage data independently and separately from other data that might
@@ -73,7 +71,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* *
* Spring Data GemFire's {@link GemfireTemplate} should intelligently employ the right * Spring Data GemFire's {@link GemfireTemplate} should intelligently employ the right
* {@link org.apache.geode.cache.query.QueryService} configured with the {@link Region Region's} {@link Pool} * {@link org.apache.geode.cache.query.QueryService} configured with the {@link Region Region's} {@link Pool}
* meta-data when executing the query in order to ensure the right servers containing the {@link Region Region's} * metadata when executing the query in order to ensure the right servers containing the {@link Region Region's}
* with the data of interest are targeted. * with the data of interest are targeted.
* *
* @author John Blum * @author John Blum
@@ -104,21 +102,26 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
private GemfireTemplate dogsTemplate; private GemfireTemplate dogsTemplate;
@BeforeClass @BeforeClass
public static void setupGemFireCluster() throws Exception { public static void runGemFireCluster() throws Exception {
serverOne = ProcessExecutor.launch(createDirectory("serverOne"), GemFireCacheServerOneConfiguration.class);
serverOne = run(createDirectory("serverOne"), GemFireCacheServerOneConfiguration.class);
waitForServerToStart("localhost", 41414); waitForServerToStart("localhost", 41414);
serverTwo = ProcessExecutor.launch(createDirectory("serverTwo"), GemFireCacheServerTwoConfiguration.class);
serverTwo = run(createDirectory("serverTwo"), GemFireCacheServerTwoConfiguration.class);
waitForServerToStart("localhost", 42424); waitForServerToStart("localhost", 42424);
} }
@AfterClass @AfterClass
public static void shutdownGemFireCluster() { public static void shutdownGemFireCluster() {
serverOne.stop(); stop(serverOne);
serverTwo.stop(); stop(serverTwo);
} }
@Test @Test
public void findsAllCats() { public void findsAllCats() {
List<String> catNames = catsTemplate.<String>find("SELECT c.name FROM /Cats c").asList(); List<String> catNames = catsTemplate.<String>find("SELECT c.name FROM /Cats c").asList();
assertThat(catNames).isNotNull(); assertThat(catNames).isNotNull();
@@ -128,6 +131,7 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
@Test @Test
public void findsAllDogs() { public void findsAllDogs() {
List<String> dogNames = dogsTemplate.<String>find("SELECT d.name FROM /Dogs d").asList(); List<String> dogNames = dogsTemplate.<String>find("SELECT d.name FROM /Dogs d").asList();
assertThat(dogNames).isNotNull(); assertThat(dogNames).isNotNull();
@@ -161,7 +165,7 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
} }
String applicationName() { String applicationName() {
return GemFireClientCacheConfiguration.class.getName(); return GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.class.getName();
} }
String logLevel() { String logLevel() {
@@ -217,7 +221,6 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
ClientRegionFactoryBean<String, Cat> catsRegion = new ClientRegionFactoryBean<>(); ClientRegionFactoryBean<String, Cat> catsRegion = new ClientRegionFactoryBean<>();
catsRegion.setCache(gemfireCache); catsRegion.setCache(gemfireCache);
catsRegion.setClose(false);
catsRegion.setPoolName(serverOnePool.getName()); catsRegion.setPoolName(serverOnePool.getName());
catsRegion.setShortcut(ClientRegionShortcut.PROXY); catsRegion.setShortcut(ClientRegionShortcut.PROXY);
@@ -231,7 +234,6 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
ClientRegionFactoryBean<String, Cat> dogsRegion = new ClientRegionFactoryBean<>(); ClientRegionFactoryBean<String, Cat> dogsRegion = new ClientRegionFactoryBean<>();
dogsRegion.setCache(gemfireCache); dogsRegion.setCache(gemfireCache);
dogsRegion.setClose(false);
dogsRegion.setPoolName(serverTwoPool.getName()); dogsRegion.setPoolName(serverTwoPool.getName());
dogsRegion.setShortcut(ClientRegionShortcut.PROXY); dogsRegion.setShortcut(ClientRegionShortcut.PROXY);
@@ -263,7 +265,6 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
.setProperty("name", applicationName()) .setProperty("name", applicationName())
.setProperty("log-level", logLevel()) .setProperty("log-level", logLevel())
.setProperty("locators", "localhost[11235]") .setProperty("locators", "localhost[11235]")
.setProperty("enable-cluster-configuration", "false")
.setProperty("groups", groups()) .setProperty("groups", groups())
.setProperty("start-locator", startLocator()) .setProperty("start-locator", startLocator())
.build(); .build();
@@ -315,6 +316,11 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
@SuppressWarnings("all") @SuppressWarnings("all")
static class GemFireCacheServerOneConfiguration extends AbstractGemFireCacheServerConfiguration { static class GemFireCacheServerOneConfiguration extends AbstractGemFireCacheServerConfiguration {
public static void main(String[] args) {
new AnnotationConfigApplicationContext(GemFireCacheServerOneConfiguration.class)
.registerShutdownHook();
}
@Resource(name = "Cats") @Resource(name = "Cats")
private org.apache.geode.cache.Region<String, Cat> cats; private org.apache.geode.cache.Region<String, Cat> cats;
@@ -353,22 +359,21 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
LocalRegionFactoryBean catsRegion = new LocalRegionFactoryBean(); LocalRegionFactoryBean catsRegion = new LocalRegionFactoryBean();
catsRegion.setCache(gemfireCache); catsRegion.setCache(gemfireCache);
catsRegion.setClose(false);
catsRegion.setPersistent(false); catsRegion.setPersistent(false);
return catsRegion; return catsRegion;
} }
public static void main(String[] args) {
new AnnotationConfigApplicationContext(GemFireCacheServerOneConfiguration.class)
.registerShutdownHook();
}
} }
@Configuration @Configuration
@SuppressWarnings("all") @SuppressWarnings("all")
static class GemFireCacheServerTwoConfiguration extends AbstractGemFireCacheServerConfiguration { static class GemFireCacheServerTwoConfiguration extends AbstractGemFireCacheServerConfiguration {
public static void main(String[] args) {
new AnnotationConfigApplicationContext(GemFireCacheServerTwoConfiguration.class)
.registerShutdownHook();
}
@Resource(name = "Dogs") @Resource(name = "Dogs")
private org.apache.geode.cache.Region<String, Dog> dogs; private org.apache.geode.cache.Region<String, Dog> dogs;
@@ -399,15 +404,9 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT
LocalRegionFactoryBean<String, Dog> dogsRegion = new LocalRegionFactoryBean<String, Dog>(); LocalRegionFactoryBean<String, Dog> dogsRegion = new LocalRegionFactoryBean<String, Dog>();
dogsRegion.setCache(gemfireCache); dogsRegion.setCache(gemfireCache);
dogsRegion.setClose(false);
dogsRegion.setPersistent(false); dogsRegion.setPersistent(false);
return dogsRegion; return dogsRegion;
} }
public static void main(String[] args) {
new AnnotationConfigApplicationContext(GemFireCacheServerTwoConfiguration.class)
.registerShutdownHook();
}
} }
} }

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.config.annotation; package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@@ -23,12 +22,12 @@ import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.geode.cache.Region;
import org.junit.Before; import org.junit.Before;
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.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;
@@ -39,9 +38,10 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
/** /**
* The EnableLuceneIndexingConfigurationIntegrationTests class... * Integration Tests for Lucene Indexing Configuration.
* *
* @author John Blum * @author John Blum
* @see org.junit.Test
* @since 1.0.0 * @since 1.0.0
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)

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.process; package org.springframework.data.gemfire.process;
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
@@ -26,6 +25,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.gemfire.test.support.FileSystemUtils; import org.springframework.data.gemfire.test.support.FileSystemUtils;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -86,6 +86,12 @@ public abstract class ProcessExecutor {
command.add(JAVA_EXE.getAbsolutePath()); command.add(JAVA_EXE.getAbsolutePath());
command.add("-server"); command.add("-server");
command.add("-ea"); command.add("-ea");
command.add("--add-opens");
command.add("java.base/java.lang=ALL-UNNAMED");
command.add("--add-opens");
command.add("java.base/java.nio=ALL-UNNAMED");
command.add("--add-opens");
command.add("java.base/java.util=ALL-UNNAMED");
command.add("-classpath"); command.add("-classpath");
command.add(StringUtils.hasText(classpath) ? classpath : JAVA_CLASSPATH); command.add(StringUtils.hasText(classpath) ? classpath : JAVA_CLASSPATH);
command.addAll(getSpringGemFireSystemProperties()); command.addAll(getSpringGemFireSystemProperties());
@@ -94,7 +100,7 @@ public abstract class ProcessExecutor {
if (isJvmOption(arg)) { if (isJvmOption(arg)) {
command.add(arg); command.add(arg);
} }
else if (!StringUtils.isEmpty(arg)) { else if (StringUtils.hasText(arg)) {
programArguments.add(arg); programArguments.add(arg);
} }
} }
@@ -102,9 +108,23 @@ public abstract class ProcessExecutor {
command.add(type.getName()); command.add(type.getName());
command.addAll(programArguments); command.addAll(programArguments);
//System.err.printf("JAVA COMMAND (%s)%n", toExecutableCommandString(command));
//System.err.flush();
return command.toArray(new String[0]); return command.toArray(new String[0]);
} }
private static String toExecutableCommandString(Iterable<String> command) {
StringBuilder commandString = new StringBuilder();
for (String commandPart : CollectionUtils.nullSafeIterable(command)) {
commandString.append(" ").append(commandPart);
}
return commandString.toString().trim();
}
protected static Collection<? extends String> getSpringGemFireSystemProperties() { protected static Collection<? extends String> getSpringGemFireSystemProperties() {
return System.getProperties().stringPropertyNames().stream() return System.getProperties().stringPropertyNames().stream()

View File

@@ -28,17 +28,13 @@ 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 lombok.Data; import org.junit.Test;
import lombok.NonNull; import org.junit.runner.RunWith;
import lombok.RequiredArgsConstructor;
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.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;
@@ -51,6 +47,10 @@ 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;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
/** /**
* Integration tests for the Spring Data Geode, Apache Geode and Apache Lucene Integration. * Integration tests for the Spring Data Geode, Apache Geode and Apache Lucene Integration.
* *
@@ -74,13 +74,13 @@ public class LuceneOperationsIntegrationTests {
protected static final String GEMFIRE_LOG_LEVEL = "none"; protected static final String GEMFIRE_LOG_LEVEL = "none";
private static Person jonDoe = Person.newPerson(LocalDate.of(1969, Month.JULY, 4), "Jon", "Doe").with("Master of Science"); private static final 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 final 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 final 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 final 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 final 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 final 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"); private static final Person sourDoe = Person.newPerson(LocalDate.of(1999, Month.DECEMBER, 1), "Sour", "Doe").with("Bachelor of Art");
private static List<String> asNames(List<? extends Nameable> nameables) { private static List<String> asNames(List<? extends Nameable> nameables) {
@@ -110,7 +110,6 @@ public class LuceneOperationsIntegrationTests {
} }
@Test @Test
@SuppressWarnings("all")
public void findsMasterDoesAsTypeUserSuccessfully() { public void findsMasterDoesAsTypeUserSuccessfully() {
List<User> masterDoes = template.query("title: Master*", "title", User.class); List<User> masterDoes = template.query("title: Master*", "title", User.class);

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 static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
@@ -89,7 +88,7 @@ public abstract class FileSystemUtils extends FileUtils {
Assert.isTrue(isDirectory(directory), String.format( Assert.isTrue(isDirectory(directory), String.format(
"File [%s] does not refer to a valid directory", directory)); "File [%s] does not refer to a valid directory", directory));
List<File> results = new ArrayList<File>(); List<File> results = new ArrayList<>();
for (File file : safeListFiles(directory, fileFilter)) { for (File file : safeListFiles(directory, fileFilter)) {
if (isDirectory(file)) { if (isDirectory(file)) {
@@ -100,15 +99,13 @@ public abstract class FileSystemUtils extends FileUtils {
} }
} }
return results.toArray(new File[results.size()]); return results.toArray(new File[0]);
} }
/* (non-Javadoc) */
public static File[] safeListFiles(File directory) { public static File[] safeListFiles(File directory) {
return safeListFiles(directory, AllFilesFilter.INSTANCE); return safeListFiles(directory, AllFilesFilter.INSTANCE);
} }
/* (non-Javadoc) */
public static File[] safeListFiles(File directory, FileFilter fileFilter) { public static File[] safeListFiles(File directory, FileFilter fileFilter) {
FileFilter resolvedFileFilter = (fileFilter != null ? fileFilter : AllFilesFilter.INSTANCE); FileFilter resolvedFileFilter = (fileFilter != null ? fileFilter : AllFilesFilter.INSTANCE);
File[] files = (isDirectory(directory) ? directory.listFiles(resolvedFileFilter) : null); File[] files = (isDirectory(directory) ? directory.listFiles(resolvedFileFilter) : null);
@@ -185,7 +182,8 @@ public abstract class FileSystemUtils extends FileUtils {
} }
enum LogicalOperator { enum LogicalOperator {
AND, OR; AND,
OR
} }
} }