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);

View File

@@ -10,7 +10,8 @@
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>expiration-eviction</artifactId>
<artifactId>spring-data-geode-expiration-eviction-example</artifactId>
<name>Spring Data Geode - Expiration</name>
<dependencies>
<dependency>

View File

@@ -123,7 +123,7 @@ public class ExpirationEvictionServerTests {
@Test
public void evictionIsConfiguredCorrectly() {
final int evictionThreshold = 10;
final var 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())));

View File

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

View File

@@ -36,8 +36,8 @@ public class CustomerFunctions {
hasResult = true)
public List<Customer> listAllCustomersForEmailAddress(@RegionData Map<Long, Customer> customerData,
String... emailAddresses) {
List<String> emailAddressesAsList = Arrays.asList(emailAddresses);
List<Customer> collect = customerData.values().parallelStream()
var emailAddressesAsList = Arrays.asList(emailAddresses);
var collect = customerData.values().parallelStream()
.filter((customer) -> emailAddressesAsList.contains(customer.getEmailAddress().getValue()))
.collect(Collectors.toList());
return collect;

View File

@@ -80,12 +80,12 @@ public class FunctionInvocationClientTests extends ForkingClientServerIntegratio
public void functionsExecuteCorrectly() {
createCustomerData();
List<Customer> cust = customerFunctionExecutions.listAllCustomersForEmailAddress("2@2.com", "3@3.com").get(0);
var cust = customerFunctionExecutions.listAllCustomersForEmailAddress("2@2.com", "3@3.com").get(0);
assertThat(cust.size()).isEqualTo(2);
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);
var sum = productFunctionExecutions.sumPricesForAllProducts().get(0);
assertThat(sum).isEqualTo(BigDecimal.valueOf(1499.97));
log.info("Running function to sum up all product prices: \n\t" + sum);
@@ -94,7 +94,7 @@ public class FunctionInvocationClientTests extends ForkingClientServerIntegratio
sum = orderFunctionExecutions.sumPricesForAllProductsForOrder(1L).get(0);
assertThat(sum).isGreaterThanOrEqualTo(BigDecimal.valueOf(99.99));
log.info("Running function to sum up all order lineItems prices for order 1: \n\t" + sum);
Order order = orderRepository.findById(1L).get();
var order = orderRepository.findById(1L).get();
log.info("For order: \n\t " + order);
}
@@ -113,7 +113,7 @@ public class FunctionInvocationClientTests extends ForkingClientServerIntegratio
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);
@@ -123,13 +123,13 @@ public class FunctionInvocationClientTests extends ForkingClientServerIntegratio
public void createOrders() {
Random random = new Random();
Address address = new Address("it", "doesn't", "matter");
var random = new Random();
var 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);
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));
});

View File

@@ -10,7 +10,8 @@
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>queries</artifactId>
<artifactId>spring-data-geode-queries-example</artifactId>
<name>Spring Data Geode - Queries</name>
<dependencies>
<dependency>

View File

@@ -92,15 +92,15 @@ public class QueryTests extends ForkingClientServerIntegrationTestsSupport {
public void oqlQueriesConfiguredCorrectly() {
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");
var john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith");
var frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport");
var 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);
Customer customer = customerRepository.findById(2L).get();
var customer = customerRepository.findById(2L).get();
assertThat(customer).isEqualTo(frank);
log.info("Find customer with key=2 using GemFireRepository: " + customer);
List customerList = customerTemplate.find("select * from /Customers where id=$1", 2L).asList();

View File

@@ -10,7 +10,8 @@
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>security</artifactId>
<artifactId>spring-data-geode-security-example</artifactId>
<name>Spring Data Geode - Security</name>
<dependencies>
<dependency>

View File

@@ -84,7 +84,7 @@ public class User implements Comparable<User>, Cloneable, Principal, Serializabl
* @see ResourcePermission
*/
public boolean hasPermission(ResourcePermission permission) {
for (Role role : roles) {
for (var role : roles) {
if (role.hasPermission(permission)) {
return true;
}

View File

@@ -48,7 +48,7 @@ public abstract class CachingSecurityRepository implements SecurityRepository {
@Override
public User save(User user) {
User putUser = users.put(user.getName(), user);
var putUser = users.put(user.getName(), user);
return putUser != null ? putUser : user;
}
}

View File

@@ -54,8 +54,8 @@ public class JdbcSecurityRepository extends CachingSecurityRepository implements
public void afterPropertiesSet() {
List<Role> roles = this.jdbcTemplate.query(ROLES_QUERY, (resultSet, i) -> Role.newRole(resultSet.getString(1)));
HashMap<String, Role> roleMapping = new HashMap<>(roles.size());
var roles = this.jdbcTemplate.query(ROLES_QUERY, (resultSet, i) -> Role.newRole(resultSet.getString(1)));
var roleMapping = new HashMap<String, Role>(roles.size());
roles.forEach((role) -> {
this.jdbcTemplate.query(ROLE_PERMISSIONS_QUERY, Collections.singleton(role.getName()).toArray(),
@@ -65,7 +65,7 @@ public class JdbcSecurityRepository extends CachingSecurityRepository implements
roleMapping.put(role.getName(), role);
});
List<User> users = this.jdbcTemplate.query(USERS_QUERY,
var users = this.jdbcTemplate.query(USERS_QUERY,
(resultSet, i) -> createUser(resultSet.getString(1)).withCredentials(resultSet.getString(2)));
users.forEach((role) -> {

View File

@@ -64,9 +64,9 @@ public interface SecurityRepository {
/* (non-Javadoc) */
default int count() {
int count = 0;
Iterable<User> users = findAll();
for (User user : users) {
var count = 0;
var users = findAll();
for (var user : users) {
count++;
}
return count;
@@ -79,7 +79,7 @@ public interface SecurityRepository {
/* (non-Javadoc) */
default boolean delete(String username) {
User user = findBy(username);
var user = findBy(username);
if (user != null) {
return delete(user);
}
@@ -98,7 +98,7 @@ public interface SecurityRepository {
/* (non-Javadoc) */
default boolean deleteAll(Iterable<User> users) {
for (User user : users) {
for (var user : users) {
if (!delete(user)) {
return false;
}
@@ -134,7 +134,7 @@ public interface SecurityRepository {
/* (non-Javadoc) */
default User findBy(String username) {
for (User user : findAll()) {
for (var user : findAll()) {
if (user.getName().equals(username)) {
return user;
}

View File

@@ -53,12 +53,12 @@ public class SimpleSecurityManager extends SecurityManagerSupport {
*/
@Override
public Object authenticate(Properties securityProperties) {
String username = getUsername(securityProperties);
String password = getPassword(securityProperties);
var username = getUsername(securityProperties);
var password = getPassword(securityProperties);
logDebug("User with name [{}] is attempting to login with password [{}]", username, password);
User user = securityRepository.findBy(username);
var user = securityRepository.findBy(username);
if (isNotAuthentic(user, password)) {
throw new AuthenticationFailedException(String.format("Failed to authenticate user [%s]", username));
@@ -90,7 +90,7 @@ public class SimpleSecurityManager extends SecurityManagerSupport {
/* (non-Javadoc) */
protected boolean isAuthorized(Object principal, ResourcePermission permission) {
User user = resolveUser(principal);
var user = resolveUser(principal);
return user != null && isAuthorized(user, permission);
}

View File

@@ -61,9 +61,9 @@ public class SecurityEnabledClientShiroTests extends ForkingClientServerIntegrat
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");
var john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith");
var frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport");
var jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons");
customerRepository.save(john);
customerRepository.save(frank);
@@ -72,7 +72,7 @@ public class SecurityEnabledClientShiroTests extends ForkingClientServerIntegrat
assertThat(customers.keySetOnServer().size()).isEqualTo(3);
log.info("Customers saved on server:");
List<Customer> customerList = customerRepository.findAll();
var customerList = customerRepository.findAll();
assertThat(customerList.size()).isEqualTo(3);
assertThat(customerList.contains(john)).isTrue();

View File

@@ -61,9 +61,9 @@ public class SecurityEnabledClientTests extends ForkingClientServerIntegrationTe
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");
var john = new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith");
var frank = new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport");
var jude = new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons");
customerRepository.save(john);
customerRepository.save(frank);
@@ -73,7 +73,7 @@ public class SecurityEnabledClientTests extends ForkingClientServerIntegrationTe
log.info("Customers saved on server:");
List<Customer> customerList = customerRepository.findAll();
var customerList = customerRepository.findAll();
assertThat(customerList.size()).isEqualTo(3);
assertThat(customerList.contains(john)).isTrue();

View File

@@ -10,7 +10,8 @@
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>storage</artifactId>
<artifactId>spring-data-geode-storage-example</artifactId>
<name>Spring Data Geode - Storage</name>
<dependencies>
<dependency>

View File

@@ -57,12 +57,12 @@ public class StorageServer {
}
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));
});
@@ -73,7 +73,7 @@ public class StorageServer {
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

@@ -56,7 +56,7 @@ public class StorageServerTests {
assertThat(customers.getAttributes().getCompressor()).isInstanceOf(SnappyCompressor.class);
GemFireCacheImpl impl = (GemFireCacheImpl) cache;
var impl = (GemFireCacheImpl) cache;
assertThat(impl.getCachePerfStats().getTotalPostCompressedBytes())
.isLessThan(impl.getCachePerfStats().getTotalPreCompressedBytes());

View File

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

View File

@@ -33,7 +33,7 @@ public class CustomerTransactionWriter implements TransactionWriter {
@Override
public void beforeCommit(TransactionEvent transactionEvent) throws TransactionWriterException {
AtomicBoolean six_found = new AtomicBoolean(false);
var six_found = new AtomicBoolean(false);
transactionEvent.getEvents().forEach(event -> {
if (event instanceof EntryEvent<?, ?>

View File

@@ -64,7 +64,7 @@ public class TransactionalClientTests extends ForkingClientServerIntegrationTest
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();
var customer = customerService.findById(2L).get();
assertThat(customer.getFirstName()).isEqualTo("Humpty");
log.info("Customer for ID after (transaction commit success) = " + customer);
@@ -74,8 +74,8 @@ public class TransactionalClientTests extends ForkingClientServerIntegrationTest
assertThat(customer.getFirstName()).isEqualTo("Humpty");
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");
var numpty = new Customer(2L, new EmailAddress("2@2.com"), "Numpty", "Hamilton");
var frumpy = new Customer(2L, new EmailAddress("2@2.com"), "Frumpy", "Hamilton");
customerService.updateCustomersWithDelay(1000, numpty);
customerService.updateCustomersWithDelay(10, frumpy);
customer = customerService.findById(2L).get();

View File

@@ -21,6 +21,7 @@
<!-- <module>couchbase</module> -->
<module>cassandra</module>
<module>elasticsearch</module>
<!-- <module>geode</module> -->
<module>jdbc</module>
<module>jpa</module>
<module>ldap</module>