From 54f7146e0fc6f1200b0dede2eea43d4ce7c0ce0c Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 27 Feb 2020 10:21:46 +0100 Subject: [PATCH] #539 - Polishing. Add author tags. Simplify dependency setup. Replace logger declarations with Lombok's CommonsLog. Simplify test annotations. Disable WAN module as the WAN server does not stop after running tests. Reformat code. --- README.md | 72 +++---- geode/events/pom.xml | 18 +- .../geode/server/events/Address.java | 2 +- .../geode/server/events/Customer.java | 3 +- .../server/events/CustomerCacheWriter.java | 4 +- .../server/events/CustomerRepository.java | 4 +- .../geode/server/events/EmailAddress.java | 4 +- .../geode/server/events/EventServer.java | 81 ++++---- .../server/events/EventServerConfig.java | 13 +- .../geode/server/events/LineItem.java | 3 +- .../server/events/LoggingCacheListener.java | 17 +- .../springdata/geode/server/events/Order.java | 4 +- .../events/OrderAsyncQueueListener.java | 24 ++- .../server/events/OrderProductSummary.java | 3 +- .../events/OrderProductSummaryRepository.java | 8 +- .../geode/server/events/OrderRepository.java | 7 +- .../geode/server/events/Product.java | 1 - .../server/events/ProductCacheLoader.java | 16 +- .../server/events/ProductRepository.java | 7 +- .../geode/server/events/EventServerTests.java | 27 +-- geode/expiration-eviction/pom.xml | 30 +-- .../server/expiration/eviction/Address.java | 2 +- .../eviction/CustomCustomerExpiry.java | 9 +- .../server/expiration/eviction/Customer.java | 3 +- .../eviction/CustomerRepository.java | 7 +- .../expiration/eviction/EmailAddress.java | 4 +- .../eviction/ExpirationEvictionServer.java | 6 +- .../ExpirationEvictionServerConfig.java | 24 +-- .../eviction/ExpirationPolicyConfig.java | 12 +- .../server/expiration/eviction/Order.java | 8 +- .../expiration/eviction/OrderRepository.java | 7 +- .../server/expiration/eviction/Product.java | 1 - .../eviction/ProductRepository.java | 7 +- .../EntityDefinedExpirationTests.java | 64 +++---- .../ExpirationEvictionServerTests.java | 99 +++++----- geode/function-invocation/pom.xml | 19 +- .../geode/client/function/Address.java | 2 +- .../geode/client/function/Customer.java | 3 +- .../geode/client/function/EmailAddress.java | 4 +- .../geode/client/function/LineItem.java | 3 +- .../geode/client/function/Order.java | 3 +- .../geode/client/function/Product.java | 1 - .../client/CustomerFunctionExecutions.java | 11 +- .../function/client/CustomerRepository.java | 11 +- ...tionInvocationClientApplicationConfig.java | 9 +- .../client/OrderFunctionExecutions.java | 12 +- .../function/client/OrderRepository.java | 9 +- .../client/ProductFunctionExecutions.java | 12 +- .../function/client/ProductRepository.java | 9 +- .../function/server/CustomerFunctions.java | 16 +- .../function/server/FunctionServer.java | 6 +- .../FunctionServerApplicationConfig.java | 6 +- .../function/server/OrderFunctions.java | 11 +- .../function/server/ProductFunctions.java | 13 +- .../client/FunctionInvocationClientTests.java | 112 ++++++----- geode/pom.xml | 179 +++++++----------- geode/queries/pom.xml | 35 ++-- .../geode/client/queries/Customer.java | 5 +- .../geode/client/queries/EmailAddress.java | 4 +- .../queries/client/CustomerRepository.java | 10 +- .../queries/client/QueryClientConfig.java | 11 +- .../client/queries/server/QueryServer.java | 8 +- .../queries/server/QueryServerConfig.java | 7 +- .../geode/client/queries/QueryTests.java | 78 ++++---- geode/security/pom.xml | 18 +- .../geode/client/security/Constants.java | 1 - .../geode/client/security/Customer.java | 3 +- .../geode/client/security/EmailAddress.java | 3 +- .../geode/client/security/Role.java | 14 +- .../geode/client/security/User.java | 17 +- .../security/client/CustomerRepository.java | 10 +- .../SecurityEnabledClientConfiguration.java | 3 +- .../server/ApacheShiroIniConfiguration.java | 18 +- .../server/CachingSecurityRepository.java | 2 +- ...eIntegratedSecurityProxyConfiguration.java | 25 ++- .../server/JdbcSecurityRepository.java | 45 ++--- .../server/SecurityEnabledServer.java | 15 +- .../SecurityEnabledServerConfiguration.java | 32 ++-- .../security/server/SecurityManagerProxy.java | 46 ++--- .../server/SecurityManagerSupport.java | 1 - .../security/server/SecurityRepository.java | 7 +- .../server/SimpleSecurityManager.java | 17 +- .../SecurityEnabledClientShiroTests.java | 48 +++-- .../client/SecurityEnabledClientTests.java | 51 +++-- geode/storage/pom.xml | 30 +-- .../geode/server/storage/Address.java | 2 +- .../geode/server/storage/Customer.java | 3 +- .../server/storage/CustomerRepository.java | 4 +- .../geode/server/storage/EmailAddress.java | 4 +- .../geode/server/storage/LineItem.java | 3 +- .../geode/server/storage/Order.java | 12 +- .../geode/server/storage/OrderRepository.java | 7 +- .../geode/server/storage/Product.java | 1 - .../server/storage/ProductRepository.java | 7 +- .../geode/server/storage/StorageServer.java | 69 +++---- .../server/storage/StorageServerConfig.java | 21 +- .../server/storage/StorageServerTests.java | 38 ++-- geode/transactions/pom.xml | 20 +- .../geode/client/transactions/Customer.java | 3 +- .../client/transactions/EmailAddress.java | 4 +- .../client/CustomerRepository.java | 12 +- .../transactions/client/CustomerService.java | 41 ++-- .../client/TransactionalClientConfig.java | 10 +- .../server/CustomerTransactionListener.java | 17 +- .../server/CustomerTransactionWriter.java | 16 +- .../server/TransactionalServer.java | 15 +- .../server/TransactionalServerConfig.java | 6 +- .../client/TransactionalClientTests.java | 49 +++-- geode/wan/pom.xml | 36 ++-- .../geode/server/wan/event/Customer.java | 3 +- .../server/wan/event/CustomerRepository.java | 7 +- .../geode/server/wan/event/EmailAddress.java | 4 +- .../server/EvenNumberedKeyWanEventFilter.java | 8 +- .../server/WanEventSubstitutionFilter.java | 9 +- .../server/wan/event/server/WanServer.java | 36 ++-- .../wan/event/server/WanServerConfig.java | 42 ++-- .../WanTransportEncryptionListener.java | 22 ++- .../siteA/SiteAWanEnabledServerConfig.java | 13 +- .../server/siteB/SiteBWanServerConfig.java | 22 ++- .../server/wan/event/WanServerTests.java | 55 +++--- .../wan/event/client/WanClientConfig.java | 15 +- 121 files changed, 1160 insertions(+), 1092 deletions(-) diff --git a/README.md b/README.md index f9854851..c810429f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,19 @@ This repository contains example projects for the different Spring Data modules We have separate folders for the samples of individual modules: +## Spring Data for Apache Cassandra + +* `example` - Shows core Spring Data support for Apache Cassandra. +* `java8` - Java 8 specific functionality like the support for JSR-310 types in object mapping. +* `kotlin` - Example for using Cassandra with Kotlin. +* `reactive` - Example project to show reactive template and repository support. + +## Spring Data Elasticsearch + +* `example` - Example how to use basic text search, geo-spatial search and facets. +* `rest` - Example how to use the High Level REST Client backing template and repository. +* `reactive` - Example how to use reactive client, template and repository features. + ## Spring Data for Apache Geode * `events` - In this example the test will make use of event handlers and async event queue to handle events. @@ -17,6 +30,10 @@ We have separate folders for the samples of individual modules: * `transactions` - In this example the client will perform operations within a transaction. First, it will do a successful transaction where entries are saved to the server, and then a failed transaction where all changes are reverted. * `wan` - In these example two servers are deployed. One server populates itself with data, and the other server gets populated with that data via WAN replication. +## Spring Data JDBC + +* `basic` - Basic usage of Spring Data JDBC. + ## Spring Data JPA * `eclipselink` - Sample project to show how to use Spring Data JPA with Spring Boot and [Eclipselink](https://www.eclipse.org/eclipselink/). @@ -30,6 +47,10 @@ We have separate folders for the samples of individual modules: * `showcase` - Refactoring show case of how to improve a plain-JPA-based persistence layer by using Spring Data JPA (read: removing close to all of the implementation code). Follow the `demo.txt` file for detailed instructions. * `vavr` - Shows the support of [Vavr](https://www.vavr.io) collection types as return types for query methods. +## Spring Data LDAP + +* `example` - Sample for Spring Data repositories to access an LDAP store. + ## Spring Data MongoDB * `aggregation` - Example project to showcase the MongoDB aggregation framework support. @@ -46,14 +67,13 @@ We have separate folders for the samples of individual modules: * `text-search` - Example project showing usage of MongoDB text search feature. * `transactions` - Example project for imperative and reactive MongoDB 4.0 transaction support. -## Spring Data REST +## Spring Data Neo4j -* `headers` - A sample showing the population of HTTP headers and the usage of them to perform conditional `GET` requests. -* `multi-store` - A sample REST web-service based on both Spring Data JPA and Spring Data MongoDB. -* `projections` - A sample REST web-service showing how to use projections. -* `security` - A sample REST web-service secured using Spring Security. -* `starbucks` - A sample REST web-service built with Spring Data REST and MongoDB. -* `uri-customizations` - Example project to show URI customization capabilities. +* `example` - Example to show basic node and relationship entities and repository usage. + +## Spring Data R2DBC + +* `example` - Basic usage of Spring Data R2DBC. ## Spring Data Redis @@ -64,46 +84,26 @@ We have separate folders for the samples of individual modules: * `sentinel` - Example for Redis Sentinel support. * `streams` - Example for [Redis Streams](https://redis.io/topics/streams-intro) support. +## Spring Data REST + +* `headers` - A sample showing the population of HTTP headers and the usage of them to perform conditional `GET` requests. +* `multi-store` - A sample REST web-service based on both Spring Data JPA and Spring Data MongoDB. +* `projections` - A sample REST web-service showing how to use projections. +* `security` - A sample REST web-service secured using Spring Security. +* `starbucks` - A sample REST web-service built with Spring Data REST and MongoDB. +* `uri-customizations` - Example project to show URI customization capabilities. + ## Spring Data for Apache Solr * `example` - Example project for Spring Data repositories for Apache Solr. * `managed-schema` - Example project to show managed schema integration. -## Spring Data Elasticsearch - -* `example` - Example how to use basic text search, geo-spatial search and facets. -* `rest` - Example how to use the High Level REST Client backing template and repository. -* `reactive` - Example how to use reactive client, template and repository features. - -## Spring Data Neo4j - -* `example` - Example to show basic node and relationship entities and repository usage. - ## Spring Data web support * `projections` - Example for Spring Data web support for JSONPath and XPath expressions on projection interfaces. * `querydsl` - Example for Spring Data Querydsl web integration (creating a `Predicate` from web requests). * `web` - Example for Spring Data web integration (binding `Pageable` instances to Spring MVC controller methods, using interfaces to bind Spring MVC request payloads). -## Spring Data for Apache Cassandra - -* `example` - Shows core Spring Data support for Apache Cassandra. -* `java8` - Java 8 specific functionality like the support for JSR-310 types in object mapping. -* `kotlin` - Example for using Cassandra with Kotlin. -* `reactive` - Example project to show reactive template and repository support. - -## Spring Data LDAP - -* `example` - Sample for Spring Data repositories to access an LDAP store. - -## Spring Data JDBC - -* `basic` - Basic usage of Spring Data JDBC. - -## Spring Data R2DBC - -* `example` - Basic usage of Spring Data R2DBC. - ## Miscellaneous * `bom` - Example project how to use the Spring Data release train bom in non-Spring-Boot scenarios. diff --git a/geode/events/pom.xml b/geode/events/pom.xml index d7c2c297..51c10ee5 100755 --- a/geode/events/pom.xml +++ b/geode/events/pom.xml @@ -2,16 +2,14 @@ - - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - - 4.0.0 - events + 4.0.0 - + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + - + events - \ No newline at end of file + diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/Address.java b/geode/events/src/main/java/example/springdata/geode/server/events/Address.java index 5f8b8007..47300101 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/Address.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/Address.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; @@ -29,6 +28,7 @@ import java.io.Serializable; */ @Data public class Address implements Serializable { + private String street; private String city; private String country; diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/Customer.java b/geode/events/src/main/java/example/springdata/geode/server/events/Customer.java index 1be4fe37..8fb20343 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/Customer.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; @@ -48,4 +47,4 @@ public class Customer implements Serializable { this.lastName = lastName; this.addresses = Arrays.asList(addresses); } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/CustomerCacheWriter.java b/geode/events/src/main/java/example/springdata/geode/server/events/CustomerCacheWriter.java index 8f31e674..11cfc198 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/CustomerCacheWriter.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/CustomerCacheWriter.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import org.apache.geode.cache.CacheWriterException; @@ -22,6 +21,9 @@ import org.apache.geode.cache.util.CacheWriterAdapter; import org.apache.geode.internal.cache.EntryEventImpl; import org.springframework.stereotype.Component; +/** + * @author Patrick Johnson + */ @Component public class CustomerCacheWriter extends CacheWriterAdapter { diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/CustomerRepository.java b/geode/events/src/main/java/example/springdata/geode/server/events/CustomerRepository.java index 42b321a4..1613b694 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/CustomerRepository.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/CustomerRepository.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import org.springframework.data.repository.CrudRepository; +/** + * @author Patrick Johnson + */ public interface CustomerRepository extends CrudRepository { } diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/EmailAddress.java b/geode/events/src/main/java/example/springdata/geode/server/events/EmailAddress.java index 501f222b..1fc0b8ac 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/EmailAddress.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; @@ -28,10 +27,11 @@ import java.io.Serializable; */ @Data public class EmailAddress implements Serializable { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/EventServer.java b/geode/events/src/main/java/example/springdata/geode/server/events/EventServer.java index c687d8d6..3471f5a8 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/EventServer.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/EventServer.java @@ -13,40 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; -import org.apache.geode.cache.Region; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.ApplicationRunner; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Bean; - import java.math.BigDecimal; import java.util.List; import java.util.Random; import java.util.stream.IntStream; import java.util.stream.LongStream; -@SpringBootApplication(scanBasePackageClasses = EventServerConfig.class) +import lombok.extern.apachecommons.CommonsLog; +import org.apache.geode.cache.Region; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Bean; + +/** + * @author Patrick Johnson + */ +@SpringBootApplication +@CommonsLog public class EventServer { - private Logger logger = LoggerFactory.getLogger(this.getClass()); - public static void main(String[] args) { - new SpringApplicationBuilder(EventServer.class) - .web(WebApplicationType.NONE) - .build() - .run(args); + new SpringApplicationBuilder(EventServer.class).web(WebApplicationType.NONE).build().run(args); } @Bean public ApplicationRunner runner(CustomerRepository customerRepository, OrderRepository orderRepository, - ProductRepository productRepository, OrderProductSummaryRepository orderProductSummaryRepository, @Qualifier("Products") Region products) { + ProductRepository productRepository, OrderProductSummaryRepository orderProductSummaryRepository, + @Qualifier("Products") Region products) { return args -> { createCustomerData(customerRepository); @@ -54,43 +55,37 @@ public class EventServer { createOrders(productRepository, orderRepository); - logger.info("Completed creating orders "); + log.info("Completed creating orders "); - final List allForProductID = orderProductSummaryRepository.findAllForProductID(3L); - allForProductID.forEach(orderProductSummary -> logger.info("orderProductSummary = " + orderProductSummary)); + List allForProductID = orderProductSummaryRepository.findAllForProductID(3L); + allForProductID.forEach(orderProductSummary -> log.info("orderProductSummary = " + orderProductSummary)); }; } private void createOrders(ProductRepository productRepository, OrderRepository orderRepository) { Random random = new Random(System.nanoTime()); Address address = new Address("it", "doesn't", "matter"); - LongStream.rangeClosed(1, 10).forEach((orderId) -> - LongStream.rangeClosed(1, 300).forEach((customerId) -> { - Order order = new Order(orderId, customerId, address); - IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> { - int quantity = random.nextInt(3) + 1; - long productId = random.nextInt(3) + 1; - order.add(new LineItem(productRepository.findById(productId).get(), quantity)); - }); - orderRepository.save(order); - })); + LongStream.rangeClosed(1, 10).forEach((orderId) -> LongStream.rangeClosed(1, 300).forEach((customerId) -> { + Order order = new Order(orderId, customerId, address); + IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> { + int quantity = random.nextInt(3) + 1; + long productId = random.nextInt(3) + 1; + order.add(new LineItem(productRepository.findById(productId).get(), quantity)); + }); + orderRepository.save(order); + })); } private void createProducts(ProductRepository productRepository) { - productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), - "An Apple portable music player")); - productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), - "An Apple tablet device")); - Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), - "An Apple notebook computer"); + productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), "An Apple portable music player")); + productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), "An Apple tablet device")); + Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), "An Apple notebook computer"); macbook.addAttribute("warranty", "included"); productRepository.save(macbook); } private void createCustomerData(CustomerRepository customerRepository) { - LongStream.rangeClosed(0, 300) - .parallel() - .forEach(customerId -> - customerRepository.save(new Customer(customerId, new EmailAddress(customerId + "@2.com"), "John" + customerId, "Smith" + customerId))); + LongStream.rangeClosed(0, 300).parallel().forEach(customerId -> customerRepository.save( + new Customer(customerId, new EmailAddress(customerId + "@2.com"), "John" + customerId, "Smith" + customerId))); } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/EventServerConfig.java b/geode/events/src/main/java/example/springdata/geode/server/events/EventServerConfig.java index f1c240c7..abc77899 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/EventServerConfig.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/EventServerConfig.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import org.apache.geode.cache.Cache; @@ -48,7 +47,7 @@ public class EventServerConfig { @Bean AsyncEventQueueFactoryBean orderAsyncEventQueue(GemFireCache gemFireCache, AsyncEventListener orderAsyncEventListener) { - final AsyncEventQueueFactoryBean asyncEventQueueFactoryBean = new AsyncEventQueueFactoryBean((Cache) gemFireCache); + AsyncEventQueueFactoryBean asyncEventQueueFactoryBean = new AsyncEventQueueFactoryBean((Cache) gemFireCache); asyncEventQueueFactoryBean.setBatchTimeInterval(1000); asyncEventQueueFactoryBean.setBatchSize(5); asyncEventQueueFactoryBean.setAsyncEventListener(orderAsyncEventListener); @@ -57,7 +56,7 @@ public class EventServerConfig { @Bean(name = "OrderProductSummary") PartitionedRegionFactoryBean createOrderProductSummaryRegion(GemFireCache gemFireCache) { - final PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); + PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); partitionedRegionFactoryBean.setCache(gemFireCache); partitionedRegionFactoryBean.setRegionName("OrderProductSummary"); partitionedRegionFactoryBean.setDataPolicy(DataPolicy.PARTITION); @@ -66,7 +65,7 @@ public class EventServerConfig { @Bean("Orders") PartitionedRegionFactoryBean createOrderRegion(GemFireCache gemFireCache, AsyncEventQueue orderAsyncEventQueue) { - final PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); + PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); partitionedRegionFactoryBean.setCache(gemFireCache); partitionedRegionFactoryBean.setRegionName("Orders"); partitionedRegionFactoryBean.setDataPolicy(DataPolicy.PARTITION); @@ -77,7 +76,7 @@ public class EventServerConfig { @Bean("Products") ReplicatedRegionFactoryBean createProductRegion(GemFireCache gemFireCache, CacheListener loggingCacheListener, CacheLoader productCacheLoader) { - final ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); + ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); replicatedRegionFactoryBean.setCache(gemFireCache); replicatedRegionFactoryBean.setRegionName("Products"); replicatedRegionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); @@ -90,7 +89,7 @@ public class EventServerConfig { ReplicatedRegionFactoryBean createCustomerRegion(GemFireCache gemFireCache, CacheWriter customerCacheWriter, CacheListener loggingCacheListener) { - final ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); + ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); replicatedRegionFactoryBean.setCache(gemFireCache); replicatedRegionFactoryBean.setRegionName("Customers"); replicatedRegionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); @@ -98,4 +97,4 @@ public class EventServerConfig { replicatedRegionFactoryBean.setCacheWriter(customerCacheWriter); return replicatedRegionFactoryBean; } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/LineItem.java b/geode/events/src/main/java/example/springdata/geode/server/events/LineItem.java index 0d353247..fba6241d 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/LineItem.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/LineItem.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; @@ -45,4 +44,4 @@ public class LineItem implements Serializable { public Long getProductId() { return product.getId(); } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/LoggingCacheListener.java b/geode/events/src/main/java/example/springdata/geode/server/events/LoggingCacheListener.java index eb669e8b..aeeb4ff3 100644 --- a/geode/events/src/main/java/example/springdata/geode/server/events/LoggingCacheListener.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/LoggingCacheListener.java @@ -13,32 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; +import lombok.extern.apachecommons.CommonsLog; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.geode.cache.EntryEvent; import org.apache.geode.cache.util.CacheListenerAdapter; import org.springframework.stereotype.Component; +/** + * @author Patrick Johnson + */ @Component +@CommonsLog public class LoggingCacheListener extends CacheListenerAdapter { - private Log logger = LogFactory.getLog(LoggingCacheListener.class); @Override public void afterCreate(EntryEvent event) { - logger.info("In region [" + event.getRegion().getName() + "] created key [" + event.getKey() + "] value [" + event.getNewValue() + "]"); + log.info("In region [" + event.getRegion().getName() + "] created key [" + event.getKey() + "] value [" + + event.getNewValue() + "]"); } @Override public void afterDestroy(EntryEvent event) { - logger.info("In region [" + event.getRegion().getName() + "] destroyed key [" + event.getKey() + "] "); + log.info("In region [" + event.getRegion().getName() + "] destroyed key [" + event.getKey() + "] "); } @Override public void afterUpdate(EntryEvent event) { - logger.info("In region [" + event.getRegion().getName() + "] updated key [" + event.getNewValue() + "] [oldValue [" + event.getOldValue() + "]] new value [" + event.getNewValue() + "]"); + log.info("In region [" + event.getRegion().getName() + "] updated key [" + event.getNewValue() + "] [oldValue [" + + event.getOldValue() + "]] new value [" + event.getNewValue() + "]"); } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/Order.java b/geode/events/src/main/java/example/springdata/geode/server/events/Order.java index 9ff04a20..3847fd07 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/Order.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/Order.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; @@ -34,6 +33,7 @@ import java.util.List; @Data @Region("Orders") public class Order implements Serializable { + @Id private Long id; private Long customerId; @@ -69,4 +69,4 @@ public class Order implements Serializable { public void add(LineItem lineItem) { lineItems.add(lineItem); } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/OrderAsyncQueueListener.java b/geode/events/src/main/java/example/springdata/geode/server/events/OrderAsyncQueueListener.java index 37dbee2a..80469324 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/OrderAsyncQueueListener.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/OrderAsyncQueueListener.java @@ -13,17 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.geode.cache.Region; import org.apache.geode.cache.asyncqueue.AsyncEvent; import org.apache.geode.cache.asyncqueue.AsyncEventListener; -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.List; - +/** + * @author Patrick Johnson + */ public class OrderAsyncQueueListener implements AsyncEventListener { private Region summaryRegion; @@ -34,9 +37,9 @@ public class OrderAsyncQueueListener implements AsyncEventListener { @Override public boolean processEvents(List list) { - HashMap summaryMap = new HashMap<>(); + Map summaryMap = new HashMap<>(); list.forEach(asyncEvent -> { - final Order order = (Order) asyncEvent.getDeserializedValue(); + Order order = (Order) asyncEvent.getDeserializedValue(); if (order != null) { order.getLineItems().forEach(lineItem -> { OrderProductSummary orderProductSummary = summaryMap.get(lineItem.getProductId()); @@ -50,14 +53,15 @@ public class OrderAsyncQueueListener implements AsyncEventListener { }); summaryMap.forEach((orderProductSummaryKey, orderProductSummary) -> { - final OrderProductSummary productSummary = summaryRegion.get(orderProductSummaryKey); + OrderProductSummary productSummary = summaryRegion.get(orderProductSummaryKey); if (productSummary != null) { - final BigDecimal newSummaryAmount = productSummary.getSummaryAmount().add(orderProductSummary.getSummaryAmount()); + BigDecimal newSummaryAmount = productSummary.getSummaryAmount().add(orderProductSummary.getSummaryAmount()); summaryRegion.put(orderProductSummaryKey, new OrderProductSummary(orderProductSummaryKey, newSummaryAmount)); } else { summaryRegion.put(orderProductSummaryKey, orderProductSummary); } }); + return true; } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummary.java b/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummary.java index f27512bd..b5c8e800 100644 --- a/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummary.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummary.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; @@ -43,4 +42,4 @@ public class OrderProductSummary implements Serializable { this.summaryKey = summaryKey; this.summaryAmount = summaryAmount; } -} \ No newline at end of file +} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummaryRepository.java b/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummaryRepository.java index eb1525d4..d2d8f256 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummaryRepository.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/OrderProductSummaryRepository.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; +import java.util.List; + import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.gemfire.repository.Query; import org.springframework.data.gemfire.repository.query.annotation.Hint; import org.springframework.data.repository.CrudRepository; -import java.util.List; - +/** + * @author Patrick Johnson + */ @Region("OrderProductSummary") public interface OrderProductSummaryRepository extends CrudRepository { @Hint("emailAddressIndex") diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/OrderRepository.java b/geode/events/src/main/java/example/springdata/geode/server/events/OrderRepository.java index be877760..6d391f09 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/OrderRepository.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/OrderRepository.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import org.springframework.data.repository.CrudRepository; -public interface OrderRepository extends CrudRepository { -} +/** + * @author Patrick Johnson + */ +public interface OrderRepository extends CrudRepository {} diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/Product.java b/geode/events/src/main/java/example/springdata/geode/server/events/Product.java index e9cb21e2..18c456c0 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/Product.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/Product.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import lombok.Data; diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/ProductCacheLoader.java b/geode/events/src/main/java/example/springdata/geode/server/events/ProductCacheLoader.java index 6aca0394..8d31fa1f 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/ProductCacheLoader.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/ProductCacheLoader.java @@ -13,17 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; -import com.github.javafaker.Faker; +import lombok.SneakyThrows; + +import java.math.BigDecimal; +import java.text.DecimalFormat; + import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.LoaderHelper; + import org.springframework.stereotype.Component; -import java.math.BigDecimal; +import com.github.javafaker.Faker; +/** + * @author Patrick Johnson + */ @Component public class ProductCacheLoader implements CacheLoader { private Faker faker = new Faker(); @@ -33,8 +40,9 @@ public class ProductCacheLoader implements CacheLoader { return new Product((long) loaderHelper.getKey(), randomStringName(), randomPrice(), ""); } + @SneakyThrows private BigDecimal randomPrice() { - return new BigDecimal(faker.commerce().price()); + return new BigDecimal(new DecimalFormat("#0.00").parse(faker.commerce().price()).toString()); } private String randomStringName() { diff --git a/geode/events/src/main/java/example/springdata/geode/server/events/ProductRepository.java b/geode/events/src/main/java/example/springdata/geode/server/events/ProductRepository.java index 4f28a25f..efb9484d 100755 --- a/geode/events/src/main/java/example/springdata/geode/server/events/ProductRepository.java +++ b/geode/events/src/main/java/example/springdata/geode/server/events/ProductRepository.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; import org.springframework.data.repository.CrudRepository; -public interface ProductRepository extends CrudRepository { -} +/** + * @author Patrick Johnson + */ +public interface ProductRepository extends CrudRepository {} diff --git a/geode/events/src/test/java/example/springdata/geode/server/events/EventServerTests.java b/geode/events/src/test/java/example/springdata/geode/server/events/EventServerTests.java index d6840d81..f93c9e91 100755 --- a/geode/events/src/test/java/example/springdata/geode/server/events/EventServerTests.java +++ b/geode/events/src/test/java/example/springdata/geode/server/events/EventServerTests.java @@ -13,32 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.events; +import static org.assertj.core.api.Assertions.*; + import org.apache.geode.cache.Cache; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; - +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = EventServer.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest public class EventServerTests { - @Autowired - Cache cache; + @Autowired Cache cache; - @Autowired - private ProductRepository productRepository; + @Autowired private ProductRepository productRepository; - @Autowired - private OrderProductSummaryRepository orderProductSummaryRepository; + @Autowired private OrderProductSummaryRepository orderProductSummaryRepository; @Test public void asyncEventQueueEasConfiguredCorrectly() { @@ -47,9 +45,12 @@ public class EventServerTests { @Test public void productCacheLoaderWorks() { + long size = productRepository.count(); + assertThat(this.productRepository.findById(777L)).isNotNull(); assertThat(productRepository.count()).isEqualTo(size + 1); + productRepository.deleteById(777L); } -} \ No newline at end of file +} diff --git a/geode/expiration-eviction/pom.xml b/geode/expiration-eviction/pom.xml index 6d1bd957..7d15c469 100755 --- a/geode/expiration-eviction/pom.xml +++ b/geode/expiration-eviction/pom.xml @@ -2,22 +2,22 @@ - - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - - 4.0.0 + 4.0.0 - expiration-eviction + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + - - - com.jayway.awaitility - awaitility - 1.7.0 - - + expiration-eviction + + + org.awaitility + awaitility + test + + - \ No newline at end of file + diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Address.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Address.java index 330611ca..a92bedc9 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Address.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Address.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import lombok.Data; @@ -29,6 +28,7 @@ import java.io.Serializable; */ @Data public class Address implements Serializable { + private String street; private String city; private String country; diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomCustomerExpiry.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomCustomerExpiry.java index 9f68657a..ceccc560 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomCustomerExpiry.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomCustomerExpiry.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import org.apache.geode.cache.CustomExpiry; @@ -21,10 +20,12 @@ import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.Region; - +/** + * @author Patrick Johnson + */ public class CustomCustomerExpiry implements CustomExpiry { - private int timeout; + private final int timeout; public CustomCustomerExpiry(int timeout) { this.timeout = timeout; @@ -37,4 +38,4 @@ public class CustomCustomerExpiry implements CustomExpiry { } return null; } -} \ No newline at end of file +} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Customer.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Customer.java index 7da9f4c3..260a9037 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Customer.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import lombok.Data; @@ -48,4 +47,4 @@ public class Customer implements Serializable { this.lastName = lastName; this.addresses = Arrays.asList(addresses); } -} \ No newline at end of file +} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomerRepository.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomerRepository.java index a0d0f0d8..8de6532b 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomerRepository.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/CustomerRepository.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.repository.CrudRepository; +/** + * @author Patrick Johnson + */ @Region("Customers") -public interface CustomerRepository extends CrudRepository { -} +public interface CustomerRepository extends CrudRepository {} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/EmailAddress.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/EmailAddress.java index 6d3780b9..145cacab 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/EmailAddress.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import lombok.Data; @@ -28,10 +27,11 @@ import java.io.Serializable; */ @Data public class EmailAddress implements Serializable { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServer.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServer.java index e1ec74c8..fb1fd4db 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServer.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServer.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -@SpringBootApplication(scanBasePackageClasses = ExpirationEvictionServerConfig.class) +/** + * @author Patrick Johnson + */ +@SpringBootApplication public class ExpirationEvictionServer { public static void main(String[] args) { diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerConfig.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerConfig.java index 8e574900..2321bdf8 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerConfig.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerConfig.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; -import com.github.javafaker.Faker; import org.apache.geode.cache.CustomExpiry; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Scope; + import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,16 +33,19 @@ import org.springframework.data.gemfire.eviction.EvictionActionType; import org.springframework.data.gemfire.eviction.EvictionPolicyType; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; +import com.github.javafaker.Faker; + +/** + * @author Patrick Johnson + */ @Configuration @CacheServerApplication(logLevel = "error") @EnableLocator @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) @EnableExpiration @Import(ExpirationPolicyConfig.class) -@EnableEviction(policies = @EnableEviction.EvictionPolicy(regionNames = "Orders", - maximum = 10, - action = EvictionActionType.LOCAL_DESTROY, - type = EvictionPolicyType.ENTRY_COUNT)) +@EnableEviction(policies = @EnableEviction.EvictionPolicy(regionNames = "Orders", maximum = 10, + action = EvictionActionType.LOCAL_DESTROY, type = EvictionPolicyType.ENTRY_COUNT)) public class ExpirationEvictionServerConfig { @Bean @@ -63,9 +65,9 @@ public class ExpirationEvictionServerConfig { @Bean("Products") public ReplicatedRegionFactoryBean createProductRegion(GemFireCache gemFireCache, - @Qualifier("IDLE") CustomExpiry idleExpiry, - @Qualifier("TTL") CustomExpiry ttlExpiry) { - final ReplicatedRegionFactoryBean regionFactoryBean = new ReplicatedRegionFactoryBean<>(); + @Qualifier("IDLE") CustomExpiry idleExpiry, + @Qualifier("TTL") CustomExpiry ttlExpiry) { + ReplicatedRegionFactoryBean regionFactoryBean = new ReplicatedRegionFactoryBean<>(); regionFactoryBean.setCache(gemFireCache); regionFactoryBean.setScope(Scope.DISTRIBUTED_ACK); regionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); @@ -77,7 +79,7 @@ public class ExpirationEvictionServerConfig { @Bean("Customers") public ReplicatedRegionFactoryBean createCustomerRegion(GemFireCache gemFireCache) { - final ReplicatedRegionFactoryBean regionFactoryBean = new ReplicatedRegionFactoryBean<>(); + ReplicatedRegionFactoryBean regionFactoryBean = new ReplicatedRegionFactoryBean<>(); regionFactoryBean.setCache(gemFireCache); regionFactoryBean.setScope(Scope.DISTRIBUTED_ACK); regionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); @@ -87,7 +89,7 @@ public class ExpirationEvictionServerConfig { @Bean("Orders") public ReplicatedRegionFactoryBean createOrderRegion(GemFireCache gemFireCache) { - final ReplicatedRegionFactoryBean regionFactoryBean = new ReplicatedRegionFactoryBean<>(); + ReplicatedRegionFactoryBean regionFactoryBean = new ReplicatedRegionFactoryBean<>(); regionFactoryBean.setCache(gemFireCache); regionFactoryBean.setScope(Scope.DISTRIBUTED_ACK); regionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationPolicyConfig.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationPolicyConfig.java index ea5b5cdf..4cd30678 100644 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationPolicyConfig.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ExpirationPolicyConfig.java @@ -20,12 +20,14 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.gemfire.config.annotation.EnableExpiration; import org.springframework.data.gemfire.expiration.ExpirationActionType; +/** + * @author Patrick Johnson + */ @Profile("!default") @Configuration @EnableExpiration(policies = { - @EnableExpiration.ExpirationPolicy(timeout = 4, action = ExpirationActionType.DESTROY, - regionNames = {"Customers"}, types = {EnableExpiration.ExpirationType.TIME_TO_LIVE}), @EnableExpiration.ExpirationPolicy(timeout = 2, action = ExpirationActionType.DESTROY, - regionNames = {"Customers"}, types = {EnableExpiration.ExpirationType.IDLE_TIMEOUT})}) -public class ExpirationPolicyConfig { -} + regionNames = { "Customers" }, types = { EnableExpiration.ExpirationType.TIME_TO_LIVE }), + @EnableExpiration.ExpirationPolicy(timeout = 1, action = ExpirationActionType.DESTROY, + regionNames = { "Customers" }, types = { EnableExpiration.ExpirationType.IDLE_TIMEOUT }) }) +public class ExpirationPolicyConfig {} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Order.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Order.java index 1cde9eb5..f24277a6 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Order.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Order.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import lombok.Data; @@ -31,10 +30,11 @@ import java.io.Serializable; * @author Patrick Johnson */ @Data -@IdleTimeoutExpiration(action = "DESTROY", timeout = "2") -@TimeToLiveExpiration(action = "DESTROY", timeout = "4") +@IdleTimeoutExpiration(action = "DESTROY", timeout = "1") +@TimeToLiveExpiration(action = "DESTROY", timeout = "2") @Region("Orders") public class Order implements Serializable { + @Id private Long id; private Long total; @@ -47,4 +47,4 @@ public class Order implements Serializable { this.billingAddress = address; this.shippingAddress = address; } -} \ No newline at end of file +} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/OrderRepository.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/OrderRepository.java index 3f8d18cf..5e7787f5 100644 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/OrderRepository.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/OrderRepository.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.repository.CrudRepository; +/** + * @author Patrick Johnson + */ @Region("Orders") -public interface OrderRepository extends CrudRepository { -} +public interface OrderRepository extends CrudRepository {} diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Product.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Product.java index 9b766c0d..6c46ed4d 100755 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Product.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/Product.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import lombok.Data; diff --git a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ProductRepository.java b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ProductRepository.java index 49f5d48d..51682fd9 100644 --- a/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ProductRepository.java +++ b/geode/expiration-eviction/src/main/java/example/springdata/geode/server/expiration/eviction/ProductRepository.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; import org.springframework.data.repository.CrudRepository; -public interface ProductRepository extends CrudRepository { -} +/** + * @author Patrick Johnson + */ +public interface ProductRepository extends CrudRepository {} diff --git a/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/EntityDefinedExpirationTests.java b/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/EntityDefinedExpirationTests.java index 209b9fd3..b3f656d5 100644 --- a/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/EntityDefinedExpirationTests.java +++ b/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/EntityDefinedExpirationTests.java @@ -15,70 +15,68 @@ */ package example.springdata.geode.server.expiration.eviction; -import com.github.javafaker.Faker; -import com.jayway.awaitility.Awaitility; +import static org.assertj.core.api.Assertions.*; + +import lombok.extern.apachecommons.CommonsLog; + +import java.time.Instant; +import java.util.concurrent.TimeUnit; + +import org.awaitility.Awaitility; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; +import com.github.javafaker.Faker; +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = ExpirationEvictionServer.class) +@SpringBootTest @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@CommonsLog public class EntityDefinedExpirationTests { - @Autowired - private OrderRepository orderRepository; + @Autowired private OrderRepository orderRepository; - @Autowired - Faker faker; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired Faker faker; @Test public void entityDefinedExpirationIsConfiguredCorrectly() { - orderRepository.save(new Order(1L, 50L, new Address(faker.address().streetAddress(), faker.address().city(), faker.address().country()))); + + orderRepository.save(new Order(1L, 50L, + new Address(faker.address().streetAddress(), faker.address().city(), faker.address().country()))); assertThat(orderRepository.count()).isEqualTo(1); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss:SSS"); - logger.info("Starting TTL wait period: " + simpleDateFormat.format(new Date())); - //Due to the constant "getting" of the entry, the idle expiry timeout will not be met and the time-to-live + log.info("Starting TTL wait period: " + Instant.now()); + // Due to the constant "getting" of the entry, the idle expiry timeout will not be met and the time-to-live // will be used. - Awaitility.await() - .pollInterval(1, TimeUnit.SECONDS) - .atMost(10, TimeUnit.SECONDS) + Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS) .until(() -> !orderRepository.findById(1L).isPresent()); assertThat(orderRepository.count()).isEqualTo(0); - logger.info("Ending TTL wait period: " + simpleDateFormat.format(new Date())); + log.info("Ending TTL wait period: " + Instant.now()); - orderRepository.save(new Order(1L, 50L, new Address(faker.address().streetAddress(), faker.address().city(), faker.address().country()))); + orderRepository.save(new Order(1L, 50L, + new Address(faker.address().streetAddress(), faker.address().city(), faker.address().country()))); assertThat(orderRepository.count()).isEqualTo(1); - logger.info("Starting Idle wait period: " + simpleDateFormat.format(new Date())); + log.info("Starting Idle wait period: " + Instant.now()); - //Due to the delay in "getting" the entry, the idle timeout of 2s should delete the entry. - Awaitility.await() - .pollDelay(2, TimeUnit.SECONDS) - .pollInterval(100, TimeUnit.MILLISECONDS) - .atMost(10, TimeUnit.SECONDS) - .until(() -> !orderRepository.findById(1L).isPresent()); + // Due to the delay in "getting" the entry, the idle timeout of 2s should delete the entry. + Awaitility.await().pollDelay(2, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS).until(() -> !orderRepository.findById(1L).isPresent()); assertThat(orderRepository.count()).isEqualTo(0); - logger.info("Ending Idle wait period: " + simpleDateFormat.format(new Date())); + log.info("Ending Idle wait period: " + Instant.now()); } } diff --git a/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerTests.java b/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerTests.java index 0b29c798..f3ef7a64 100755 --- a/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerTests.java +++ b/geode/expiration-eviction/src/test/java/example/springdata/geode/server/expiration/eviction/ExpirationEvictionServerTests.java @@ -13,68 +13,64 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.expiration.eviction; -import com.github.javafaker.Faker; -import com.jayway.awaitility.Awaitility; +import static org.assertj.core.api.Assertions.*; + +import lombok.extern.apachecommons.CommonsLog; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.concurrent.TimeUnit; + +import org.awaitility.Awaitility; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; +import com.github.javafaker.Faker; +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = ExpirationEvictionServer.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest(classes = ExpirationEvictionServer.class) @ActiveProfiles("expiration_policy") +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@CommonsLog public class ExpirationEvictionServerTests { - @Autowired - private CustomerRepository customerRepository; + @Autowired private CustomerRepository customerRepository; - @Autowired - private ProductRepository productRepository; + @Autowired private ProductRepository productRepository; - @Autowired - private OrderRepository orderRepository; + @Autowired private OrderRepository orderRepository; - @Autowired - Faker faker; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired Faker faker; @Test public void cacheDefinedExpirationIsConfiguredCorrectly() { + customerRepository.save(new Customer(1L, new EmailAddress(faker.internet().emailAddress()), faker.name().firstName(), faker.name().lastName(), new Address(faker.address().streetAddress(), faker.address().city(), faker.address().country()))); assertThat(customerRepository.count()).isEqualTo(1); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss:SSS"); - logger.info("Starting TTL wait period: " + simpleDateFormat.format(new Date())); - //Due to the constant "getting" of the entry, the idle expiry timeout will not be met and the time-to-live + log.info(String.format("Starting TTL wait period: %s", Instant.now())); + // Due to the constant "getting" of the entry, the idle expiry timeout will not be met and the time-to-live // will be used. - Awaitility.await() - .pollInterval(1, TimeUnit.SECONDS) - .atMost(10, TimeUnit.SECONDS) + Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS) .until(() -> !customerRepository.findById(1L).isPresent()); assertThat(customerRepository.count()).isEqualTo(0); - logger.info("Ending TTL wait period: " + simpleDateFormat.format(new Date())); + log.info(String.format("Ending TTL wait period: %s", Instant.now())); customerRepository.save(new Customer(1L, new EmailAddress(faker.internet().emailAddress()), faker.name().firstName(), faker.name().lastName(), @@ -82,18 +78,15 @@ public class ExpirationEvictionServerTests { assertThat(customerRepository.count()).isEqualTo(1); - logger.info("Starting Idle wait period: " + simpleDateFormat.format(new Date())); + log.info(String.format("Starting Idle wait period: %s", Instant.now())); - //Due to the delay in "getting" the entry, the idle timeout of 2s should delete the entry. - Awaitility.await() - .pollDelay(2, TimeUnit.SECONDS) - .pollInterval(100, TimeUnit.MILLISECONDS) - .atMost(10, TimeUnit.SECONDS) - .until(() -> !customerRepository.findById(1L).isPresent()); + // Due to the delay in "getting" the entry, the idle timeout of 2s should delete the entry. + Awaitility.await().pollDelay(2, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS).until(() -> !customerRepository.findById(1L).isPresent()); assertThat(customerRepository.count()).isEqualTo(0); - logger.info("Ending Idle wait period: " + simpleDateFormat.format(new Date())); + log.info(String.format("Ending Idle wait period: %s", Instant.now())); } @Test @@ -102,36 +95,29 @@ public class ExpirationEvictionServerTests { assertThat(productRepository.count()).isEqualTo(1); - - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss:SSS"); - logger.info("Starting TTL wait period: " + simpleDateFormat.format(new Date())); - //Due to the constant "getting" of the entry, the idle expiry timeout will not be met and the time-to-live + log.info(String.format("Starting TTL wait period: %s", Instant.now())); + // Due to the constant "getting" of the entry, the idle expiry timeout will not be met and the time-to-live // will be used. - Awaitility.await() - .pollInterval(1, TimeUnit.SECONDS) - .atMost(10, TimeUnit.SECONDS) + Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS) .until(() -> !productRepository.findById(3L).isPresent()); assertThat(productRepository.count()).isEqualTo(0); - logger.info("Ending TTL wait period: " + simpleDateFormat.format(new Date())); + log.info("Ending TTL wait period: " + Instant.now()); productRepository.save(new Product(3L, "MacBook Pro", BigDecimal.valueOf(20), "A cool computing device")); assertThat(productRepository.count()).isEqualTo(1); - logger.info("Starting Idle wait period: " + simpleDateFormat.format(new Date())); + log.info(String.format("Starting Idle wait period: %s", Instant.now())); - //Due to the delay in "getting" the entry, the idle timeout of 2s should delete the entry. - Awaitility.await() - .pollDelay(2, TimeUnit.SECONDS) - .pollInterval(100, TimeUnit.MILLISECONDS) - .atMost(10, TimeUnit.SECONDS) - .until(() -> !productRepository.findById(3L).isPresent()); + // Due to the delay in "getting" the entry, the idle timeout of 2s should delete the entry. + Awaitility.await().pollDelay(2, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS).until(() -> !productRepository.findById(3L).isPresent()); assertThat(productRepository.count()).isEqualTo(0); - logger.info("Ending Idle wait period: " + simpleDateFormat.format(new Date())); + log.info(String.format("Ending Idle wait period: %s", Instant.now())); } @Test @@ -139,10 +125,11 @@ public class ExpirationEvictionServerTests { final int evictionThreshold = 10; for (long i = 0; i < evictionThreshold + 1; i++) { - orderRepository.save(new Order(i, i, new Address(faker.address().streetName(), faker.address().city(), faker.address().country()))); + orderRepository.save(new Order(i, i, + new Address(faker.address().streetName(), faker.address().city(), faker.address().country()))); } assertThat(orderRepository.count()).isEqualTo(evictionThreshold); orderRepository.deleteAll(); } -} \ No newline at end of file +} diff --git a/geode/function-invocation/pom.xml b/geode/function-invocation/pom.xml index 79694888..7f4dc59d 100755 --- a/geode/function-invocation/pom.xml +++ b/geode/function-invocation/pom.xml @@ -2,17 +2,14 @@ - - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - - 4.0.0 - function-invocation - 1.0-SNAPSHOT + 4.0.0 - + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + - + function-invocation - \ No newline at end of file + diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Address.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Address.java index ccdf1fdd..74cb91d3 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Address.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Address.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function; import lombok.Data; @@ -29,6 +28,7 @@ import java.io.Serializable; */ @Data public class Address implements Serializable { + private String street; private String city; private String country; diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Customer.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Customer.java index e24b3d92..15eff178 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Customer.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function; import lombok.Data; @@ -55,4 +54,4 @@ public class Customer implements Serializable { public void add(Address address) { this.addresses.add(address); } -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/EmailAddress.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/EmailAddress.java index 145ed6d4..692f5fd9 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/EmailAddress.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function; import lombok.Data; @@ -28,10 +27,11 @@ import java.io.Serializable; */ @Data public class EmailAddress implements Serializable { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/LineItem.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/LineItem.java index 4055db5b..d3d8f966 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/LineItem.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/LineItem.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function; import lombok.Data; @@ -41,4 +40,4 @@ public class LineItem implements Serializable { public BigDecimal calcTotal() { return product.getPrice().multiply(BigDecimal.valueOf(amount)); } -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Order.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Order.java index 69550e8b..fe16f46c 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Order.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Order.java @@ -34,6 +34,7 @@ import java.util.List; @Data @Region("Orders") public class Order implements Serializable { + @Id private Long id; private Long customerId; @@ -70,4 +71,4 @@ public class Order implements Serializable { public void add(LineItem lineItem) { lineItems.add(lineItem); } -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Product.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Product.java index c10dfb0e..95c2c556 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Product.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/Product.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function; import lombok.Data; diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerFunctionExecutions.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerFunctionExecutions.java index 7ad8f320..16c73913 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerFunctionExecutions.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerFunctionExecutions.java @@ -13,18 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; import example.springdata.geode.client.function.Customer; -import org.springframework.data.gemfire.function.annotation.FunctionId; -import org.springframework.data.gemfire.function.annotation.OnRegion; import java.util.List; +import org.springframework.data.gemfire.function.annotation.FunctionId; +import org.springframework.data.gemfire.function.annotation.OnRegion; + +/** + * @author Patrick Johnson + */ @OnRegion(region = "Customers") public interface CustomerFunctionExecutions { @FunctionId("listConsumersForEmailAddressesFnc") List> listAllCustomersForEmailAddress(String... emailAddresses); -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerRepository.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerRepository.java index b2154535..89ca6c53 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerRepository.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/CustomerRepository.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; import example.springdata.geode.client.function.Customer; + +import java.util.List; + import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.repository.Query; import org.springframework.data.gemfire.repository.query.annotation.Hint; @@ -24,8 +26,9 @@ import org.springframework.data.gemfire.repository.query.annotation.Limit; import org.springframework.data.gemfire.repository.query.annotation.Trace; import org.springframework.data.repository.CrudRepository; -import java.util.List; - +/** + * @author Patrick Johnson + */ @ClientRegion("Customers") public interface CustomerRepository extends CrudRepository { @@ -39,4 +42,4 @@ public interface CustomerRepository extends CrudRepository { @Limit(100) @Query("select * from /Customers customer where customer.firstName = $1") List findByFirstNameUsingIndex(String firstName); -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/FunctionInvocationClientApplicationConfig.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/FunctionInvocationClientApplicationConfig.java index ddc0ff89..cf073ed1 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/FunctionInvocationClientApplicationConfig.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/FunctionInvocationClientApplicationConfig.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; import example.springdata.geode.client.function.Customer; import example.springdata.geode.client.function.Order; import example.springdata.geode.client.function.Product; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientRegionShortcut; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; @@ -35,11 +36,11 @@ import org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTra * @author Udo Kohlmeyer * @author Patrick Johnson */ - @Configuration @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) @EnableGemfireFunctionExecutions(basePackageClasses = CustomerFunctionExecutions.class) -@ClientCacheApplication(name = "FunctionInvocationClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1) +@ClientCacheApplication(name = "FunctionInvocationClient", logLevel = "error", pingInterval = 5000L, + readTimeout = 15000, retryAttempts = 1) @EnableGemfireCacheTransactions public class FunctionInvocationClientApplicationConfig { @@ -69,4 +70,4 @@ public class FunctionInvocationClientApplicationConfig { clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY); return clientRegionFactoryBean; } -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderFunctionExecutions.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderFunctionExecutions.java index 38c41541..c5407f2e 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderFunctionExecutions.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderFunctionExecutions.java @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; -import org.springframework.data.gemfire.function.annotation.FunctionId; -import org.springframework.data.gemfire.function.annotation.OnRegion; - import java.math.BigDecimal; import java.util.List; +import org.springframework.data.gemfire.function.annotation.FunctionId; +import org.springframework.data.gemfire.function.annotation.OnRegion; + +/** + * @author Patrick Johnson + */ @OnRegion(region = "Orders") public interface OrderFunctionExecutions { @FunctionId("sumPricesForAllProductsForOrderFnc") List sumPricesForAllProductsForOrder(Long orderId); -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderRepository.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderRepository.java index 22b80fc5..485ce7f4 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderRepository.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/OrderRepository.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; import example.springdata.geode.client.function.Order; + import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.repository.CrudRepository; +/** + * @author Patrick Johnson + */ @ClientRegion("Orders") -public interface OrderRepository extends CrudRepository { - -} +public interface OrderRepository extends CrudRepository {} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductFunctionExecutions.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductFunctionExecutions.java index ef9cac47..15e71e50 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductFunctionExecutions.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductFunctionExecutions.java @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; -import org.springframework.data.gemfire.function.annotation.FunctionId; -import org.springframework.data.gemfire.function.annotation.OnRegion; - import java.math.BigDecimal; import java.util.List; +import org.springframework.data.gemfire.function.annotation.FunctionId; +import org.springframework.data.gemfire.function.annotation.OnRegion; + +/** + * @author Patrick Johnson + */ @OnRegion(region = "Products") public interface ProductFunctionExecutions { @FunctionId("sumPricesForAllProductsFnc") List sumPricesForAllProducts(); -} \ No newline at end of file +} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductRepository.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductRepository.java index c7159880..109fc277 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductRepository.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/client/ProductRepository.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; import example.springdata.geode.client.function.Product; + import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.repository.CrudRepository; +/** + * @author Patrick Johnson + */ @ClientRegion("Products") -public interface ProductRepository extends CrudRepository { - -} +public interface ProductRepository extends CrudRepository {} diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/CustomerFunctions.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/CustomerFunctions.java index 48642fbc..4ad9e654 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/CustomerFunctions.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/CustomerFunctions.java @@ -13,25 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.server; import example.springdata.geode.client.function.Customer; -import org.springframework.data.gemfire.function.annotation.GemfireFunction; -import org.springframework.data.gemfire.function.annotation.RegionData; -import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.springframework.data.gemfire.function.annotation.GemfireFunction; +import org.springframework.data.gemfire.function.annotation.RegionData; +import org.springframework.stereotype.Component; + +/** + * @author Patrick Johnson + */ @Component public class CustomerFunctions { - @GemfireFunction(id = "listConsumersForEmailAddressesFnc", HA = true, optimizeForWrite = true, batchSize = 3, hasResult = true) + @GemfireFunction(id = "listConsumersForEmailAddressesFnc", HA = true, optimizeForWrite = true, batchSize = 3, + hasResult = true) public List listAllCustomersForEmailAddress(@RegionData Map customerData, - String... emailAddresses) { + String... emailAddresses) { List emailAddressesAsList = Arrays.asList(emailAddresses); List collect = customerData.values().parallelStream() .filter((customer) -> emailAddressesAsList.contains(customer.getEmailAddress().getValue())) diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServer.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServer.java index d93642ee..3327fd4d 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServer.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServer.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.server; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -@SpringBootApplication(scanBasePackageClasses = FunctionServerApplicationConfig.class) +/** + * @author Patrick Johnson + */ +@SpringBootApplication public class FunctionServer { public static void main(String[] args) { diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServerApplicationConfig.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServerApplicationConfig.java index 62830acb..5c1bf769 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServerApplicationConfig.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/FunctionServerApplicationConfig.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.server; import example.springdata.geode.client.function.Customer; import example.springdata.geode.client.function.Order; import example.springdata.geode.client.function.Product; import example.springdata.geode.client.function.client.CustomerRepository; + import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Scope; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -34,6 +35,9 @@ import org.springframework.data.gemfire.config.annotation.EnableManager; import org.springframework.data.gemfire.function.config.EnableGemfireFunctions; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; +/** + * @author Patrick Johnson + */ @Configuration @ComponentScan(basePackageClasses = CustomerFunctions.class) @EnableGemfireFunctions diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/OrderFunctions.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/OrderFunctions.java index 686395e6..09ba5e06 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/OrderFunctions.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/OrderFunctions.java @@ -13,17 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.server; import example.springdata.geode.client.function.Order; -import org.springframework.data.gemfire.function.annotation.GemfireFunction; -import org.springframework.data.gemfire.function.annotation.RegionData; -import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.Map; +import org.springframework.data.gemfire.function.annotation.GemfireFunction; +import org.springframework.data.gemfire.function.annotation.RegionData; +import org.springframework.stereotype.Component; + +/** + * @author Patrick Johnson + */ @Component public class OrderFunctions { diff --git a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/ProductFunctions.java b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/ProductFunctions.java index 8a9fda9e..77f155e6 100755 --- a/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/ProductFunctions.java +++ b/geode/function-invocation/src/main/java/example/springdata/geode/client/function/server/ProductFunctions.java @@ -13,21 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.server; import example.springdata.geode.client.function.Product; -import org.springframework.data.gemfire.function.annotation.GemfireFunction; -import org.springframework.data.gemfire.function.annotation.RegionData; -import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.Map; +import org.springframework.data.gemfire.function.annotation.GemfireFunction; +import org.springframework.data.gemfire.function.annotation.RegionData; +import org.springframework.stereotype.Component; + +/** + * @author Patrick Johnson + */ @Component public class ProductFunctions { - @GemfireFunction(id = "sumPricesForAllProductsFnc", HA = true, optimizeForWrite = false, hasResult = true) + @GemfireFunction(id = "sumPricesForAllProductsFnc", HA = true, hasResult = true) public BigDecimal sumPricesForAllProductsFnc(@RegionData Map productData) { return productData.values().stream().map(Product::getPrice).reduce(BigDecimal::add).get(); } diff --git a/geode/function-invocation/src/test/java/example/springdata/geode/client/function/client/FunctionInvocationClientTests.java b/geode/function-invocation/src/test/java/example/springdata/geode/client/function/client/FunctionInvocationClientTests.java index e2f60715..7462f928 100755 --- a/geode/function-invocation/src/test/java/example/springdata/geode/client/function/client/FunctionInvocationClientTests.java +++ b/geode/function-invocation/src/test/java/example/springdata/geode/client/function/client/FunctionInvocationClientTests.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.function.client; +import static org.assertj.core.api.Assertions.*; + import example.springdata.geode.client.function.Address; import example.springdata.geode.client.function.Customer; import example.springdata.geode.client.function.EmailAddress; @@ -23,19 +24,8 @@ import example.springdata.geode.client.function.LineItem; import example.springdata.geode.client.function.Order; import example.springdata.geode.client.function.Product; import example.springdata.geode.client.function.server.FunctionServer; -import org.apache.geode.cache.Region; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import lombok.extern.apachecommons.CommonsLog; -import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.util.List; @@ -43,41 +33,43 @@ import java.util.Random; import java.util.stream.IntStream; import java.util.stream.LongStream; -import static org.assertj.core.api.Assertions.assertThat; +import javax.annotation.Resource; +import org.apache.geode.cache.Region; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = FunctionInvocationClientApplicationConfig.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest(classes = FunctionInvocationClientApplicationConfig.class) +@CommonsLog public class FunctionInvocationClientTests extends ForkingClientServerIntegrationTestsSupport { - @Autowired - private CustomerRepository customerRepository; + @Autowired private CustomerRepository customerRepository; - @Autowired - private OrderRepository orderRepository; + @Autowired private OrderRepository orderRepository; - @Autowired - private ProductRepository productRepository; + @Autowired private ProductRepository productRepository; - @Autowired - private CustomerFunctionExecutions customerFunctionExecutions; + @Autowired private CustomerFunctionExecutions customerFunctionExecutions; - @Autowired - private OrderFunctionExecutions orderFunctionExecutions; + @Autowired private OrderFunctionExecutions orderFunctionExecutions; - @Autowired - private ProductFunctionExecutions productFunctionExecutions; + @Autowired private ProductFunctionExecutions productFunctionExecutions; - @Resource(name = "Customers") - private Region customers; + @Resource(name = "Customers") private Region customers; - @Resource(name = "Orders") - private Region orders; + @Resource(name = "Orders") private Region orders; - @Resource(name = "Products") - private Region products; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Resource(name = "Products") private Region products; @BeforeClass public static void setup() throws IOException { @@ -90,56 +82,60 @@ public class FunctionInvocationClientTests extends ForkingClientServerIntegratio List cust = customerFunctionExecutions.listAllCustomersForEmailAddress("2@2.com", "3@3.com").get(0); assertThat(cust.size()).isEqualTo(2); - logger.info("All customers for emailAddresses:3@3.com,2@2.com using function invocation: \n\t " + cust); + log.info("All customers for emailAddresses:3@3.com,2@2.com using function invocation: \n\t " + cust); createProducts(); BigDecimal sum = productFunctionExecutions.sumPricesForAllProducts().get(0); assertThat(sum).isEqualTo(BigDecimal.valueOf(1499.97)); - logger.info("Running function to sum up all product prices: \n\t" + sum); + log.info("Running function to sum up all product prices: \n\t" + sum); createOrders(); sum = orderFunctionExecutions.sumPricesForAllProductsForOrder(1L).get(0); assertThat(sum).isGreaterThanOrEqualTo(BigDecimal.valueOf(99.99)); - logger.info("Running function to sum up all order lineItems prices for order 1: \n\t" + sum); + log.info("Running function to sum up all order lineItems prices for order 1: \n\t" + sum); Order order = orderRepository.findById(1L).get(); - logger.info("For order: \n\t " + order); + log.info("For order: \n\t " + order); } public void createCustomerData() { - logger.info("Inserting 3 entries for keys: 1, 2, 3"); + log.info("Inserting 3 entries for keys: 1, 2, 3"); + customerRepository.save(new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith")); customerRepository.save(new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport")); customerRepository.save(new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons")); + assertThat(customers.keySetOnServer().size()).isEqualTo(3); } public void createProducts() { - productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), - "An Apple portable music player")); - productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), - "An Apple tablet device")); - Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), - "An Apple notebook computer"); + + productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), "An Apple portable music player")); + productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), "An Apple tablet device")); + Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), "An Apple notebook computer"); macbook.addAttribute("warranty", "included"); + productRepository.save(macbook); + assertThat(products.keySetOnServer().size()).isEqualTo(3); } public void createOrders() { + Random random = new Random(); Address address = new Address("it", "doesn't", "matter"); - LongStream.rangeClosed(1, 100).forEach((orderId) -> - LongStream.rangeClosed(1, 3).forEach((customerId) -> { - Order order = new Order(orderId, customerId, address); - IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> { - int quantity = random.nextInt(3) + 1; - long productId = random.nextInt(3) + 1; - order.add(new LineItem(productRepository.findById(productId).get(), quantity)); - }); - orderRepository.save(order); - })); + + LongStream.rangeClosed(1, 100).forEach((orderId) -> LongStream.rangeClosed(1, 3).forEach((customerId) -> { + Order order = new Order(orderId, customerId, address); + IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> { + int quantity = random.nextInt(3) + 1; + long productId = random.nextInt(3) + 1; + order.add(new LineItem(productRepository.findById(productId).get(), quantity)); + }); + orderRepository.save(order); + })); + assertThat(orders.keySetOnServer().size()).isEqualTo(100); } -} \ No newline at end of file +} diff --git a/geode/pom.xml b/geode/pom.xml index c780f93f..3d83358e 100755 --- a/geode/pom.xml +++ b/geode/pom.xml @@ -2,127 +2,78 @@ - 4.0.0 + 4.0.0 - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - https://github.com/spring-projects/spring-geode-examples - pom + spring-data-geode-examples + pom - - events - expiration-eviction - function-invocation - queries - security - storage - transactions - wan - + + org.springframework.data.examples + spring-data-examples + 2.0.0.BUILD-SNAPSHOT + - - SpringSource - http://springsource.org - + Spring Data for Apache Geode - Examples + Sample projects for Spring Data for Apache Geode + https://projects.spring.io/spring-data-geode - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - + + events + expiration-eviction + function-invocation + queries + security + storage + transactions - - org.springframework.data.build - spring-data-parent - 2.2.5.BUILD-SNAPSHOT - + + + - - 2.12.1 - 1.7.28 - 2.2.4.BUILD-SNAPSHOT - 0.0.12.RELEASE - Moore-RELEASE - + + 0.0.12.RELEASE + - - - - org.springframework.data - spring-data-releasetrain - ${spring.data.releasetrain.version} - pom - import - - - + + + + org.awaitility + awaitility + 4.0.2 + + + org.iq80.snappy + snappy + 0.4 + + + - - - org.projectlombok - lombok - 1.18.12 - provided - - - com.github.javafaker - javafaker - 1.0.1 - - - org.springframework.data - spring-data-geode - ${spring.boot.version} - - - org.springframework.data - spring-data-geode-test - ${spring.test.data.geode.version} - test - - - org.springframework.boot - spring-boot-starter - ${spring.boot.version} - - - org.springframework.boot - spring-boot-starter-logging - - - - - org.springframework.boot - spring-boot-starter-test - ${spring.boot.version} - test - - - org.slf4j - slf4j-api - ${slf4j.log4j.version} - compile - - + + + org.springframework.data + spring-data-geode + + + com.github.javafaker + javafaker + 1.0.1 + + + org.springframework.data + spring-data-geode-test + ${spring.test.data.geode.version} + test + + - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - maven-compiler-plugin - - 1.8 - 1.8 - - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + - \ No newline at end of file + diff --git a/geode/queries/pom.xml b/geode/queries/pom.xml index f4c942c3..753a969d 100755 --- a/geode/queries/pom.xml +++ b/geode/queries/pom.xml @@ -2,23 +2,22 @@ - - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - - 4.0.0 + 4.0.0 - example.springdata.geode.client - queries - 1.0-SNAPSHOT - - - org.awaitility - awaitility - 3.1.6 - test - - + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + - \ No newline at end of file + queries + + + + org.awaitility + awaitility + test + + + + diff --git a/geode/queries/src/main/java/example/springdata/geode/client/queries/Customer.java b/geode/queries/src/main/java/example/springdata/geode/client/queries/Customer.java index babebc0a..e252caa4 100755 --- a/geode/queries/src/main/java/example/springdata/geode/client/queries/Customer.java +++ b/geode/queries/src/main/java/example/springdata/geode/client/queries/Customer.java @@ -33,11 +33,10 @@ import java.io.Serializable; @Data @PartitionRegion(name = "Customers") public class Customer implements Serializable { + @Id private Long id; - private EmailAddress emailAddress; - private String firstName; @LuceneIndexed(name = "lastName_lucene") @@ -49,4 +48,4 @@ public class Customer implements Serializable { this.firstName = firstName; this.lastName = lastName; } -} \ No newline at end of file +} diff --git a/geode/queries/src/main/java/example/springdata/geode/client/queries/EmailAddress.java b/geode/queries/src/main/java/example/springdata/geode/client/queries/EmailAddress.java index 5e07ca50..b46aed3a 100755 --- a/geode/queries/src/main/java/example/springdata/geode/client/queries/EmailAddress.java +++ b/geode/queries/src/main/java/example/springdata/geode/client/queries/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.queries; import lombok.Data; @@ -28,10 +27,11 @@ import java.io.Serializable; */ @Data public class EmailAddress implements Serializable { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/queries/src/main/java/example/springdata/geode/client/queries/client/CustomerRepository.java b/geode/queries/src/main/java/example/springdata/geode/client/queries/client/CustomerRepository.java index 81424cd7..297fbd3d 100755 --- a/geode/queries/src/main/java/example/springdata/geode/client/queries/client/CustomerRepository.java +++ b/geode/queries/src/main/java/example/springdata/geode/client/queries/client/CustomerRepository.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.queries.client; import example.springdata.geode.client.queries.Customer; + +import java.util.List; + import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.repository.Query; import org.springframework.data.gemfire.repository.query.annotation.Hint; @@ -24,10 +26,12 @@ import org.springframework.data.gemfire.repository.query.annotation.Limit; import org.springframework.data.gemfire.repository.query.annotation.Trace; import org.springframework.data.repository.CrudRepository; -import java.util.List; - +/** + * @author Patrick Johnson + */ @ClientRegion(name = "Customers") public interface CustomerRepository extends CrudRepository { + @Trace @Limit(100) @Hint("emailAddressIndex") diff --git a/geode/queries/src/main/java/example/springdata/geode/client/queries/client/QueryClientConfig.java b/geode/queries/src/main/java/example/springdata/geode/client/queries/client/QueryClientConfig.java index 5b3de4c1..d616cb3b 100755 --- a/geode/queries/src/main/java/example/springdata/geode/client/queries/client/QueryClientConfig.java +++ b/geode/queries/src/main/java/example/springdata/geode/client/queries/client/QueryClientConfig.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.queries.client; import org.apache.geode.cache.GemFireCache; @@ -28,9 +27,13 @@ import org.springframework.data.gemfire.config.annotation.EnableContinuousQuerie import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.search.lucene.LuceneTemplate; +/** + * @author Patrick Johnson + */ @Configuration -@EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) -@ClientCacheApplication(name = "CQClientCache", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, subscriptionEnabled = true, readyForEvents = true) +@EnableGemfireRepositories +@ClientCacheApplication(name = "CQClientCache", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, + subscriptionEnabled = true, readyForEvents = true) @EnableContinuousQueries @EnableClusterDefinedRegions(clientRegionShortcut = ClientRegionShortcut.PROXY) public class QueryClientConfig { @@ -45,4 +48,4 @@ public class QueryClientConfig { LuceneTemplate createCustomerLuceneTemplate() { return new LuceneTemplate("lastName_lucene", "/Customers"); } -} \ No newline at end of file +} diff --git a/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServer.java b/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServer.java index cc95bce9..de36aeaf 100755 --- a/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServer.java +++ b/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServer.java @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.queries.server; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -@SpringBootApplication(scanBasePackageClasses = QueryServerConfig.class) +/** + * @author Patrick Johnson + */ +@SpringBootApplication public class QueryServer { public static void main(String[] args) { new SpringApplicationBuilder(QueryServer.class).web(WebApplicationType.NONE).build().run(args); } -} \ No newline at end of file +} diff --git a/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServerConfig.java b/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServerConfig.java index 441e4760..aacf9f7a 100755 --- a/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServerConfig.java +++ b/geode/queries/src/main/java/example/springdata/geode/client/queries/server/QueryServerConfig.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.queries.server; import example.springdata.geode.client.queries.Customer; import example.springdata.geode.client.queries.client.CustomerRepository; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @@ -27,6 +27,9 @@ import org.springframework.data.gemfire.config.annotation.EnableIndexing; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.search.lucene.LuceneTemplate; +/** + * @author Patrick Johnson + */ @Configuration @CacheServerApplication(logLevel = "error") @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) @@ -39,4 +42,4 @@ public class QueryServerConfig { LuceneTemplate createCustomerLuceneTemplate() { return new LuceneTemplate("lastName_lucene", "/Customers"); } -} \ No newline at end of file +} diff --git a/geode/queries/src/test/java/example/springdata/geode/client/queries/QueryTests.java b/geode/queries/src/test/java/example/springdata/geode/client/queries/QueryTests.java index b026f237..9b56a66e 100755 --- a/geode/queries/src/test/java/example/springdata/geode/client/queries/QueryTests.java +++ b/geode/queries/src/test/java/example/springdata/geode/client/queries/QueryTests.java @@ -13,12 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.queries; +import static org.assertj.core.api.Assertions.*; + import example.springdata.geode.client.queries.client.CustomerRepository; import example.springdata.geode.client.queries.client.QueryClientConfig; import example.springdata.geode.client.queries.server.QueryServer; +import lombok.extern.apachecommons.CommonsLog; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.annotation.Resource; + import org.apache.geode.cache.Region; import org.apache.geode.cache.lucene.LuceneResultStruct; import org.apache.geode.cache.query.CqEvent; @@ -27,8 +37,7 @@ import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.gemfire.GemfireTemplate; @@ -36,41 +45,28 @@ import org.springframework.data.gemfire.listener.ContinuousQueryListenerContaine import org.springframework.data.gemfire.listener.annotation.ContinuousQuery; import org.springframework.data.gemfire.search.lucene.LuceneTemplate; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; - +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = QueryClientConfig.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest(classes = QueryClientConfig.class) +@CommonsLog public class QueryTests extends ForkingClientServerIntegrationTestsSupport { - @Autowired - private ContinuousQueryListenerContainer container; + @Autowired private ContinuousQueryListenerContainer container; - @Autowired - private CustomerRepository customerRepository; + @Autowired private CustomerRepository customerRepository; - @Autowired - private GemfireTemplate customerTemplate; + @Autowired private GemfireTemplate customerTemplate; - @Resource(name = "Customers") - private Region customers; + @Resource(name = "Customers") private Region customers; - @Autowired - private LuceneTemplate luceneTemplate; + @Autowired private LuceneTemplate luceneTemplate; private AtomicInteger counter = new AtomicInteger(0); - private Logger logger = LoggerFactory.getLogger(this.getClass()); - @BeforeClass public static void setup() throws IOException { startGemFireServer(QueryServer.class); @@ -88,14 +84,14 @@ public class QueryTests extends ForkingClientServerIntegrationTestsSupport { List> lastName = luceneTemplate.query("D*", "lastName", 10); assertThat(lastName.size()).isEqualTo(3); - logger.info("Customers with last names beginning with 'D':"); - lastName.forEach(result -> logger.info(result.getValue().toString())); + log.info("Customers with last names beginning with 'D':"); + lastName.forEach(result -> log.info(result.getValue().toString())); } @Test public void oqlQueriesConfiguredCorrectly() { - logger.info("Inserting 3 entries for keys: 1, 2, 3"); + log.info("Inserting 3 entries for keys: 1, 2, 3"); Customer john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith"); Customer frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport"); Customer jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons"); @@ -106,11 +102,11 @@ public class QueryTests extends ForkingClientServerIntegrationTestsSupport { Customer customer = customerRepository.findById(2L).get(); assertThat(customer).isEqualTo(frank); - logger.info("Find customer with key=2 using GemFireRepository: " + customer); + log.info("Find customer with key=2 using GemFireRepository: " + customer); List customerList = customerTemplate.find("select * from /Customers where id=$1", 2L).asList(); assertThat(customerList.size()).isEqualTo(1); assertThat(customerList.contains(frank)).isTrue(); - logger.info("Find customer with key=2 using GemFireTemplate: " + customerList); + log.info("Find customer with key=2 using GemFireTemplate: " + customerList); customer = new Customer(1L, new EmailAddress("3@3.com"), "Jude", "Smith"); customerRepository.save(customer); @@ -120,25 +116,33 @@ public class QueryTests extends ForkingClientServerIntegrationTestsSupport { assertThat(customerList.size()).isEqualTo(2); assertThat(customerList.contains(frank)).isTrue(); assertThat(customerList.contains(customer)).isTrue(); - logger.info("Find customers with emailAddress=3@3.com: " + customerList); + log.info("Find customers with emailAddress=3@3.com: " + customerList); customerList = customerRepository.findByFirstNameUsingIndex("Frank"); assertThat(customerList.get(0)).isEqualTo(frank); - logger.info("Find customers with firstName=Frank: " + customerList); + + log.info("Find customers with firstName=Frank: " + customerList); + customerList = customerRepository.findByFirstNameUsingIndex("Jude"); + assertThat(customerList.size()).isEqualTo(2); assertThat(customerList.contains(jude)).isTrue(); assertThat(customerList.contains(customer)).isTrue(); - logger.info("Find customers with firstName=Jude: " + customerList); + + log.info("Find customers with firstName=Jude: " + customerList); } @Test public void continuousQueryWorkingCorrectly() { + assertThat(this.customers).isEmpty(); - logger.info("Inserting 3 entries for keys: 1, 2, 3"); + + log.info("Inserting 3 entries for keys: 1, 2, 3"); + customerRepository.save(new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith")); customerRepository.save(new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport")); customerRepository.save(new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons")); + assertThat(customers.keySetOnServer().size()).isEqualTo(3); Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> this.counter.get() == 3); @@ -146,7 +150,7 @@ public class QueryTests extends ForkingClientServerIntegrationTestsSupport { @ContinuousQuery(name = "CustomerCQ", query = "SELECT * FROM /Customers") public void handleEvent(CqEvent event) { - logger.info("Received message for CQ 'CustomerCQ'" + event); + log.info("Received message for CQ 'CustomerCQ'" + event); counter.incrementAndGet(); } @@ -155,4 +159,4 @@ public class QueryTests extends ForkingClientServerIntegrationTestsSupport { customerRepository.deleteAll(customerRepository.findAll()); container.getQueryService().closeCqs(); } -} \ No newline at end of file +} diff --git a/geode/security/pom.xml b/geode/security/pom.xml index c5663e94..f2f7b51b 100755 --- a/geode/security/pom.xml +++ b/geode/security/pom.xml @@ -2,41 +2,33 @@ + 4.0.0 + - example.springdata.geode + org.springframework.data.examples spring-data-geode-examples - 1.0-SNAPSHOT + 2.0.0.BUILD-SNAPSHOT - 4.0.0 security org.springframework spring-jdbc - 5.2.3.RELEASE org.springframework.data spring-data-jpa - 2.2.4.RELEASE - - - org.codeprimate - cp-elements - 1.0.0.M5 org.hsqldb hsqldb - 2.4.1 javax.persistence javax.persistence-api - 2.2 - \ No newline at end of file + diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/Constants.java b/geode/security/src/main/java/example/springdata/geode/client/security/Constants.java index de045712..c8511f93 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/Constants.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/Constants.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security; /** diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/Customer.java b/geode/security/src/main/java/example/springdata/geode/client/security/Customer.java index 39dd25e2..aed09eea 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/Customer.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security; import lombok.Data; @@ -44,4 +43,4 @@ public class Customer implements Serializable { this.firstName = firstName; this.lastName = lastName; } -} \ No newline at end of file +} diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/EmailAddress.java b/geode/security/src/main/java/example/springdata/geode/client/security/EmailAddress.java index bc222121..85f60acd 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/EmailAddress.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security; import lombok.Data; @@ -34,4 +33,4 @@ public class EmailAddress implements Serializable { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/Role.java b/geode/security/src/main/java/example/springdata/geode/client/security/Role.java index dd9fc6be..a832c5da 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/Role.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/Role.java @@ -13,12 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security; import lombok.Data; -import org.apache.geode.security.ResourcePermission; -import org.cp.elements.lang.Identifiable; import java.io.Serializable; import java.util.Arrays; @@ -26,6 +23,8 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import org.apache.geode.security.ResourcePermission; + /** * The [Role] class is an Abstract Data Type (ADT) modeling a role of a user (e.g. Admin). * @@ -34,11 +33,10 @@ import java.util.Iterator; * @see Comparable * @see Iterable * @see ResourcePermission - * @see org.cp.elements.lang.Identifiable * @since 1.0.0 */ @Data -public class Role implements Comparable, Identifiable, Iterable, Serializable { +public class Role implements Comparable, Iterable, Serializable { private String name; private HashSet permissions = new HashSet<>(); @@ -47,12 +45,10 @@ public class Role implements Comparable, Identifiable, Iterable, Identifiable, Iterable, Cloneable, Principal, Serializable, Iterable, Identifiable { +public class User implements Comparable, Cloneable, Principal, Serializable, Iterable { private String name; private List roles; @@ -42,15 +44,13 @@ public class User implements Comparable, Cloneable, Principal, Serializabl } public User(String name) { - this(name, new ArrayList()); + this(name, new ArrayList<>()); } - @Override public void setId(String id) { throw new UnsupportedOperationException("Operation Not Supported"); } - @Override public String getId() { return name; } @@ -80,8 +80,7 @@ public class User implements Comparable, Cloneable, Principal, Serializabl * Determines whether this [User] has been granted (assigned) the given [permission][ResourcePermission]. * * @param permission [ResourcePermission] to evalute. - * @return a boolean value indicating whether this [User] has been granted (assigned) - * the given [ResourcePermission]. + * @return a boolean value indicating whether this [User] has been granted (assigned) the given [ResourcePermission]. * @see ResourcePermission */ public boolean hasPermission(ResourcePermission permission) { diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/client/CustomerRepository.java b/geode/security/src/main/java/example/springdata/geode/client/security/client/CustomerRepository.java index dacd8e9d..3d782b66 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/client/CustomerRepository.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/client/CustomerRepository.java @@ -13,14 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.client; import example.springdata.geode.client.security.Customer; -import org.springframework.data.repository.CrudRepository; import java.util.List; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Patrick Johnson + */ public interface CustomerRepository extends CrudRepository { + + @Override List findAll(); + } diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/client/SecurityEnabledClientConfiguration.java b/geode/security/src/main/java/example/springdata/geode/client/security/client/SecurityEnabledClientConfiguration.java index 88754f38..5c934592 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/client/SecurityEnabledClientConfiguration.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/client/SecurityEnabledClientConfiguration.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.client; import example.springdata.geode.client.security.Customer; @@ -30,4 +29,4 @@ import org.springframework.data.gemfire.repository.config.EnableGemfireRepositor @ClientCacheApplication(name = "SecurityClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1) @EnableEntityDefinedRegions(basePackageClasses = Customer.class, clientRegionShortcut = ClientRegionShortcut.CACHING_PROXY) public class SecurityEnabledClientConfiguration { -} \ No newline at end of file +} diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/ApacheShiroIniConfiguration.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/ApacheShiroIniConfiguration.java index fd9f187d..53f54611 100644 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/ApacheShiroIniConfiguration.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/ApacheShiroIniConfiguration.java @@ -1,3 +1,18 @@ +/* + * Copyright 2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package example.springdata.geode.client.security.server; import org.springframework.context.annotation.Configuration; @@ -7,5 +22,4 @@ import org.springframework.data.gemfire.config.annotation.EnableSecurity; @Configuration @EnableSecurity(shiroIniResourcePath = "shiro.ini") @Profile("shiro-ini-configuration") -public class ApacheShiroIniConfiguration { -} +public class ApacheShiroIniConfiguration {} diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/CachingSecurityRepository.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/CachingSecurityRepository.java index 94ac8202..cdf6be29 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/CachingSecurityRepository.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/CachingSecurityRepository.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import example.springdata.geode.client.security.User; @@ -31,6 +30,7 @@ import java.util.Map; * @since 1.0.0 */ public abstract class CachingSecurityRepository implements SecurityRepository { + private Map users = new HashMap<>(); @Override diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/GeodeIntegratedSecurityProxyConfiguration.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/GeodeIntegratedSecurityProxyConfiguration.java index 05faf3b7..633fe65d 100644 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/GeodeIntegratedSecurityProxyConfiguration.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/GeodeIntegratedSecurityProxyConfiguration.java @@ -1,13 +1,28 @@ +/* + * Copyright 2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package example.springdata.geode.client.security.server; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.data.gemfire.config.annotation.EnableSecurity; - +/** + * @author Patrick Johnson + */ @Configuration @EnableSecurity(securityManagerClassName = "example.springdata.geode.client.security.server.SecurityManagerProxy") -@Profile({"default", "geode-security-manager-proxy-configuration"}) -public class GeodeIntegratedSecurityProxyConfiguration { - -} +@Profile({ "default", "geode-security-manager-proxy-configuration" }) +public class GeodeIntegratedSecurityProxyConfiguration {} diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/JdbcSecurityRepository.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/JdbcSecurityRepository.java index b8608524..599abda6 100644 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/JdbcSecurityRepository.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/JdbcSecurityRepository.java @@ -13,42 +13,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import example.springdata.geode.client.security.Role; import example.springdata.geode.client.security.User; -import org.apache.geode.security.ResourcePermission; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Repository; +import lombok.extern.apachecommons.CommonsLog; import java.util.Collections; import java.util.HashMap; import java.util.List; -@Repository -public class JdbcSecurityRepository extends CachingSecurityRepository implements InitializingBean { +import org.apache.geode.security.ResourcePermission; - private Logger logger = LoggerFactory.getLogger(this.getClass()); +import org.springframework.beans.factory.InitializingBean; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Repository; + +/** + * @author Patrick Johnson + */ +@Repository +@CommonsLog +public class JdbcSecurityRepository extends CachingSecurityRepository implements InitializingBean { private final JdbcTemplate jdbcTemplate; private static final String ROLES_QUERY = "SELECT name FROM geode_security.roles"; private static final String ROLE_PERMISSIONS_QUERY = "" + " SELECT rolePerms.resource, rolePerms.operation, rolePerms.region_name, rolePerms.key_name" + " FROM geode_security.roles_permissions rolePerms" - + " INNER JOIN geode_security.roles roles ON roles.id = rolePerms.role_id " - + " WHERE roles.name = ?"; + + " INNER JOIN geode_security.roles roles ON roles.id = rolePerms.role_id " + " WHERE roles.name = ?"; private static final String USERS_QUERY = "SELECT name, credentials FROM geode_security.users"; - private static final String USER_ROLES_QUERY = "" - + " SELECT roles.name" - + " FROM geode_security.roles roles" + private static final String USER_ROLES_QUERY = "" + " SELECT roles.name" + " FROM geode_security.roles roles" + " INNER JOIN geode_security.users_roles userRoles ON roles.id = userRoles.role_id" - + " INNER JOIN geode_security.users users ON userRoles.user_id = users.id" - + " WHERE users.name = ?"; + + " INNER JOIN geode_security.users users ON userRoles.user_id = users.id" + " WHERE users.name = ?"; public JdbcSecurityRepository(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; @@ -61,15 +59,14 @@ public class JdbcSecurityRepository extends CachingSecurityRepository implements roles.forEach((role) -> { this.jdbcTemplate.query(ROLE_PERMISSIONS_QUERY, Collections.singleton(role.getName()).toArray(), - (RowMapper) (resultSet, i) -> role.withPermissions(newResourcePermission( - resultSet.getString(1), resultSet.getString(2), - resultSet.getString(3), resultSet.getString(4)))); + (RowMapper) (resultSet, i) -> role.withPermissions(newResourcePermission(resultSet.getString(1), + resultSet.getString(2), resultSet.getString(3), resultSet.getString(4)))); roleMapping.put(role.getName(), role); }); - List users = this.jdbcTemplate.query(USERS_QUERY, (resultSet, i) -> - createUser(resultSet.getString(1)).withCredentials(resultSet.getString(2))); + List users = this.jdbcTemplate.query(USERS_QUERY, + (resultSet, i) -> createUser(resultSet.getString(1)).withCredentials(resultSet.getString(2))); users.forEach((role) -> { this.jdbcTemplate.query(USER_ROLES_QUERY, Collections.singleton(role.getName()).toArray(), @@ -78,7 +75,7 @@ public class JdbcSecurityRepository extends CachingSecurityRepository implements save(role); }); - logger.debug("Users {}", users); + log.debug(String.format("Users %s", users)); } protected ResourcePermission newResourcePermission(String resource, String operation, String region, String key) { diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServer.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServer.java index d3d5f6ef..6278b91f 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServer.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServer.java @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -@SpringBootApplication(scanBasePackageClasses = SecurityEnabledServerConfiguration.class) +/** + * @author Patrick Johnson + */ +@SpringBootApplication public class SecurityEnabledServer { + public static void main(String[] args) { - new SpringApplicationBuilder(SecurityEnabledServer.class) - .web(WebApplicationType.NONE) - .build() - .run(args); + new SpringApplicationBuilder(SecurityEnabledServer.class).web(WebApplicationType.NONE).build().run(args); } -} \ No newline at end of file + +} diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServerConfiguration.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServerConfiguration.java index 3bc188d2..00f8316f 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServerConfiguration.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityEnabledServerConfiguration.java @@ -13,11 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import example.springdata.geode.client.security.Customer; + +import javax.sql.DataSource; + import org.apache.geode.cache.RegionShortcut; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -29,32 +32,25 @@ import org.springframework.data.gemfire.config.annotation.EnableManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import javax.sql.DataSource; - +/** + * @author Patrick Johnson + */ @Configuration @EnableLocator @EnableIndexing @EnableManager -@Import({ApacheShiroIniConfiguration.class, GeodeIntegratedSecurityProxyConfiguration.class}) +@Import({ ApacheShiroIniConfiguration.class, GeodeIntegratedSecurityProxyConfiguration.class }) @CacheServerApplication(port = 0, logLevel = "error") @EnableEntityDefinedRegions(basePackageClasses = Customer.class, serverRegionShortcut = RegionShortcut.REPLICATE) public class SecurityEnabledServerConfiguration { @Bean DataSource hsqlDataSource() { - return new EmbeddedDatabaseBuilder() - .setName("geode_security") - .setScriptEncoding("UTF-8") - .setType(EmbeddedDatabaseType.HSQL) - .addScript("sql/geode-security-schema-ddl.sql") - .addScript("sql/define-roles-table-ddl.sql") - .addScript("sql/define-roles-permissions-table-ddl.sql") - .addScript("sql/define-users-table-ddl.sql") - .addScript("sql/define-users-roles-table-ddl.sql") - .addScript("sql/insert-roles-dml.sql") - .addScript("sql/insert-roles-permissions-dml.sql") - .addScript("sql/insert-users-dml.sql") - .addScript("sql/insert-users-roles-dml.sql") - .build(); + return new EmbeddedDatabaseBuilder().setName("geode_security").setScriptEncoding("UTF-8") + .setType(EmbeddedDatabaseType.HSQL).addScript("sql/geode-security-schema-ddl.sql") + .addScript("sql/define-roles-table-ddl.sql").addScript("sql/define-roles-permissions-table-ddl.sql") + .addScript("sql/define-users-table-ddl.sql").addScript("sql/define-users-roles-table-ddl.sql") + .addScript("sql/insert-roles-dml.sql").addScript("sql/insert-roles-permissions-dml.sql") + .addScript("sql/insert-users-dml.sql").addScript("sql/insert-users-roles-dml.sql").build(); } } diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerProxy.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerProxy.java index 69fa1d97..541a74c4 100644 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerProxy.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerProxy.java @@ -13,22 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; -import org.apache.geode.security.AuthenticationFailedException; -import org.apache.geode.security.ResourcePermission; -import org.cp.elements.lang.Assert; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.support.LazyWiringDeclarableSupport; - import java.util.Properties; +import org.apache.geode.security.AuthenticationFailedException; +import org.apache.geode.security.ResourcePermission; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.gemfire.support.LazyWiringDeclarableSupport; +import org.springframework.util.Assert; + /** * The {@link SecurityManagerProxy} class is a Proxy delegating to an underlying Apache Geode - * {@link org.apache.geode.security.SecurityManager} implementation, that maybe a Spring managed bean - * in a Spring context that may have been configured and auto-wired the Spring container, or possibly - * other managed environment (Cloud or Java EE Server, etc). + * {@link org.apache.geode.security.SecurityManager} implementation, that maybe a Spring managed bean in a Spring + * context that may have been configured and auto-wired the Spring container, or possibly other managed environment + * (Cloud or Java EE Server, etc). * * @author John Blum * @see org.apache.geode.security.SecurityManager @@ -42,8 +42,8 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport private org.apache.geode.security.SecurityManager securityManager; /** - * Constructs an instance of the {@link SecurityManagerProxy}, whick will delegate all Apache Geode - * security operations to a Spring managed {@link org.apache.geode.security.SecurityManager} bean. + * Constructs an instance of the {@link SecurityManagerProxy}, whick will delegate all Apache Geode security + * operations to a Spring managed {@link org.apache.geode.security.SecurityManager} bean. */ public SecurityManagerProxy() { // TODO remove init() call when GEODE-2083 (https://issues.apache.org/jira/browse/GEODE-2083) is resolved! @@ -56,13 +56,13 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport } /** - * Returns a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance - * delegated to by this {@link SecurityManagerProxy}. + * Returns a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance delegated to by + * this {@link SecurityManagerProxy}. * - * @return a reference to the underlying, Apache Geode {@link org.apache.geode.security.SecurityManager} - * instance delegated to by this {@link SecurityManagerProxy}. - * @throws IllegalStateException if the configured Apache Geode {@link org.apache.geode.security.SecurityManager} - * was not properly initialized. + * @return a reference to the underlying, Apache Geode {@link org.apache.geode.security.SecurityManager} instance + * delegated to by this {@link SecurityManagerProxy}. + * @throws IllegalStateException if the configured Apache Geode {@link org.apache.geode.security.SecurityManager} was + * not properly initialized. * @see org.apache.geode.security.SecurityManager */ protected org.apache.geode.security.SecurityManager getSecurityManager() { @@ -71,13 +71,13 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport } /** - * Sets a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance - * delegated to by this {@link SecurityManagerProxy}. + * Sets a reference to the Apache Geode {@link org.apache.geode.security.SecurityManager} instance delegated to by + * this {@link SecurityManagerProxy}. * * @param securityManager reference to the underlying, Apache Geode {@link org.apache.geode.security.SecurityManager} - * instance delegated to by this {@link SecurityManagerProxy}. - * @throws IllegalArgumentException if the Apache Geode {@link org.apache.geode.security.SecurityManager} reference - * is {@literal null}. + * instance delegated to by this {@link SecurityManagerProxy}. + * @throws IllegalArgumentException if the Apache Geode {@link org.apache.geode.security.SecurityManager} reference is + * {@literal null}. * @see org.apache.geode.security.SecurityManager */ @Autowired diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerSupport.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerSupport.java index 5b0645d7..feb81c5b 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerSupport.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityManagerSupport.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import example.springdata.geode.client.security.Constants; diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityRepository.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityRepository.java index 9a4ac2a0..15d064b2 100755 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityRepository.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/SecurityRepository.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import example.springdata.geode.client.security.Role; @@ -24,8 +23,8 @@ import java.util.Arrays; import java.util.List; /** - * The [SecurityRepository] interface is a contract for Data Access Objects (DAO) implementing this interface - * to perform CRUD and query operations on [User] information, pertinent to the security of the system. + * The [SecurityRepository] interface is a contract for Data Access Objects (DAO) implementing this interface to perform + * CRUD and query operations on [User] information, pertinent to the security of the system. * * @author John Blum * @author Udo Kohlmeyer @@ -35,6 +34,7 @@ import java.util.List; * @since 1.0.0 */ public interface SecurityRepository { + /** * Finds all [Users][User] of the system. * @@ -154,4 +154,3 @@ public interface SecurityRepository { return saved; } } - diff --git a/geode/security/src/main/java/example/springdata/geode/client/security/server/SimpleSecurityManager.java b/geode/security/src/main/java/example/springdata/geode/client/security/server/SimpleSecurityManager.java index a0280947..94a69e0f 100644 --- a/geode/security/src/main/java/example/springdata/geode/client/security/server/SimpleSecurityManager.java +++ b/geode/security/src/main/java/example/springdata/geode/client/security/server/SimpleSecurityManager.java @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.server; import example.springdata.geode.client.security.Role; import example.springdata.geode.client.security.User; -import org.apache.geode.security.AuthenticationFailedException; -import org.apache.geode.security.ResourcePermission; -import org.springframework.stereotype.Service; import java.util.Properties; +import org.apache.geode.security.AuthenticationFailedException; +import org.apache.geode.security.ResourcePermission; + +import org.springframework.stereotype.Service; + /** - * The [SimpleSecurityManager] class is an example Apache Geode [SecurityManager] provider implementation - * used to secure Apache Geode. + * The [SimpleSecurityManager] class is an example Apache Geode [SecurityManager] provider implementation used to secure + * Apache Geode. * * @author John Blum * @see SecurityManagerSupport @@ -81,8 +82,8 @@ public class SimpleSecurityManager extends SecurityManagerSupport { */ @Override public boolean authorize(Object principal, ResourcePermission permission) { - logDebug("Principal [{}] is requesting access to a Resource {} with the required Permission [{}]", - principal, permission.getResource(), permission); + logDebug("Principal [{}] is requesting access to a Resource {} with the required Permission [{}]", principal, + permission.getResource(), permission); return isAuthorized(principal, permission); } diff --git a/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientShiroTests.java b/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientShiroTests.java index 8ae28b4f..b132833c 100755 --- a/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientShiroTests.java +++ b/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientShiroTests.java @@ -13,42 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.client; +import static org.assertj.core.api.Assertions.*; + import example.springdata.geode.client.security.Customer; import example.springdata.geode.client.security.EmailAddress; import example.springdata.geode.client.security.server.SecurityEnabledServer; +import lombok.extern.apachecommons.CommonsLog; + +import java.io.IOException; +import java.util.List; + +import javax.annotation.Resource; + import org.apache.geode.cache.Region; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; -import java.io.IOException; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = SecurityEnabledClientConfiguration.class) +@SpringBootTest(classes = SecurityEnabledClientConfiguration.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@CommonsLog public class SecurityEnabledClientShiroTests extends ForkingClientServerIntegrationTestsSupport { - @Autowired - private CustomerRepository customerRepository; + @Autowired private CustomerRepository customerRepository; - @Resource(name = "Customers") - private Region customers; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Resource(name = "Customers") private Region customers; @BeforeClass public static void setup() throws IOException { @@ -57,20 +58,27 @@ public class SecurityEnabledClientShiroTests extends ForkingClientServerIntegrat @Test public void securityWasConfiguredCorrectly() { - logger.info("Inserting 3 entries for keys: 1, 2, 3"); + + log.info("Inserting 3 entries for keys: 1, 2, 3"); + Customer john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith"); Customer frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport"); Customer jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons"); + customerRepository.save(john); customerRepository.save(frank); customerRepository.save(jude); + assertThat(customers.keySetOnServer().size()).isEqualTo(3); - logger.info("Customers saved on server:"); + log.info("Customers saved on server:"); + List customerList = customerRepository.findAll(); + assertThat(customerList.size()).isEqualTo(3); assertThat(customerList.contains(john)).isTrue(); assertThat(customerList.contains(frank)).isTrue(); assertThat(customerList.contains(jude)).isTrue(); - customerList.forEach(customer -> logger.info("\t Entry: \n \t\t " + customer)); + + customerList.forEach(customer -> log.info("\t Entry: \n \t\t " + customer)); } -} \ No newline at end of file +} diff --git a/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientTests.java b/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientTests.java index 003c89f8..f96118ec 100755 --- a/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientTests.java +++ b/geode/security/src/test/java/example/springdata/geode/client/security/client/SecurityEnabledClientTests.java @@ -13,42 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.security.client; +import static org.assertj.core.api.Assertions.*; + import example.springdata.geode.client.security.Customer; import example.springdata.geode.client.security.EmailAddress; import example.springdata.geode.client.security.server.SecurityEnabledServer; +import lombok.extern.apachecommons.CommonsLog; + +import java.io.IOException; +import java.util.List; + +import javax.annotation.Resource; + import org.apache.geode.cache.Region; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; -import java.io.IOException; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = SecurityEnabledClientConfiguration.class) +@SpringBootTest(classes = SecurityEnabledClientConfiguration.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@CommonsLog public class SecurityEnabledClientTests extends ForkingClientServerIntegrationTestsSupport { - @Autowired - private CustomerRepository customerRepository; + @Autowired private CustomerRepository customerRepository; - @Resource(name = "Customers") - private Region customers; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Resource(name = "Customers") private Region customers; @BeforeClass public static void setup() throws IOException { @@ -57,20 +58,28 @@ public class SecurityEnabledClientTests extends ForkingClientServerIntegrationTe @Test public void SecurityWasConfiguredCorrectly() { - logger.info("Inserting 3 entries for keys: 1, 2, 3"); + + log.info("Inserting 3 entries for keys: 1, 2, 3"); + Customer john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith"); Customer frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport"); Customer jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons"); + customerRepository.save(john); customerRepository.save(frank); customerRepository.save(jude); - assertThat(customers.keySetOnServer().size()).isEqualTo(3); - logger.info("Customers saved on server:"); + + assertThat(customers.keySetOnServer()).hasSize(3); + + log.info("Customers saved on server:"); + List customerList = customerRepository.findAll(); + assertThat(customerList.size()).isEqualTo(3); assertThat(customerList.contains(john)).isTrue(); assertThat(customerList.contains(frank)).isTrue(); assertThat(customerList.contains(jude)).isTrue(); - customerList.forEach(customer -> logger.info("\t Entry: \n \t\t " + customer)); + + customerList.forEach(customer -> log.info("\t Entry: \n \t\t " + customer)); } -} \ No newline at end of file +} diff --git a/geode/storage/pom.xml b/geode/storage/pom.xml index 649af983..8f9c24e7 100644 --- a/geode/storage/pom.xml +++ b/geode/storage/pom.xml @@ -2,21 +2,21 @@ - - spring-data-geode-examples - example.springdata.geode - 1.0-SNAPSHOT - - 4.0.0 + 4.0.0 - storage + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + - - - org.iq80.snappy - snappy - 0.4 - - + storage - \ No newline at end of file + + + org.iq80.snappy + snappy + + + + diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/Address.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/Address.java index 44544bbf..15b8553a 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/Address.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/Address.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import lombok.Data; @@ -29,6 +28,7 @@ import java.io.Serializable; */ @Data public class Address implements Serializable { + private String street; private String city; private String country; diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/Customer.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/Customer.java index 100f5b3c..e09e41ee 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/Customer.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import lombok.Data; @@ -48,4 +47,4 @@ public class Customer implements Serializable { this.lastName = lastName; this.addresses = Arrays.asList(addresses); } -} \ No newline at end of file +} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/CustomerRepository.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/CustomerRepository.java index 2d61b8a4..12a04879 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/CustomerRepository.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/CustomerRepository.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import org.springframework.data.repository.CrudRepository; +/** + * @author Patrick Johnson + */ public interface CustomerRepository extends CrudRepository { } diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/EmailAddress.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/EmailAddress.java index 68a91b88..324e59e0 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/EmailAddress.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import lombok.Data; @@ -28,10 +27,11 @@ import java.io.Serializable; */ @Data public class EmailAddress implements Serializable { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/LineItem.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/LineItem.java index ae7b088b..d8850fc6 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/LineItem.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/LineItem.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import lombok.Data; @@ -41,4 +40,4 @@ public class LineItem implements Serializable { public BigDecimal calcTotal() { return product.getPrice().multiply(BigDecimal.valueOf(amount)); } -} \ No newline at end of file +} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/Order.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/Order.java index 01753d7d..27c9a32d 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/Order.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/Order.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import lombok.Data; -import org.springframework.data.annotation.Id; -import org.springframework.data.gemfire.mapping.annotation.Region; import java.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import org.springframework.data.annotation.Id; +import org.springframework.data.gemfire.mapping.annotation.Region; + /** * Orders object used in the examples * @@ -34,8 +34,8 @@ import java.util.List; @Data @Region("Orders") public class Order implements Serializable { - @Id - private Long id; + + @Id private Long id; private Long customerId; private Address billingAddress; private Address shippingAddress; @@ -69,4 +69,4 @@ public class Order implements Serializable { public void add(LineItem lineItem) { lineItems.add(lineItem); } -} \ No newline at end of file +} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/OrderRepository.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/OrderRepository.java index 5cdd8c35..d42d690c 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/OrderRepository.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/OrderRepository.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import org.springframework.data.repository.CrudRepository; -public interface OrderRepository extends CrudRepository { -} +/** + * @author Patrick Johnson + */ +public interface OrderRepository extends CrudRepository {} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/Product.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/Product.java index 9f2e316b..8369ee60 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/Product.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/Product.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import lombok.Data; diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/ProductRepository.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/ProductRepository.java index d861dbfb..fc86d529 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/ProductRepository.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/ProductRepository.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import org.springframework.data.repository.CrudRepository; -public interface ProductRepository extends CrudRepository { -} +/** + * @author Patrick Johnson + */ +public interface ProductRepository extends CrudRepository {} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServer.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServer.java index 1756415d..9035d82f 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServer.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServer.java @@ -13,12 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; +import lombok.extern.apachecommons.CommonsLog; + +import java.math.BigDecimal; +import java.util.Random; +import java.util.stream.IntStream; +import java.util.stream.LongStream; + import org.apache.geode.cache.Region; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.WebApplicationType; @@ -26,26 +31,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.Bean; -import java.math.BigDecimal; -import java.util.Random; -import java.util.stream.IntStream; -import java.util.stream.LongStream; - -@SpringBootApplication(scanBasePackageClasses = StorageServerConfig.class) +/** + * @author Patrick Johnson + */ +@SpringBootApplication +@CommonsLog public class StorageServer { - private Logger logger = LoggerFactory.getLogger(this.getClass()); - public static void main(String[] args) { - new SpringApplicationBuilder(StorageServer.class) - .web(WebApplicationType.NONE) - .build() - .run(args); + new SpringApplicationBuilder(StorageServer.class).web(WebApplicationType.NONE).build().run(args); } @Bean public ApplicationRunner runner(CustomerRepository customerRepository, OrderRepository orderRepository, - ProductRepository productRepository, @Qualifier("Products") Region products) { + ProductRepository productRepository, @Qualifier("Products") Region products) { return args -> { createCustomerData(customerRepository); @@ -53,40 +52,34 @@ public class StorageServer { createOrders(productRepository, orderRepository); - logger.info("Completed creating orders "); + log.info("Completed creating orders "); }; } private void createOrders(ProductRepository productRepository, OrderRepository orderRepository) { Random random = new Random(System.nanoTime()); Address address = new Address("it", "doesn't", "matter"); - LongStream.rangeClosed(1, 10).forEach((orderId) -> - LongStream.rangeClosed(1, 300).forEach((customerId) -> { - Order order = new Order(orderId, customerId, address); - IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> { - int quantity = random.nextInt(3) + 1; - long productId = random.nextInt(3) + 1; - order.add(new LineItem(productRepository.findById(productId).get(), quantity)); - }); - orderRepository.save(order); - })); + LongStream.rangeClosed(1, 10).forEach((orderId) -> LongStream.rangeClosed(1, 300).forEach((customerId) -> { + Order order = new Order(orderId, customerId, address); + IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> { + int quantity = random.nextInt(3) + 1; + long productId = random.nextInt(3) + 1; + order.add(new LineItem(productRepository.findById(productId).get(), quantity)); + }); + orderRepository.save(order); + })); } private void createProducts(ProductRepository productRepository) { - productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), - "An Apple portable music player")); - productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), - "An Apple tablet device")); - Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), - "An Apple notebook computer"); + productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), "An Apple portable music player")); + productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), "An Apple tablet device")); + Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), "An Apple notebook computer"); macbook.addAttribute("warranty", "included"); productRepository.save(macbook); } private void createCustomerData(CustomerRepository customerRepository) { - LongStream.rangeClosed(0, 300) - .parallel() - .forEach(customerId -> - customerRepository.save(new Customer(customerId, new EmailAddress(customerId + "@2.com"), "John" + customerId, "Smith" + customerId))); + LongStream.rangeClosed(0, 300).parallel().forEach(customerId -> customerRepository.save( + new Customer(customerId, new EmailAddress(customerId + "@2.com"), "John" + customerId, "Smith" + customerId))); } -} \ No newline at end of file +} diff --git a/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServerConfig.java b/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServerConfig.java index f4970b2e..656a69a6 100755 --- a/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServerConfig.java +++ b/geode/storage/src/main/java/example/springdata/geode/server/storage/StorageServerConfig.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; import org.apache.geode.cache.DataPolicy; @@ -33,11 +32,14 @@ import org.springframework.data.gemfire.config.annotation.CacheServerApplication import org.springframework.data.gemfire.config.annotation.EnableOffHeap; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; +/** + * @author Patrick Johnson + */ @Configuration @ComponentScan @CacheServerApplication(logLevel = "error") @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) -@EnableOffHeap(memorySize = "8192m", regionNames = "Products") +@EnableOffHeap(memorySize = "512m", regionNames = "Products") public class StorageServerConfig { @Bean @@ -47,22 +49,23 @@ public class StorageServerConfig { @Bean RegionAttributesFactoryBean regionAttributes(PartitionAttributes partitionAttributes) { - final RegionAttributesFactoryBean regionAttributesFactoryBean = new RegionAttributesFactoryBean<>(); + RegionAttributesFactoryBean regionAttributesFactoryBean = new RegionAttributesFactoryBean<>(); regionAttributesFactoryBean.setPartitionAttributes(partitionAttributes); return regionAttributesFactoryBean; } @Bean PartitionAttributesFactoryBean partitionAttributes() { - final PartitionAttributesFactoryBean partitionAttributesFactoryBean = new PartitionAttributesFactoryBean<>(); + PartitionAttributesFactoryBean partitionAttributesFactoryBean = new PartitionAttributesFactoryBean<>(); partitionAttributesFactoryBean.setTotalNumBuckets(11); partitionAttributesFactoryBean.setRedundantCopies(1); return partitionAttributesFactoryBean; } @Bean("Orders") - PartitionedRegionFactoryBean createOrderRegion(GemFireCache gemFireCache, RegionAttributes regionAttributes) { - final PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); + PartitionedRegionFactoryBean createOrderRegion(GemFireCache gemFireCache, + RegionAttributes regionAttributes) { + PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); partitionedRegionFactoryBean.setCache(gemFireCache); partitionedRegionFactoryBean.setRegionName("Orders"); partitionedRegionFactoryBean.setDataPolicy(DataPolicy.PARTITION); @@ -72,7 +75,7 @@ public class StorageServerConfig { @Bean("Products") ReplicatedRegionFactoryBean createProductRegion(GemFireCache gemFireCache) { - final ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); + ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); replicatedRegionFactoryBean.setCache(gemFireCache); replicatedRegionFactoryBean.setRegionName("Products"); replicatedRegionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); @@ -81,11 +84,11 @@ public class StorageServerConfig { @Bean("Customers") ReplicatedRegionFactoryBean createCustomerRegion(GemFireCache gemFireCache, Compressor compressor) { - final ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); + ReplicatedRegionFactoryBean replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>(); replicatedRegionFactoryBean.setCache(gemFireCache); replicatedRegionFactoryBean.setRegionName("Customers"); replicatedRegionFactoryBean.setDataPolicy(DataPolicy.REPLICATE); replicatedRegionFactoryBean.setCompressor(compressor); return replicatedRegionFactoryBean; } -} \ No newline at end of file +} diff --git a/geode/storage/src/test/java/example/springdata/geode/server/storage/StorageServerTests.java b/geode/storage/src/test/java/example/springdata/geode/server/storage/StorageServerTests.java index 3857299b..2e0d5671 100755 --- a/geode/storage/src/test/java/example/springdata/geode/server/storage/StorageServerTests.java +++ b/geode/storage/src/test/java/example/springdata/geode/server/storage/StorageServerTests.java @@ -13,39 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.storage; +import static org.assertj.core.api.Assertions.*; + +import javax.annotation.Resource; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.Region; import org.apache.geode.compression.SnappyCompressor; import org.apache.geode.internal.cache.GemFireCacheImpl; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; - -import static org.assertj.core.api.Assertions.assertThat; - +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = StorageServer.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest public class StorageServerTests { - @Resource(name = "Customers") - private Region customers; - @Resource(name = "Orders") - private Region orders; + @Resource(name = "Customers") private Region customers; - @Resource(name = "Products") - private Region products; + @Resource(name = "Orders") private Region orders; - @Autowired - Cache cache; + @Resource(name = "Products") private Region products; + + @Autowired Cache cache; @Test public void partitionAttributesConfiguredCorrectly() { @@ -55,9 +53,13 @@ public class StorageServerTests { @Test public void compressorIsEnabled() { + assertThat(customers.getAttributes().getCompressor()).isInstanceOf(SnappyCompressor.class); + GemFireCacheImpl impl = (GemFireCacheImpl) cache; - assertThat(impl.getCachePerfStats().getTotalPostCompressedBytes()).isLessThan(impl.getCachePerfStats().getTotalPreCompressedBytes()); + + assertThat(impl.getCachePerfStats().getTotalPostCompressedBytes()) + .isLessThan(impl.getCachePerfStats().getTotalPreCompressedBytes()); } @Test @@ -65,4 +67,4 @@ public class StorageServerTests { assertThat(products.getAttributes().getOffHeap()).isTrue(); assertThat(customers.getAttributes().getOffHeap()).isFalse(); } -} \ No newline at end of file +} diff --git a/geode/transactions/pom.xml b/geode/transactions/pom.xml index 47526744..1bd9d9c5 100755 --- a/geode/transactions/pom.xml +++ b/geode/transactions/pom.xml @@ -2,18 +2,14 @@ - - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - + 4.0.0 - 4.0.0 - transactions - 1.0-SNAPSHOT + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + - + transactions - - - \ No newline at end of file + diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/Customer.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/Customer.java index e0e9ea86..f0c5b0b4 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/Customer.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions; import lombok.Data; @@ -42,4 +41,4 @@ public class Customer { this.firstName = firstName; this.lastName = lastName; } -} \ No newline at end of file +} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/EmailAddress.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/EmailAddress.java index 16c841cc..076446e1 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/EmailAddress.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions; import lombok.Data; @@ -26,9 +25,10 @@ import lombok.Data; */ @Data public class EmailAddress { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerRepository.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerRepository.java index 1a9f2034..ab2e6e82 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerRepository.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerRepository.java @@ -13,17 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.client; import example.springdata.geode.client.transactions.Customer; + import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.repository.CrudRepository; -import java.util.List; - +/** + * @author Patrick Johnson + */ @ClientRegion("Customers") -public interface CustomerRepository extends CrudRepository { - - List findAll(); -} +public interface CustomerRepository extends CrudRepository {} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerService.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerService.java index 676d0baf..6dcf909f 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerService.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/CustomerService.java @@ -13,30 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.client; import example.springdata.geode.client.transactions.Customer; import example.springdata.geode.client.transactions.EmailAddress; -import org.apache.geode.cache.Region; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import javax.annotation.Resource; + +import org.apache.geode.cache.Region; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author Patrick Johnson + */ @Service public class CustomerService { private final CustomerRepository customerRepository; - @Resource(name = "Customers") - private Region customerRegion; + @Resource(name = "Customers") private Region customerRegion; - public CustomerService(CustomerRepository customerRepository, @Qualifier("Customers") Region customerRegion) { + public CustomerService(CustomerRepository customerRepository, + @Qualifier("Customers") Region customerRegion) { this.customerRepository = customerRepository; this.customerRegion = customerRegion; } @@ -55,13 +60,13 @@ public class CustomerService { @Transactional public List createFiveCustomers() { - return Arrays.stream(new Customer[]{new Customer(1L, new EmailAddress("1@1.com"), "John", "Melloncamp"), - new Customer(2L, new EmailAddress("2@2.com"), "Franky", "Hamilton"), - new Customer(3L, new EmailAddress("3@3.com"), "Sebastian", "Horner"), - new Customer(4L, new EmailAddress("4@4.com"), "Chris", "Vettel"), - new Customer(5L, new EmailAddress("5@5.com"), "Kimi", "Rosberg")}) - .map(customerRepository::save) - .collect(Collectors.toList()); + return Arrays + .stream(new Customer[] { new Customer(1L, new EmailAddress("1@1.com"), "John", "Melloncamp"), + new Customer(2L, new EmailAddress("2@2.com"), "Franky", "Hamilton"), + new Customer(3L, new EmailAddress("3@3.com"), "Sebastian", "Horner"), + new Customer(4L, new EmailAddress("4@4.com"), "Chris", "Vettel"), + new Customer(5L, new EmailAddress("5@5.com"), "Kimi", "Rosberg") }) + .map(customerRepository::save).collect(Collectors.toList()); } @Transactional @@ -78,6 +83,6 @@ public class CustomerService { @Transactional public void updateCustomersFailure() { customerRepository.save(new Customer(2L, new EmailAddress("2@2.com"), "Numpty", "Hamilton")); - throw new IllegalArgumentException("This should fail the transactions"); + throw new IllegalArgumentException("This is an expected exception that should fail the transactions"); } -} \ No newline at end of file +} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/TransactionalClientConfig.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/TransactionalClientConfig.java index c13e159f..09071646 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/TransactionalClientConfig.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/client/TransactionalClientConfig.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.client; import org.apache.geode.cache.client.ClientRegionShortcut; @@ -26,6 +25,9 @@ import org.springframework.data.gemfire.repository.config.EnableGemfireRepositor import org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTransactions; import org.springframework.transaction.annotation.EnableTransactionManagement; +/** + * @author Patrick Johnson + */ @EnableClusterDefinedRegions(clientRegionShortcut = ClientRegionShortcut.PROXY) @EnableTransactionManagement @EnableGemfireCacheTransactions @@ -33,6 +35,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnablePdx @ComponentScan(basePackageClasses = CustomerService.class) @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) -@ClientCacheApplication(name = "TransactionalClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1) -public class TransactionalClientConfig { -} \ No newline at end of file +@ClientCacheApplication(name = "TransactionalClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, + retryAttempts = 1) +public class TransactionalClientConfig {} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionListener.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionListener.java index a97e8d75..9962a3b8 100644 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionListener.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionListener.java @@ -13,22 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.server; +import java.util.stream.Collectors; + +import lombok.extern.apachecommons.CommonsLog; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.geode.cache.CacheEvent; import org.apache.geode.cache.TransactionEvent; import org.apache.geode.cache.util.TransactionListenerAdapter; import org.apache.geode.internal.cache.TXEntryState; + import org.springframework.stereotype.Component; -import java.util.stream.Collectors; - +/** + * @author Patrick Johnson + */ @Component +@CommonsLog public class CustomerTransactionListener extends TransactionListenerAdapter { - private Log log = LogFactory.getLog(CustomerTransactionListener.class); @Override public void afterFailedCommit(TransactionEvent event) { @@ -37,7 +41,8 @@ public class CustomerTransactionListener extends TransactionListenerAdapter { @Override public void afterRollback(TransactionEvent event) { - log.info("In afterRollback for entry(s) [" + event.getEvents().stream().map(this::getEventInfo).collect(Collectors.toList()) + "]"); + log.info("In afterRollback for entry(s) [" + + event.getEvents().stream().map(this::getEventInfo).collect(Collectors.toList()) + "]"); } private String getEventInfo(CacheEvent cacheEvent) { @@ -47,4 +52,4 @@ public class CustomerTransactionListener extends TransactionListenerAdapter { return cacheEvent.toString(); } } -} \ No newline at end of file +} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionWriter.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionWriter.java index 09e92796..16a5f723 100644 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionWriter.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/CustomerTransactionWriter.java @@ -13,26 +13,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.server; +import java.util.concurrent.atomic.AtomicBoolean; + import org.apache.geode.cache.TransactionEvent; import org.apache.geode.cache.TransactionWriter; import org.apache.geode.cache.TransactionWriterException; import org.apache.geode.internal.cache.TXEntryState; import org.apache.geode.internal.cache.TXEvent; + import org.springframework.stereotype.Component; -import java.util.concurrent.atomic.AtomicBoolean; - +/** + * @author Patrick Johnson + */ @Component public class CustomerTransactionWriter implements TransactionWriter { @Override public void beforeCommit(TransactionEvent transactionEvent) throws TransactionWriterException { + AtomicBoolean six_found = new AtomicBoolean(false); + ((TXEvent) transactionEvent).getEvents().forEach(event -> { - if (event instanceof TXEntryState.TxEntryEventImpl && ((TXEntryState.TxEntryEventImpl) event).getKey().equals(6L)) { + if (event instanceof TXEntryState.TxEntryEventImpl + && ((TXEntryState.TxEntryEventImpl) event).getKey().equals(6L)) { six_found.set(true); } }); @@ -41,4 +47,4 @@ public class CustomerTransactionWriter implements TransactionWriter { throw new TransactionWriterException("Customer for Key: 6 is being changed. Failing transaction"); } } -} \ No newline at end of file +} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServer.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServer.java index 40d45d51..791e879e 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServer.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServer.java @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.server; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -@SpringBootApplication(scanBasePackageClasses = TransactionalServerConfig.class) +/** + * @author Patrick Johnson + */ +@SpringBootApplication public class TransactionalServer { + public static void main(String[] args) { - new SpringApplicationBuilder(TransactionalServer.class) - .web(WebApplicationType.NONE) - .build() - .run(args); + new SpringApplicationBuilder(TransactionalServer.class).web(WebApplicationType.NONE).build().run(args); } -} \ No newline at end of file + +} diff --git a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServerConfig.java b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServerConfig.java index 739454dc..7a867471 100755 --- a/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServerConfig.java +++ b/geode/transactions/src/main/java/example/springdata/geode/client/transactions/server/TransactionalServerConfig.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.server; import example.springdata.geode.client.transactions.Customer; + import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Scope; + import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.CacheServerApplication; @@ -28,6 +29,9 @@ import org.springframework.data.gemfire.config.annotation.EnableManager; import org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTransactions; import org.springframework.transaction.annotation.EnableTransactionManagement; +/** + * @author Patrick Johnson + */ @EnableLocator @EnableTransactionManagement @EnableGemfireCacheTransactions diff --git a/geode/transactions/src/test/java/example/springdata/geode/client/transactions/client/TransactionalClientTests.java b/geode/transactions/src/test/java/example/springdata/geode/client/transactions/client/TransactionalClientTests.java index 69c4da99..ab341b82 100755 --- a/geode/transactions/src/test/java/example/springdata/geode/client/transactions/client/TransactionalClientTests.java +++ b/geode/transactions/src/test/java/example/springdata/geode/client/transactions/client/TransactionalClientTests.java @@ -13,41 +13,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.client.transactions.client; +import static org.assertj.core.api.Assertions.*; + import example.springdata.geode.client.transactions.Customer; import example.springdata.geode.client.transactions.EmailAddress; import example.springdata.geode.client.transactions.server.TransactionalServer; +import lombok.extern.apachecommons.CommonsLog; + +import java.io.IOException; + +import javax.annotation.Resource; + import org.apache.geode.cache.Region; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import javax.annotation.Resource; -import java.io.IOException; - -import static org.assertj.core.api.Assertions.assertThat; - +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = TransactionalClientConfig.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest(classes = TransactionalClientConfig.class) +@CommonsLog public class TransactionalClientTests extends ForkingClientServerIntegrationTestsSupport { - @Autowired - private CustomerService customerService; + @Autowired private CustomerService customerService; - @Resource(name = "Customers") - private Region customers; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Resource(name = "Customers") private Region customers; @BeforeClass public static void setup() throws IOException { @@ -57,26 +56,26 @@ public class TransactionalClientTests extends ForkingClientServerIntegrationTest @Test public void transactionsConfiguredCorrectly() throws InterruptedException { - logger.info("Number of Entries stored before = " + customerService.numberEntriesStoredOnServer()); + log.info("Number of Entries stored before = " + customerService.numberEntriesStoredOnServer()); customerService.createFiveCustomers(); assertThat(customerService.numberEntriesStoredOnServer()).isEqualTo(5); - logger.info("Number of Entries stored after = " + customerService.numberEntriesStoredOnServer()); - logger.info("Customer for ID before (transaction commit success) = " + customerService.findById(2L).get()); + log.info("Number of Entries stored after = " + customerService.numberEntriesStoredOnServer()); + log.info("Customer for ID before (transaction commit success) = " + customerService.findById(2L).get()); customerService.updateCustomersSuccess(); assertThat(customerService.numberEntriesStoredOnServer()).isEqualTo(5); Customer customer = customerService.findById(2L).get(); assertThat(customer.getFirstName()).isEqualTo("Humpty"); - logger.info("Customer for ID after (transaction commit success) = " + customer); + log.info("Customer for ID after (transaction commit success) = " + customer); try { customerService.updateCustomersFailure(); } catch (IllegalArgumentException exception) { - exception.printStackTrace(); + // do not print the exception to not spam the log } customer = customerService.findById(2L).get(); assertThat(customer.getFirstName()).isEqualTo("Humpty"); - logger.info("Customer for ID after (transaction commit failure) = " + customerService.findById(2L).get()); + log.info("Customer for ID after (transaction commit failure) = " + customerService.findById(2L).get()); Customer numpty = new Customer(2L, new EmailAddress("2@2.com"), "Numpty", "Hamilton"); Customer frumpy = new Customer(2L, new EmailAddress("2@2.com"), "Frumpy", "Hamilton"); @@ -84,6 +83,6 @@ public class TransactionalClientTests extends ForkingClientServerIntegrationTest customerService.updateCustomersWithDelay(10, frumpy); customer = customerService.findById(2L).get(); assertThat(customer).isEqualTo(frumpy); - logger.info("Customer for ID after 2 updates with delay = " + customer); + log.info("Customer for ID after 2 updates with delay = " + customer); } -} \ No newline at end of file +} diff --git a/geode/wan/pom.xml b/geode/wan/pom.xml index fb462688..7dfe8e36 100755 --- a/geode/wan/pom.xml +++ b/geode/wan/pom.xml @@ -2,22 +2,22 @@ - - example.springdata.geode - spring-data-geode-examples - 1.0-SNAPSHOT - - 4.0.0 + 4.0.0 - wan - example.springdata.geode.server - 1.0-SNAPSHOT - - - org.awaitility - awaitility - 3.1.6 - test - - - \ No newline at end of file + + org.springframework.data.examples + spring-data-geode-examples + 2.0.0.BUILD-SNAPSHOT + + + wan + + + + org.awaitility + awaitility + test + + + + diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/Customer.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/Customer.java index 71218b19..2fbec53a 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/Customer.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/Customer.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event; import lombok.Data; @@ -44,4 +43,4 @@ public class Customer implements Serializable { this.firstName = firstName; this.lastName = lastName; } -} \ No newline at end of file +} diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/CustomerRepository.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/CustomerRepository.java index f6889855..10e8bfb3 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/CustomerRepository.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/CustomerRepository.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event; import org.springframework.data.repository.CrudRepository; -public interface CustomerRepository extends CrudRepository { -} +/** + * @author Patrick Johnson + */ +public interface CustomerRepository extends CrudRepository {} diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/EmailAddress.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/EmailAddress.java index a82a808b..3f42aee8 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/EmailAddress.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/EmailAddress.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event; import lombok.Data; @@ -28,9 +27,10 @@ import java.io.Serializable; */ @Data public class EmailAddress implements Serializable { + private String value; public EmailAddress(String value) { this.value = value; } -} \ No newline at end of file +} diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/EvenNumberedKeyWanEventFilter.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/EvenNumberedKeyWanEventFilter.java index 5d8fb9e5..5446face 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/EvenNumberedKeyWanEventFilter.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/EvenNumberedKeyWanEventFilter.java @@ -20,8 +20,12 @@ import org.apache.geode.cache.wan.GatewayEventFilter; import org.apache.geode.cache.wan.GatewayQueueEvent; import org.springframework.stereotype.Component; +/** + * @author Patrick Johnson + */ @Component public class EvenNumberedKeyWanEventFilter implements GatewayEventFilter { + @Override public boolean beforeEnqueue(GatewayQueueEvent event) { return (Long) event.getKey() % 2 == 0; @@ -33,7 +37,5 @@ public class EvenNumberedKeyWanEventFilter implements GatewayEventFilter { } @Override - public void afterAcknowledgement(GatewayQueueEvent event) { - - } + public void afterAcknowledgement(GatewayQueueEvent event) {} } diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanEventSubstitutionFilter.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanEventSubstitutionFilter.java index f3c765b5..7a850b44 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanEventSubstitutionFilter.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanEventSubstitutionFilter.java @@ -13,20 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.server; import example.springdata.geode.server.wan.event.Customer; + import org.apache.geode.cache.EntryEvent; import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; + import org.springframework.stereotype.Component; +/** + * @author Patrick Johnson + */ @Component public class WanEventSubstitutionFilter implements GatewayEventSubstitutionFilter { @Override public Object getSubstituteValue(EntryEvent event) { Customer customer = event.getNewValue(); - return new Customer(customer.getId(), customer.getEmailAddress(), customer.getFirstName(), customer.getLastName().substring(0, 1)); + return new Customer(customer.getId(), customer.getEmailAddress(), customer.getFirstName(), + customer.getLastName().substring(0, 1)); } } diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServer.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServer.java index 17eaf079..c8bb4533 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServer.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServer.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.server; -import com.github.javafaker.Faker; -import com.github.javafaker.Internet; -import com.github.javafaker.Name; import example.springdata.geode.server.wan.event.Customer; import example.springdata.geode.server.wan.event.CustomerRepository; import example.springdata.geode.server.wan.event.EmailAddress; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.apachecommons.CommonsLog; + +import java.util.Scanner; +import java.util.stream.LongStream; + import org.springframework.boot.ApplicationRunner; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -31,23 +30,23 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; -import java.util.Scanner; -import java.util.stream.LongStream; +import com.github.javafaker.Faker; +import com.github.javafaker.Internet; +import com.github.javafaker.Name; +/** + * @author Patrick Johnson + */ @SpringBootApplication(scanBasePackageClasses = WanServerConfig.class) +@CommonsLog public class WanServer { - private Logger logger = LoggerFactory.getLogger(this.getClass()); - public static void main(String[] args) { - new SpringApplicationBuilder(WanServer.class) - .web(WebApplicationType.NONE) - .build() - .run(args); + new SpringApplicationBuilder(WanServer.class).web(WebApplicationType.NONE).build().run(args); } @Bean - @Profile({"default", "SiteA"}) + @Profile({ "default", "SiteA" }) public ApplicationRunner siteARunner() { return args -> new Scanner(System.in).nextLine(); } @@ -56,7 +55,7 @@ public class WanServer { @Profile("SiteB") public ApplicationRunner siteBRunner(CustomerRepository customerRepository) { return args -> { - logger.info("Inserting 300 customers"); + log.info("Inserting 300 customers"); createCustomers(customerRepository); }; } @@ -65,8 +64,7 @@ public class WanServer { Faker faker = new Faker(); Name fakerName = faker.name(); Internet fakerInternet = faker.internet(); - LongStream.range(0, 300).forEach(index -> - repository.save(new Customer(index, - new EmailAddress(fakerInternet.emailAddress()), fakerName.firstName(), fakerName.lastName()))); + LongStream.range(0, 300).forEach(index -> repository.save(new Customer(index, + new EmailAddress(fakerInternet.emailAddress()), fakerName.firstName(), fakerName.lastName()))); } } diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServerConfig.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServerConfig.java index efa23d84..4e850a1c 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServerConfig.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanServerConfig.java @@ -13,19 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.server; -import com.github.javafaker.Faker; import example.springdata.geode.server.wan.event.Customer; import example.springdata.geode.server.wan.event.CustomerRepository; import example.springdata.geode.server.wan.event.server.siteA.SiteAWanEnabledServerConfig; import example.springdata.geode.server.wan.event.server.siteB.SiteBWanServerConfig; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.PartitionAttributes; import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.wan.GatewaySender; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -35,51 +39,59 @@ import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.RegionAttributesFactoryBean; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; -import java.io.File; -import java.util.Arrays; +import com.github.javafaker.Faker; +/** + * @author Patrick Johnson + */ @Configuration @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) -@Import({SiteAWanEnabledServerConfig.class, SiteBWanServerConfig.class}) +@Import({ SiteAWanEnabledServerConfig.class, SiteBWanServerConfig.class }) public class WanServerConfig { + @Bean Faker faker() { return new Faker(); } @Bean(name = "DiskStore") - DiskStoreFactoryBean diskStore(GemFireCache gemFireCache, Faker faker) { - final DiskStoreFactoryBean diskStoreFactoryBean = new DiskStoreFactoryBean(); - final boolean completed = new File("/tmp/" + faker.name().firstName()).mkdirs(); - final DiskStoreFactoryBean.DiskDir[] diskDirs = {new DiskStoreFactoryBean.DiskDir("/tmp/" + faker.name().firstName())}; + DiskStoreFactoryBean diskStore(GemFireCache gemFireCache, Faker faker) throws IOException { + DiskStoreFactoryBean diskStoreFactoryBean = new DiskStoreFactoryBean(); + File tempDirectory = File.createTempFile(faker.name().firstName(), faker.name().firstName()); + tempDirectory.delete(); + tempDirectory.mkdirs(); + tempDirectory.deleteOnExit(); + DiskStoreFactoryBean.DiskDir[] diskDirs = { new DiskStoreFactoryBean.DiskDir(tempDirectory.getAbsolutePath()) }; diskStoreFactoryBean.setDiskDirs(Arrays.asList(diskDirs)); diskStoreFactoryBean.setCache(gemFireCache); return diskStoreFactoryBean; } @Bean - RegionAttributesFactoryBean regionAttributes(PartitionAttributes partitionAttributes) { - final RegionAttributesFactoryBean regionAttributesFactoryBean = new RegionAttributesFactoryBean<>(); + RegionAttributesFactoryBean regionAttributes( + PartitionAttributes partitionAttributes) { + RegionAttributesFactoryBean regionAttributesFactoryBean = new RegionAttributesFactoryBean<>(); regionAttributesFactoryBean.setPartitionAttributes(partitionAttributes); return regionAttributesFactoryBean; } @Bean PartitionAttributesFactoryBean partitionAttributes() { - final PartitionAttributesFactoryBean partitionAttributesFactoryBean = new PartitionAttributesFactoryBean<>(); + PartitionAttributesFactoryBean partitionAttributesFactoryBean = new PartitionAttributesFactoryBean<>(); partitionAttributesFactoryBean.setTotalNumBuckets(13); partitionAttributesFactoryBean.setRedundantCopies(0); return partitionAttributesFactoryBean; } @Bean("Customers") - PartitionedRegionFactoryBean createCustomerRegion(GemFireCache gemFireCache, RegionAttributes regionAttributes, GatewaySender gatewaySender) { - final PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); + PartitionedRegionFactoryBean createCustomerRegion(GemFireCache gemFireCache, + RegionAttributes regionAttributes, GatewaySender gatewaySender) { + PartitionedRegionFactoryBean partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>(); partitionedRegionFactoryBean.setCache(gemFireCache); partitionedRegionFactoryBean.setRegionName("Customers"); partitionedRegionFactoryBean.setDataPolicy(DataPolicy.PARTITION); partitionedRegionFactoryBean.setAttributes(regionAttributes); - partitionedRegionFactoryBean.setGatewaySenders(new GatewaySender[]{gatewaySender}); + partitionedRegionFactoryBean.setGatewaySenders(new GatewaySender[] { gatewaySender }); return partitionedRegionFactoryBean; } } diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanTransportEncryptionListener.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanTransportEncryptionListener.java index c26ec499..bc038039 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanTransportEncryptionListener.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/WanTransportEncryptionListener.java @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.server; -import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; +import lombok.extern.apachecommons.CommonsLog; import java.io.InputStream; import java.io.OutputStream; @@ -27,22 +23,28 @@ import java.util.zip.Adler32; import java.util.zip.CheckedInputStream; import java.util.zip.CheckedOutputStream; +import org.apache.geode.cache.wan.GatewayTransportFilter; + +import org.springframework.stereotype.Component; + +/** + * @author Patrick Johnson + */ @Component +@CommonsLog public class WanTransportEncryptionListener implements GatewayTransportFilter { private final Adler32 CHECKER = new Adler32(); - private Logger logger = LoggerFactory.getLogger(this.getClass()); - @Override public InputStream getInputStream(InputStream stream) { - logger.info("CheckedTransportFilter: Getting input stream"); + log.info("CheckedTransportFilter: Getting input stream"); return new CheckedInputStream(stream, CHECKER); } @Override public OutputStream getOutputStream(OutputStream stream) { - logger.info("CheckedTransportFilter: Getting output stream"); + log.info("CheckedTransportFilter: Getting output stream"); return new CheckedOutputStream(stream, CHECKER); } -} \ No newline at end of file +} diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteA/SiteAWanEnabledServerConfig.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteA/SiteAWanEnabledServerConfig.java index 70716434..fade7005 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteA/SiteAWanEnabledServerConfig.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteA/SiteAWanEnabledServerConfig.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.server.siteA; import org.apache.geode.cache.Cache; @@ -28,15 +27,19 @@ import org.springframework.data.gemfire.config.annotation.EnableLocator; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; +/** + * @author Patrick Johnson + */ @Configuration @CacheServerApplication(port = 0, locators = "localhost[10334]", name = "SiteA_Server", logLevel = "error") -@Profile({"default", "SiteA"}) +@Profile({ "default", "SiteA" }) @EnableLocator @EnableGemFireProperties(distributedSystemId = 1, remoteLocators = "localhost[20334]") public class SiteAWanEnabledServerConfig { + @Bean GatewayReceiverFactoryBean createGatewayReceiver(GemFireCache gemFireCache) { - final GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache); + GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache); gatewayReceiverFactoryBean.setStartPort(15000); gatewayReceiverFactoryBean.setEndPort(15010); gatewayReceiverFactoryBean.setManualStart(false); @@ -46,7 +49,7 @@ public class SiteAWanEnabledServerConfig { @Bean @DependsOn("DiskStore") GatewaySenderFactoryBean createGatewaySender(GemFireCache gemFireCache) { - final GatewaySenderFactoryBean gatewaySenderFactoryBean = new GatewaySenderFactoryBean(gemFireCache); + GatewaySenderFactoryBean gatewaySenderFactoryBean = new GatewaySenderFactoryBean(gemFireCache); gatewaySenderFactoryBean.setBatchSize(15); gatewaySenderFactoryBean.setBatchTimeInterval(1000); gatewaySenderFactoryBean.setRemoteDistributedSystemId(2); @@ -54,4 +57,4 @@ public class SiteAWanEnabledServerConfig { gatewaySenderFactoryBean.setDiskStoreRef("DiskStore"); return gatewaySenderFactoryBean; } -} \ No newline at end of file +} diff --git a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteB/SiteBWanServerConfig.java b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteB/SiteBWanServerConfig.java index ade0aaa9..c4c6efce 100755 --- a/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteB/SiteBWanServerConfig.java +++ b/geode/wan/src/main/java/example/springdata/geode/server/wan/event/server/siteB/SiteBWanServerConfig.java @@ -13,18 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.server.siteB; import example.springdata.geode.server.wan.event.Customer; import example.springdata.geode.server.wan.event.server.EvenNumberedKeyWanEventFilter; import example.springdata.geode.server.wan.event.server.WanEventSubstitutionFilter; import example.springdata.geode.server.wan.event.server.WanTransportEncryptionListener; + +import java.util.Collections; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.wan.GatewayEventFilter; import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; import org.apache.geode.cache.wan.GatewayTransportFilter; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @@ -36,18 +39,20 @@ import org.springframework.data.gemfire.config.annotation.EnableLocator; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; -import java.util.Collections; - +/** + * @author Patrick Johnson + */ @Configuration @CacheServerApplication(port = 0, locators = "localhost[20334]", name = "SiteB_Server", logLevel = "error") @Profile("SiteB") @EnableLocator(port = 20334) @EnableGemFireProperties(distributedSystemId = 2, remoteLocators = "localhost[10334]") -@Import({EvenNumberedKeyWanEventFilter.class, WanEventSubstitutionFilter.class, WanTransportEncryptionListener.class}) +@Import({ EvenNumberedKeyWanEventFilter.class, WanEventSubstitutionFilter.class, WanTransportEncryptionListener.class }) public class SiteBWanServerConfig { + @Bean GatewayReceiverFactoryBean createGatewayReceiver(GemFireCache gemFireCache) { - final GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache); + GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache); gatewayReceiverFactoryBean.setStartPort(25000); gatewayReceiverFactoryBean.setEndPort(25010); return gatewayReceiverFactoryBean; @@ -56,8 +61,9 @@ public class SiteBWanServerConfig { @Bean @DependsOn("DiskStore") GatewaySenderFactoryBean createGatewaySender(GemFireCache gemFireCache, GatewayEventFilter gatewayEventFilter, - GatewayTransportFilter gatewayTransportFilter, GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter) { - final GatewaySenderFactoryBean gatewaySenderFactoryBean = new GatewaySenderFactoryBean(gemFireCache); + GatewayTransportFilter gatewayTransportFilter, + GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter) { + GatewaySenderFactoryBean gatewaySenderFactoryBean = new GatewaySenderFactoryBean(gemFireCache); gatewaySenderFactoryBean.setBatchSize(15); gatewaySenderFactoryBean.setBatchTimeInterval(1000); gatewaySenderFactoryBean.setRemoteDistributedSystemId(1); @@ -68,4 +74,4 @@ public class SiteBWanServerConfig { gatewaySenderFactoryBean.setPersistent(false); return gatewaySenderFactoryBean; } -} \ No newline at end of file +} diff --git a/geode/wan/src/test/java/example/springdata/geode/server/wan/event/WanServerTests.java b/geode/wan/src/test/java/example/springdata/geode/server/wan/event/WanServerTests.java index 2db64de5..36e8fa00 100755 --- a/geode/wan/src/test/java/example/springdata/geode/server/wan/event/WanServerTests.java +++ b/geode/wan/src/test/java/example/springdata/geode/server/wan/event/WanServerTests.java @@ -16,36 +16,36 @@ package example.springdata.geode.server.wan.event; +import static org.assertj.core.api.Assertions.*; + import example.springdata.geode.server.wan.event.client.WanClientConfig; import example.springdata.geode.server.wan.event.server.WanServer; -import org.apache.geode.cache.Region; -import org.awaitility.Awaitility; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import lombok.extern.apachecommons.CommonsLog; -import javax.annotation.Resource; import java.io.IOException; import java.util.concurrent.TimeUnit; -import static org.assertj.core.api.Assertions.assertThat; +import javax.annotation.Resource; +import org.apache.geode.cache.Region; +import org.awaitility.Awaitility; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Patrick Johnson + */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = WanClientConfig.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@SpringBootTest(classes = WanClientConfig.class) +@CommonsLog public class WanServerTests extends ForkingClientServerIntegrationTestsSupport { - @Resource(name = "Customers") - private Region customers; - - private Logger logger = LoggerFactory.getLogger(this.getClass()); + @Resource(name = "Customers") private Region customers; @BeforeClass public static void setup() throws IOException { @@ -55,13 +55,16 @@ public class WanServerTests extends ForkingClientServerIntegrationTestsSupport { } @Test - @Ignore public void wanReplicationOccursCorrectly() { - Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> customers.keySetOnServer().size() == 150); - assertThat(customers.keySetOnServer().size()).isEqualTo(150); - logger.info(customers.keySetOnServer().size() + " entries replicated to siteA"); - customers.getAll(customers.keySetOnServer()).forEach((key, value) -> assertThat(value.getLastName().length()).isEqualTo(1)); - logger.info("All customers' last names changed to last initial on siteA"); + Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> customers.keySetOnServer().size() == 150); + + assertThat(customers.keySetOnServer()).hasSize(150); + + log.info(customers.keySetOnServer().size() + " entries replicated to siteA"); + + customers.getAll(customers.keySetOnServer()) + .forEach((key, value) -> assertThat(value.getLastName().length()).isEqualTo(1)); + log.info("All customers' last names changed to last initial on siteA"); } } diff --git a/geode/wan/src/test/java/example/springdata/geode/server/wan/event/client/WanClientConfig.java b/geode/wan/src/test/java/example/springdata/geode/server/wan/event/client/WanClientConfig.java index a522baeb..40f7b777 100755 --- a/geode/wan/src/test/java/example/springdata/geode/server/wan/event/client/WanClientConfig.java +++ b/geode/wan/src/test/java/example/springdata/geode/server/wan/event/client/WanClientConfig.java @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package example.springdata.geode.server.wan.event.client; import example.springdata.geode.server.wan.event.Customer; import example.springdata.geode.server.wan.event.CustomerRepository; + +import java.util.Collections; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientRegionShortcut; + import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -29,8 +32,6 @@ import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.support.ConnectionEndpoint; -import java.util.Collections; - /** * Spring JavaConfig configuration class to setup a Spring container and infrastructure components. * @@ -39,8 +40,10 @@ import java.util.Collections; */ @Configuration @EnableGemfireRepositories(basePackageClasses = CustomerRepository.class) -@ClientCacheApplication(name = "WanClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1) +@ClientCacheApplication(name = "WanClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, + retryAttempts = 1) public class WanClientConfig { + @Bean("Customers") protected ClientRegionFactoryBean configureProxyClientCustomerRegion(GemFireCache gemFireCache) { ClientRegionFactoryBean clientRegionFactoryBean = new ClientRegionFactoryBean<>(); @@ -55,7 +58,7 @@ public class WanClientConfig { @Value("${spring.data.geode.locator.host:localhost}") String hostname, @Value("${spring.data.geode.locator.port:10334}") int port) { - return (beanName, clientCacheFactoryBean) -> clientCacheFactoryBean.setLocators(Collections.singletonList( - new ConnectionEndpoint(hostname, port))); + return (beanName, clientCacheFactoryBean) -> clientCacheFactoryBean + .setLocators(Collections.singletonList(new ConnectionEndpoint(hostname, port))); } }