Changed to use the Eventuate Java Client

Simplified Spring MVC code since it supports CompletableFuture
This commit is contained in:
Chris Richardson
2016-05-16 06:27:47 -07:00
parent c5778b1379
commit 4b3fe001e7
73 changed files with 290 additions and 531 deletions

View File

@@ -8,6 +8,6 @@ dependencies {
testCompile project(":testutil")
testCompile "junit:junit:4.11"
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
}

View File

@@ -1,14 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import net.chrisrichardson.utils.config.MetricRegistryConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class})
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
public class BankingTestConfiguration {
}

View File

@@ -1,14 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
import net.chrisrichardson.eventstore.EntityWithMetadata;
import net.chrisrichardson.eventstore.EventStore;
import io.eventuate.EntityWithIdAndVersion;
import io.eventuate.EventuateAggregateStore;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.TransferState;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -16,12 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import rx.Observable;
import java.math.BigDecimal;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.await;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
@@ -38,7 +34,7 @@ public class MoneyTransferIntegrationTest {
private MoneyTransferService moneyTransferService;
@Autowired
private EventStore eventStore;
private EventuateAggregateStore eventStore;
@Test
@@ -48,52 +44,22 @@ public class MoneyTransferIntegrationTest {
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
toAccount.getEntityIdentifier(),
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(80))));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, fromAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(70), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(70), account.getEntity().getBalance()));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, toAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(380), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, toAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(380), account.getEntity().getBalance()));
eventually (
new Producer<EntityWithMetadata<MoneyTransfer>>() {
@Override
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
return (Observable<EntityWithMetadata<MoneyTransfer>>)eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
@Override
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.entity().getState());
}
});
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
}
@Test
@@ -103,52 +69,22 @@ public class MoneyTransferIntegrationTest {
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
toAccount.getEntityIdentifier(),
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(200))));
eventually (
new Producer<EntityWithMetadata<MoneyTransfer>>() {
@Override
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
return (Observable<EntityWithMetadata<MoneyTransfer>>)eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
@Override
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.entity().getState());
}
});
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.getEntity().getState()));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, fromAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(150), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(150), account.getEntity().getBalance()));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, toAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(300), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, toAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(300), account.getEntity().getBalance()));
}

View File

@@ -1,8 +1,8 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
import net.chrisrichardson.eventstore.EntityWithMetadata;
import net.chrisrichardson.eventstore.EventStore;
import io.eventuate.EntityWithIdAndVersion;
import io.eventuate.EntityWithMetadata;
import io.eventuate.EventuateAggregateStore;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
@@ -37,7 +37,7 @@ public class AccountQuerySideIntegrationTest {
private MoneyTransferService moneyTransferService;
@Autowired
private EventStore eventStore;
private EventuateAggregateStore eventStore;
@Autowired
private AccountQueryService accountQueryService;
@@ -50,49 +50,19 @@ public class AccountQuerySideIntegrationTest {
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
toAccount.getEntityIdentifier(),
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(80))));
eventually(
new Producer<EntityWithMetadata<MoneyTransfer>>() {
@Override
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
return eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
@Override
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.entity().getState());
}
});
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
eventually(
new Producer<AccountInfo>() {
@Override
public Observable<AccountInfo> produce() {
return accountQueryService.findByAccountId(fromAccount.getEntityIdentifier());
}
},
new Verifier<AccountInfo>() {
@Override
public void verify(AccountInfo accountInfo) {
Assert.assertEquals(70*100, accountInfo.getBalance());
}
});
() -> accountQueryService.findByAccountId(fromAccount.getEntityId()),
accountInfo -> Assert.assertEquals(70*100, accountInfo.getBalance()));
eventually(
new Producer<AccountInfo>() {
@Override
public Observable<AccountInfo> produce() {
return accountQueryService.findByAccountId(toAccount.getEntityIdentifier());
}
},
new Verifier<AccountInfo>() {
@Override
public void verify(AccountInfo accountInfo) {
Assert.assertEquals(380*100, accountInfo.getBalance());
}
});
() -> accountQueryService.findByAccountId(toAccount.getEntityId()),
accountInfo -> Assert.assertEquals(380*100, accountInfo.getBalance()));
}
}

View File

@@ -1,14 +1,15 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideAccountConfiguration.class})
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class,
QuerySideAccountConfiguration.class})
@EnableAutoConfiguration
public class AccountQuerySideTestConfiguration {
}