#587 - Remove use of internal Geode classes in Transactional example.

This commit is contained in:
Patrick Johnson
2020-11-04 05:37:10 -08:00
committed by GitHub
parent 8d0cfc0046
commit 6564fa8ca6
3 changed files with 12 additions and 18 deletions

View File

@@ -18,14 +18,12 @@ 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.springframework.stereotype.Component;
import org.apache.geode.cache.CacheEvent;
import org.apache.geode.cache.EntryEvent;
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;
/**
* @author Patrick Johnson
@@ -45,9 +43,9 @@ public class CustomerTransactionListener extends TransactionListenerAdapter {
+ event.getEvents().stream().map(this::getEventInfo).collect(Collectors.toList()) + "]");
}
private String getEventInfo(CacheEvent cacheEvent) {
if (cacheEvent instanceof TXEntryState.TxEntryEventImpl) {
return ((TXEntryState.TxEntryEventImpl) cacheEvent).getNewValue().toString();
private String getEventInfo(CacheEvent<?, ?> cacheEvent) {
if (cacheEvent instanceof EntryEvent) {
return ((EntryEvent<?, ?>) cacheEvent).getNewValue().toString();
} else {
return cacheEvent.toString();
}

View File

@@ -17,11 +17,10 @@ package example.springdata.geode.client.transactions.server;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.geode.cache.EntryEvent;
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;
@@ -36,9 +35,9 @@ public class CustomerTransactionWriter implements TransactionWriter {
AtomicBoolean six_found = new AtomicBoolean(false);
((TXEvent) transactionEvent).getEvents().forEach(event -> {
if (event instanceof TXEntryState.TxEntryEventImpl
&& ((TXEntryState.TxEntryEventImpl) event).getKey().equals(6L)) {
transactionEvent.getEvents().forEach(event -> {
if (event instanceof EntryEvent<?, ?>
&& ((EntryEvent<?, ?>) event).getKey().equals(6L)) {
six_found.set(true);
}
});

View File

@@ -16,6 +16,7 @@
package example.springdata.geode.client.transactions.client;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import example.springdata.geode.client.transactions.Customer;
import example.springdata.geode.client.transactions.EmailAddress;
@@ -67,11 +68,7 @@ public class TransactionalClientTests extends ForkingClientServerIntegrationTest
assertThat(customer.getFirstName()).isEqualTo("Humpty");
log.info("Customer for ID after (transaction commit success) = " + customer);
try {
customerService.updateCustomersFailure();
} catch (IllegalArgumentException exception) {
// do not print the exception to not spam the log
}
assertThrows(IllegalArgumentException.class, () -> customerService.updateCustomersFailure());
customer = customerService.findById(2L).get();
assertThat(customer.getFirstName()).isEqualTo("Humpty");