From 84f0af50e43adef573e1d62ebeb9f5b502626e0d Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 20 Jul 2020 20:58:00 -0700 Subject: [PATCH] Adapt cache data import/export auto-configuration to the new ResolverResolver, ResourceReader and ResourceWriter API. Resolves gh-92. --- .../DataImportExportAutoConfiguration.java | 32 ++++++++++++++++--- ...portAutoConfigurationIntegrationTests.java | 1 + ...portAutoConfigurationIntegrationTests.java | 5 ++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/DataImportExportAutoConfiguration.java b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/DataImportExportAutoConfiguration.java index a08db000..df40ac3b 100644 --- a/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/DataImportExportAutoConfiguration.java +++ b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/DataImportExportAutoConfiguration.java @@ -19,6 +19,7 @@ import java.util.Optional; import java.util.function.Predicate; import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -38,6 +39,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.geode.boot.autoconfigure.support.PdxInstanceWrapperRegionAspect; import org.springframework.geode.cache.SimpleCacheResolver; +import org.springframework.geode.core.io.ResourceNotFoundException; import org.springframework.geode.data.AbstractCacheDataImporterExporter; import org.springframework.geode.data.CacheDataImporterExporter; import org.springframework.geode.data.json.JsonCacheDataImporterExporter; @@ -50,6 +52,7 @@ import org.springframework.lang.Nullable; * * @author John Blum * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region * @see org.springframework.boot.autoconfigure.EnableAutoConfiguration * @see org.springframework.boot.autoconfigure.condition.AnyNestedCondition * @see org.springframework.boot.autoconfigure.condition.ConditionalOnBean @@ -57,15 +60,15 @@ import org.springframework.lang.Nullable; * @see org.springframework.boot.autoconfigure.condition.ConditionalOnProperty * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Condition - * @see org.springframework.context.annotation.ConditionContext * @see org.springframework.context.annotation.Conditional * @see org.springframework.context.annotation.Configuration + * @see org.springframework.core.env.ConfigurableEnvironment * @see org.springframework.core.env.Environment - * @see org.springframework.core.type.AnnotatedTypeMetadata * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.geode.boot.autoconfigure.support.PdxInstanceWrapperRegionAspect - * @see org.springframework.geode.cache.SimpleCacheResolver + * @see org.springframework.geode.data.CacheDataImporterExporter * @see org.springframework.geode.data.json.JsonCacheDataImporterExporter + * @see org.springframework.geode.data.support.LifecycleAwareCacheDataImporterExporter * @since 1.3.0 */ @Configuration @@ -81,7 +84,28 @@ public class DataImportExportAutoConfiguration { @Bean CacheDataImporterExporter jsonCacheDataImporterExporter() { - return new LifecycleAwareCacheDataImporterExporter(new JsonCacheDataImporterExporter()); + return new LifecycleAwareCacheDataImporterExporter(newCacheDataImporterExporter()); + } + + @SuppressWarnings("rawtypes") + protected CacheDataImporterExporter newCacheDataImporterExporter() { + + return new JsonCacheDataImporterExporter() { + + @Override + public @NonNull Region doImportInto(@NonNull Region region) { + + try { + return super.doImportInto(region); + } + catch (ResourceNotFoundException cause) { + + getLogger().info(cause.getMessage()); + + return region; + } + } + }; } @Bean diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java index cb354d70..d9522b51 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java @@ -81,6 +81,7 @@ import example.app.books.model.ISBN; @SpringBootTest( classes = ClientCacheDataImportExportAutoConfigurationIntegrationTests.TestGeodeClientConfiguration.class, properties = { + "spring.application.name=ClientCacheDataImportExportAutoConfigurationIntegrationTestsClient", "spring.data.gemfire.management.use-http=false", "spring.boot.data.gemfire.cache.data.import.active-profiles=IMPORT-CLIENT", "spring.boot.data.gemfire.cache.region.advice.enabled=true" diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/LocalClientCacheDataImportAutoConfigurationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/LocalClientCacheDataImportAutoConfigurationIntegrationTests.java index d4bc963b..6e652424 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/LocalClientCacheDataImportAutoConfigurationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/LocalClientCacheDataImportAutoConfigurationIntegrationTests.java @@ -52,7 +52,10 @@ import example.app.golf.model.Golfer; @RunWith(SpringRunner.class) @SpringBootTest( classes = LocalClientCacheDataImportAutoConfigurationIntegrationTests.TestGeodeClientConfiguration.class, - properties = "spring.boot.data.gemfire.cache.data.import.active-profiles=IMPORT-LOCAL" + properties = { + "spring.application.name=LocalClientCacheDataImportAutoConfigurationIntegrationTests", + "spring.boot.data.gemfire.cache.data.import.active-profiles=IMPORT-LOCAL" + } ) public class LocalClientCacheDataImportAutoConfigurationIntegrationTests {