Java 16 migration for Geode examples.

See #606.
This commit is contained in:
Mark Paluch
2021-04-29 11:16:44 +02:00
parent 88aabe89e2
commit 6913f7ec5f
29 changed files with 74 additions and 70 deletions

View File

@@ -10,6 +10,7 @@
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>events</artifactId>
<artifactId>spring-data-geode-events-example</artifactId>
<name>Spring Data Geode - Events</name>
</project>

View File

@@ -29,7 +29,7 @@ public class CustomerCacheWriter extends CacheWriterAdapter<Long, Customer> {
@Override
public void beforeCreate(EntryEvent<Long, Customer> event) throws CacheWriterException {
EntryEventImpl e = (EntryEventImpl) event;
var e = (EntryEventImpl) event;
super.beforeCreate(e);
}
}

View File

@@ -23,8 +23,6 @@ import java.util.stream.LongStream;
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;
@@ -57,18 +55,18 @@ public class EventServer {
log.info("Completed creating orders ");
List<OrderProductSummary> allForProductID = orderProductSummaryRepository.findAllForProductID(3L);
var 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");
var random = new Random(System.nanoTime());
var 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);
var order = new Order(orderId, customerId, address);
IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> {
int quantity = random.nextInt(3) + 1;
var quantity = random.nextInt(3) + 1;
long productId = random.nextInt(3) + 1;
order.add(new LineItem(productRepository.findById(productId).get(), quantity));
});
@@ -79,7 +77,7 @@ public class EventServer {
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");
var macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), "An Apple notebook computer");
macbook.addAttribute("warranty", "included");
productRepository.save(macbook);
}

View File

@@ -47,7 +47,7 @@ public class EventServerConfig {
@Bean
AsyncEventQueueFactoryBean orderAsyncEventQueue(GemFireCache gemFireCache, AsyncEventListener orderAsyncEventListener) {
AsyncEventQueueFactoryBean asyncEventQueueFactoryBean = new AsyncEventQueueFactoryBean((Cache) gemFireCache);
var asyncEventQueueFactoryBean = new AsyncEventQueueFactoryBean((Cache) gemFireCache);
asyncEventQueueFactoryBean.setBatchTimeInterval(1000);
asyncEventQueueFactoryBean.setBatchSize(5);
asyncEventQueueFactoryBean.setAsyncEventListener(orderAsyncEventListener);

View File

@@ -16,8 +16,6 @@
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;

View File

@@ -39,10 +39,10 @@ public class OrderAsyncQueueListener implements AsyncEventListener {
public boolean processEvents(List<AsyncEvent> list) {
Map<Long, OrderProductSummary> summaryMap = new HashMap<>();
list.forEach(asyncEvent -> {
Order order = (Order) asyncEvent.getDeserializedValue();
var order = (Order) asyncEvent.getDeserializedValue();
if (order != null) {
order.getLineItems().forEach(lineItem -> {
OrderProductSummary orderProductSummary = summaryMap.get(lineItem.getProductId());
var orderProductSummary = summaryMap.get(lineItem.getProductId());
if (orderProductSummary == null) {
orderProductSummary = new OrderProductSummary(lineItem.getProductId(), new BigDecimal("0.00"));
}

View File

@@ -46,7 +46,7 @@ public class EventServerTests {
@Test
public void productCacheLoaderWorks() {
long size = productRepository.count();
var size = productRepository.count();
assertThat(this.productRepository.findById(777L)).isNotNull();
assertThat(productRepository.count()).isEqualTo(size + 1);