Changed to use the Eventuate Java Client
Simplified Spring MVC code since it supports CompletableFuture
This commit is contained in:
@@ -27,7 +27,7 @@ fi
|
|||||||
|
|
||||||
export SERVICE_HOST=$DOCKER_HOST_IP
|
export SERVICE_HOST=$DOCKER_HOST_IP
|
||||||
|
|
||||||
./gradlew $* build
|
./gradlew $* build -x :e2e-test:test
|
||||||
|
|
||||||
if [ -z "$EVENTUATE_API_KEY_ID" -o -z "$EVENTUATE_API_KEY_SECRET" ] ; then
|
if [ -z "$EVENTUATE_API_KEY_ID" -o -z "$EVENTUATE_API_KEY_SECRET" ] ; then
|
||||||
echo You must set EVENTUATE_API_KEY_ID and EVENTUATE_API_KEY_SECRET
|
echo You must set EVENTUATE_API_KEY_ID and EVENTUATE_API_KEY_SECRET
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ apply plugin: 'java'
|
|||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
compile project(":common-backend")
|
compile project(":common-backend")
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
import net.chrisrichardson.eventstore.EventUtil;
|
import io.eventuate.EventUtil;
|
||||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Command;
|
|
||||||
|
import io.eventuate.Command;
|
||||||
|
|
||||||
interface AccountCommand extends Command {
|
interface AccountCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EventStore;
|
import io.eventuate.AggregateRepository;
|
||||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
import io.eventuate.EventuateAggregateStore;
|
||||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJavaEventHandlers
|
@EnableEventHandlers
|
||||||
public class AccountConfiguration {
|
public class AccountConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -22,7 +22,7 @@ public class AccountConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AggregateRepository<Account, AccountCommand> accountRepository(EventStore eventStore) {
|
public AggregateRepository<Account, AccountCommand> accountRepository(EventuateAggregateStore eventStore) {
|
||||||
return new AggregateRepository<Account, AccountCommand>(Account.class, eventStore);
|
return new AggregateRepository<Account, AccountCommand>(Account.class, eventStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
|
||||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
import io.eventuate.AggregateRepository;
|
||||||
|
import io.eventuate.EntityWithIdAndVersion;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class AccountService {
|
public class AccountService {
|
||||||
|
|
||||||
@@ -14,7 +16,7 @@ public class AccountService {
|
|||||||
this.accountRepository = accountRepository;
|
this.accountRepository = accountRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public rx.Observable<EntityWithIdAndVersion<Account>> openAccount(BigDecimal initialBalance) {
|
public CompletableFuture<EntityWithIdAndVersion<Account>> openAccount(BigDecimal initialBalance) {
|
||||||
return accountRepository.save(new OpenAccountCommand(initialBalance));
|
return accountRepository.save(new OpenAccountCommand(initialBalance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,36 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
import net.chrisrichardson.eventstore.javaapi.consumer.EventHandlerContext;
|
import io.eventuate.EntityWithIdAndVersion;
|
||||||
|
import io.eventuate.EventHandlerContext;
|
||||||
|
import io.eventuate.EventHandlerMethod;
|
||||||
|
import io.eventuate.EventSubscriber;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.DebitRecordedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.DebitRecordedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.*;
|
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@EventSubscriber(id="accountEventHandlers")
|
@EventSubscriber(id="accountEventHandlers")
|
||||||
public class AccountWorkflow implements CompoundEventHandler {
|
public class AccountWorkflow {
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<?> debitAccount(EventHandlerContext<MoneyTransferCreatedEvent> ctx) {
|
public CompletableFuture<EntityWithIdAndVersion<Account>> debitAccount(EventHandlerContext<MoneyTransferCreatedEvent> ctx) {
|
||||||
MoneyTransferCreatedEvent event = ctx.getEvent();
|
MoneyTransferCreatedEvent event = ctx.getEvent();
|
||||||
BigDecimal amount = event.getDetails().getAmount();
|
BigDecimal amount = event.getDetails().getAmount();
|
||||||
EntityIdentifier transactionId = ctx.getEntityIdentifier();
|
String transactionId = ctx.getEntityId();
|
||||||
|
|
||||||
EntityIdentifier fromAccountId = event.getDetails().getFromAccountId();
|
String fromAccountId = event.getDetails().getFromAccountId();
|
||||||
|
|
||||||
return ctx.update(Account.class, fromAccountId, new DebitAccountCommand(amount, transactionId));
|
return ctx.update(Account.class, fromAccountId, new DebitAccountCommand(amount, transactionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<?> creditAccount(EventHandlerContext<DebitRecordedEvent> ctx) {
|
public CompletableFuture<EntityWithIdAndVersion<Account>> creditAccount(EventHandlerContext<DebitRecordedEvent> ctx) {
|
||||||
DebitRecordedEvent event = ctx.getEvent();
|
DebitRecordedEvent event = ctx.getEvent();
|
||||||
BigDecimal amount = event.getDetails().getAmount();
|
BigDecimal amount = event.getDetails().getAmount();
|
||||||
EntityIdentifier fromAccountId = event.getDetails().getToAccountId();
|
String fromAccountId = event.getDetails().getToAccountId();
|
||||||
EntityIdentifier transactionId = ctx.getEntityIdentifier();
|
String transactionId = ctx.getEntityId();
|
||||||
|
|
||||||
return ctx.update(Account.class, fromAccountId, new CreditAccountCommand(amount, transactionId));
|
return ctx.update(Account.class, fromAccountId, new CreditAccountCommand(amount, transactionId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class CreditAccountCommand implements AccountCommand {
|
public class CreditAccountCommand implements AccountCommand {
|
||||||
private final BigDecimal amount;
|
private final BigDecimal amount;
|
||||||
private final EntityIdentifier transactionId;
|
private final String transactionId;
|
||||||
|
|
||||||
public CreditAccountCommand(BigDecimal amount, EntityIdentifier transactionId) {
|
public CreditAccountCommand(BigDecimal amount, String transactionId) {
|
||||||
|
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.transactionId = transactionId;
|
this.transactionId = transactionId;
|
||||||
@@ -19,7 +19,7 @@ public class CreditAccountCommand implements AccountCommand {
|
|||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityIdentifier getTransactionId() {
|
public String getTransactionId() {
|
||||||
return transactionId;
|
return transactionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class DebitAccountCommand implements AccountCommand {
|
public class DebitAccountCommand implements AccountCommand {
|
||||||
private final BigDecimal amount;
|
private final BigDecimal amount;
|
||||||
private final EntityIdentifier transactionId;
|
private final String transactionId;
|
||||||
|
|
||||||
public DebitAccountCommand(BigDecimal amount, EntityIdentifier transactionId) {
|
public DebitAccountCommand(BigDecimal amount, String transactionId) {
|
||||||
|
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.transactionId = transactionId;
|
this.transactionId = transactionId;
|
||||||
@@ -19,7 +19,7 @@ public class DebitAccountCommand implements AccountCommand {
|
|||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityIdentifier getTransactionId() {
|
public String getTransactionId() {
|
||||||
return transactionId;
|
return transactionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.CommandProcessingAggregates;
|
import io.eventuate.Event;
|
||||||
import net.chrisrichardson.eventstore.Event;
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -15,7 +14,7 @@ public class AccountTest {
|
|||||||
public void testSomething() {
|
public void testSomething() {
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
BigDecimal initialBalance = new BigDecimal(512);
|
BigDecimal initialBalance = new BigDecimal(512);
|
||||||
List<Event> events = CommandProcessingAggregates.processToList(account, (AccountCommand)new OpenAccountCommand(initialBalance));
|
List<Event> events = account.process(new OpenAccountCommand(initialBalance));
|
||||||
|
|
||||||
Assert.assertEquals(1, events.size());
|
Assert.assertEquals(1, events.size());
|
||||||
Assert.assertEquals(AccountOpenedEvent.class, events.get(0).getClass());
|
Assert.assertEquals(AccountOpenedEvent.class, events.get(0).getClass());
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ dependencies {
|
|||||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||||
|
|
||||||
|
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
import io.eventuate.javaclient.httpstomp.spring.EventuateHttpStompClientConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({CommandSideWebAccountsConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
@Import({CommandSideWebAccountsConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class AccountsCommandSideServiceConfiguration {
|
public class AccountsCommandSideServiceConfiguration {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ dependencies {
|
|||||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||||
|
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import rx.Observable;
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/accounts")
|
@RequestMapping("/accounts")
|
||||||
@@ -21,8 +22,8 @@ public class AccountController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST)
|
@RequestMapping(method = RequestMethod.POST)
|
||||||
public Observable<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
|
public CompletableFuture<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
|
||||||
return accountService.openAccount(request.getInitialBalance())
|
return accountService.openAccount(request.getInitialBalance())
|
||||||
.map(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityIdentifier().getId()));
|
.thenApply(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,16 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({AccountConfiguration.class})
|
@Import({AccountConfiguration.class})
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
public class CommandSideWebAccountsConfiguration extends WebMvcConfigurerAdapter {
|
public class CommandSideWebAccountsConfiguration {
|
||||||
|
|
||||||
class FakeThing {}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
|
||||||
// https://jira.spring.io/browse/SPR-13083
|
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
|
||||||
handlers.add(0, new ObservableReturnValueHandler());
|
|
||||||
adapter.setReturnValueHandlers(handlers);
|
|
||||||
return new FakeThing();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({CommandSideWebAccountsConfiguration.class, JdbcEventStoreConfiguration.class})
|
@Import({CommandSideWebAccountsConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
|
||||||
public class AccountControllerIntegrationTestConfiguration {
|
public class AccountControllerIntegrationTestConfiguration {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,13 @@ apply plugin: 'java'
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":common-backend")
|
compile project(":common-backend")
|
||||||
|
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion"
|
compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion"
|
||||||
|
|
||||||
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
|
|
||||||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
|
|
||||||
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.3'
|
|
||||||
|
|
||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.CompletableFutureUtil;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
import net.chrisrichardson.eventstore.EntityNotFoundException;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
public class AccountQueryService {
|
public class AccountQueryService {
|
||||||
|
|
||||||
@@ -13,11 +12,11 @@ public class AccountQueryService {
|
|||||||
this.accountInfoRepository = accountInfoRepository;
|
this.accountInfoRepository = accountInfoRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<AccountInfo> findByAccountId(EntityIdentifier accountId) {
|
public CompletableFuture<AccountInfo> findByAccountId(String accountId) {
|
||||||
AccountInfo account = accountInfoRepository.findOne(accountId.getId());
|
AccountInfo account = accountInfoRepository.findOne(accountId);
|
||||||
if (account == null)
|
if (account == null)
|
||||||
return Observable.error(new AccountNotFoundException(accountId.getId()));
|
return CompletableFutureUtil.failedFuture(new AccountNotFoundException(accountId));
|
||||||
else
|
else
|
||||||
return Observable.just(account);
|
return CompletableFuture.completedFuture(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||||
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
|
import io.eventuate.DispatchedEvent;
|
||||||
|
import io.eventuate.EventHandlerMethod;
|
||||||
|
import io.eventuate.EventSubscriber;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountChangedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountChangedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
|
|
||||||
import net.chrisrichardson.eventstore.subscriptions.DispatchedEvent;
|
|
||||||
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
|
|
||||||
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
|
|
||||||
import rx.Observable;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -20,7 +18,7 @@ import java.math.BigDecimal;
|
|||||||
import static net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.MoneyUtil.toIntegerRepr;
|
import static net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.MoneyUtil.toIntegerRepr;
|
||||||
|
|
||||||
@EventSubscriber(id="querySideEventHandlers")
|
@EventSubscriber(id="querySideEventHandlers")
|
||||||
public class AccountQueryWorkflow implements CompoundEventHandler {
|
public class AccountQueryWorkflow {
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@@ -31,58 +29,55 @@ public class AccountQueryWorkflow implements CompoundEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<Object> create(DispatchedEvent<AccountOpenedEvent> de) {
|
public void create(DispatchedEvent<AccountOpenedEvent> de) {
|
||||||
AccountOpenedEvent event = de.event();
|
AccountOpenedEvent event = de.getEvent();
|
||||||
String id = de.getEntityIdentifier().getId();
|
String id = de.getEntityId();
|
||||||
String eventId = de.eventId().asString();
|
String eventId = de.getEventId().asString();
|
||||||
logger.info("**************** account version=" + id + ", " + eventId);
|
logger.info("**************** account version=" + id + ", " + eventId);
|
||||||
BigDecimal initialBalance = event.getInitialBalance();
|
BigDecimal initialBalance = event.getInitialBalance();
|
||||||
accountInfoUpdateService.create(id, initialBalance, eventId);
|
accountInfoUpdateService.create(id, initialBalance, eventId);
|
||||||
return Observable.just(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<Object> recordTransfer(DispatchedEvent<MoneyTransferCreatedEvent> de) {
|
public void recordTransfer(DispatchedEvent<MoneyTransferCreatedEvent> de) {
|
||||||
String eventId = de.eventId().asString();
|
String eventId = de.getEventId().asString();
|
||||||
String moneyTransferId = de.getEntityIdentifier().getId();
|
String moneyTransferId = de.getEntityId();
|
||||||
String fromAccountId = de.event().getDetails().getFromAccountId().getId();
|
String fromAccountId = de.getEvent().getDetails().getFromAccountId();
|
||||||
String toAccountId = de.event().getDetails().getToAccountId().getId();
|
String toAccountId = de.getEvent().getDetails().getToAccountId();
|
||||||
logger.info("**************** account version=" + fromAccountId + ", " + de.eventId().asString());
|
logger.info("**************** account version=" + fromAccountId + ", " + de.getEventId().asString());
|
||||||
logger.info("**************** account version=" + toAccountId + ", " + de.eventId().asString());
|
logger.info("**************** account version=" + toAccountId + ", " + de.getEventId().asString());
|
||||||
|
|
||||||
AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId, fromAccountId, toAccountId, toIntegerRepr(de.event().getDetails().getAmount()));
|
AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId, fromAccountId, toAccountId, toIntegerRepr(de.getEvent().getDetails().getAmount()));
|
||||||
|
|
||||||
|
|
||||||
accountInfoUpdateService.addTransaction(eventId, fromAccountId, ti);
|
accountInfoUpdateService.addTransaction(eventId, fromAccountId, ti);
|
||||||
accountInfoUpdateService.addTransaction(eventId, toAccountId, ti);
|
accountInfoUpdateService.addTransaction(eventId, toAccountId, ti);
|
||||||
|
|
||||||
return Observable.just(null);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<Object> recordDebit(DispatchedEvent<AccountDebitedEvent> de) {
|
public void recordDebit(DispatchedEvent<AccountDebitedEvent> de) {
|
||||||
return saveChange(de, -1);
|
saveChange(de, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<Object> recordCredit(DispatchedEvent<AccountCreditedEvent> de) {
|
public void recordCredit(DispatchedEvent<AccountCreditedEvent> de) {
|
||||||
return saveChange(de, +1);
|
saveChange(de, +1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AccountChangedEvent> Observable<Object> saveChange(DispatchedEvent<T> de, int delta) {
|
public <T extends AccountChangedEvent> void saveChange(DispatchedEvent<T> de, int delta) {
|
||||||
String changeId = de.eventId().asString();
|
String changeId = de.getEventId().asString();
|
||||||
String transactionId = de.event().getTransactionId().getId();
|
String transactionId = de.getEvent().getTransactionId();
|
||||||
long amount = toIntegerRepr(de.event().getAmount());
|
long amount = toIntegerRepr(de.getEvent().getAmount());
|
||||||
|
|
||||||
long balanceDelta = amount * delta;
|
long balanceDelta = amount * delta;
|
||||||
AccountChangeInfo ci = new AccountChangeInfo(changeId, transactionId, de.event().getClass().getSimpleName(), amount, balanceDelta);
|
AccountChangeInfo ci = new AccountChangeInfo(changeId, transactionId, de.getEvent().getClass().getSimpleName(), amount, balanceDelta);
|
||||||
String accountId = de.getEntityIdentifier().getId();
|
String accountId = de.getEntityId();
|
||||||
logger.info("**************** account version=" + accountId + ", " + de.eventId().asString());
|
logger.info("**************** account version=" + accountId + ", " + de.getEventId().asString());
|
||||||
|
|
||||||
accountInfoUpdateService.updateBalance(accountId, changeId, balanceDelta, ci);
|
accountInfoUpdateService.updateBalance(accountId, changeId, balanceDelta, ci);
|
||||||
|
|
||||||
return Observable.just(null);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||||
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
@@ -9,7 +9,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableMongoRepositories
|
@EnableMongoRepositories
|
||||||
@EnableJavaEventHandlers
|
@EnableEventHandlers
|
||||||
public class QuerySideAccountConfiguration {
|
public class QuerySideAccountConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import rx.Observable;
|
|
||||||
import rx.Subscriber;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -22,17 +20,7 @@ public class QuerySideDependencyChecker {
|
|||||||
try {
|
try {
|
||||||
logger.info("Checking mongodb connectivity {}", System.getenv("SPRING_DATA_MONGODB_URI"));
|
logger.info("Checking mongodb connectivity {}", System.getenv("SPRING_DATA_MONGODB_URI"));
|
||||||
|
|
||||||
Observable.<Object>create(new Observable.OnSubscribe<Object>() {
|
mongoTemplate.getDb().getCollectionNames();
|
||||||
@Override
|
|
||||||
public void call(Subscriber<? super Object> subscriber) {
|
|
||||||
try {
|
|
||||||
subscriber.onNext(mongoTemplate.getDb().getCollectionNames());
|
|
||||||
subscriber.onCompleted();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
subscriber.onError(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).timeout(5, TimeUnit.SECONDS).toBlocking().first();
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException("Error connecting to Mongo - have you set SPRING_DATA_MONGODB_URI or --spring.data.mongodb_uri?", e);
|
throw new RuntimeException("Error connecting to Mongo - have you set SPRING_DATA_MONGODB_URI or --spring.data.mongodb_uri?", e);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ dependencies {
|
|||||||
compile "org.springframework.boot:spring-boot-starter-web"
|
compile "org.springframework.boot:spring-boot-starter-web"
|
||||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||||
|
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
import io.eventuate.javaclient.httpstomp.spring.EventuateHttpStompClientConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({QuerySideWebConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
@Import({QuerySideWebConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class AccountsQuerySideServiceConfiguration {
|
public class AccountsQuerySideServiceConfiguration {
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||||
|
|
||||||
@@ -51,8 +51,8 @@ public class AccountsQuerySideServiceIntegrationTest {
|
|||||||
eventually(
|
eventually(
|
||||||
new Producer<GetAccountResponse>() {
|
new Producer<GetAccountResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public Observable<GetAccountResponse> produce() {
|
public CompletableFuture<GetAccountResponse> produce() {
|
||||||
return Observable.just(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
|
return CompletableFuture.completedFuture(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Verifier<GetAccountResponse>() {
|
new Verifier<GetAccountResponse>() {
|
||||||
|
|||||||
@@ -1,36 +1,14 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.QuerySideAccountConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.QuerySideAccountConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({QuerySideAccountConfiguration.class})
|
@Import({QuerySideAccountConfiguration.class})
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class QuerySideWebConfiguration extends WebMvcConfigurerAdapter {
|
public class QuerySideWebConfiguration {
|
||||||
|
|
||||||
class FakeThing {}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
|
||||||
// https://jira.spring.io/browse/SPR-13083
|
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
|
||||||
handlers.add(0, new ObservableReturnValueHandler());
|
|
||||||
adapter.setReturnValueHandlers(handlers);
|
|
||||||
return new FakeThing();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountNotFoundException;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountNotFoundException;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountQueryService;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountQueryService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class AccountQueryController {
|
public class AccountQueryController {
|
||||||
@@ -21,9 +21,9 @@ public class AccountQueryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/accounts/{accountId}", method = RequestMethod.GET)
|
@RequestMapping(value="/accounts/{accountId}", method = RequestMethod.GET)
|
||||||
public Observable<GetAccountResponse> get(@PathVariable String accountId) {
|
public CompletableFuture<GetAccountResponse> get(@PathVariable String accountId) {
|
||||||
return accountInfoQueryService.findByAccountId(new EntityIdentifier(accountId))
|
return accountInfoQueryService.findByAccountId(accountId)
|
||||||
.map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance())));
|
.thenApply(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseStatus(value= HttpStatus.NOT_FOUND, reason="account not found")
|
@ResponseStatus(value= HttpStatus.NOT_FOUND, reason="account not found")
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ dependencies {
|
|||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
|
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.accounts.AccountConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
|
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.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class})
|
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
|
||||||
public class BankingTestConfiguration {
|
public class BankingTestConfiguration {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
import io.eventuate.EntityWithIdAndVersion;
|
||||||
import net.chrisrichardson.eventstore.EntityWithMetadata;
|
import io.eventuate.EventuateAggregateStore;
|
||||||
import net.chrisrichardson.eventstore.EventStore;
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
|
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.accounts.AccountService;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
|
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.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.commandside.transactions.TransferState;
|
||||||
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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.IntegrationTest;
|
||||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
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.await;
|
||||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||||
|
|
||||||
@@ -38,7 +34,7 @@ public class MoneyTransferIntegrationTest {
|
|||||||
private MoneyTransferService moneyTransferService;
|
private MoneyTransferService moneyTransferService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EventStore eventStore;
|
private EventuateAggregateStore eventStore;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -48,52 +44,22 @@ public class MoneyTransferIntegrationTest {
|
|||||||
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
|
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
|
||||||
|
|
||||||
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
||||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
|
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
|
||||||
toAccount.getEntityIdentifier(),
|
toAccount.getEntityId(),
|
||||||
new BigDecimal(80))));
|
new BigDecimal(80))));
|
||||||
|
|
||||||
|
|
||||||
eventually (
|
eventually (
|
||||||
new Producer<EntityWithMetadata<Account>>() {
|
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
|
||||||
@Override
|
account -> Assert.assertEquals(new BigDecimal(70), account.getEntity().getBalance()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
eventually (
|
eventually (
|
||||||
new Producer<EntityWithMetadata<Account>>() {
|
() -> eventStore.find(Account.class, toAccount.getEntityId()),
|
||||||
@Override
|
account -> Assert.assertEquals(new BigDecimal(380), account.getEntity().getBalance()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
eventually (
|
eventually (
|
||||||
new Producer<EntityWithMetadata<MoneyTransfer>>() {
|
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
|
||||||
@Override
|
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -103,52 +69,22 @@ public class MoneyTransferIntegrationTest {
|
|||||||
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
|
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
|
||||||
|
|
||||||
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
||||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
|
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
|
||||||
toAccount.getEntityIdentifier(),
|
toAccount.getEntityId(),
|
||||||
new BigDecimal(200))));
|
new BigDecimal(200))));
|
||||||
|
|
||||||
|
|
||||||
eventually (
|
eventually (
|
||||||
new Producer<EntityWithMetadata<MoneyTransfer>>() {
|
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
|
||||||
@Override
|
updatedTransaction -> Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.getEntity().getState()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
eventually (
|
eventually (
|
||||||
new Producer<EntityWithMetadata<Account>>() {
|
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
|
||||||
@Override
|
account -> Assert.assertEquals(new BigDecimal(150), account.getEntity().getBalance()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
eventually (
|
eventually (
|
||||||
new Producer<EntityWithMetadata<Account>>() {
|
() -> eventStore.find(Account.class, toAccount.getEntityId()),
|
||||||
@Override
|
account -> Assert.assertEquals(new BigDecimal(300), account.getEntity().getBalance()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
import io.eventuate.EntityWithIdAndVersion;
|
||||||
import net.chrisrichardson.eventstore.EntityWithMetadata;
|
import io.eventuate.EntityWithMetadata;
|
||||||
import net.chrisrichardson.eventstore.EventStore;
|
import io.eventuate.EventuateAggregateStore;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
|
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.accounts.AccountService;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
|
||||||
@@ -37,7 +37,7 @@ public class AccountQuerySideIntegrationTest {
|
|||||||
private MoneyTransferService moneyTransferService;
|
private MoneyTransferService moneyTransferService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EventStore eventStore;
|
private EventuateAggregateStore eventStore;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AccountQueryService accountQueryService;
|
private AccountQueryService accountQueryService;
|
||||||
@@ -50,49 +50,19 @@ public class AccountQuerySideIntegrationTest {
|
|||||||
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
|
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
|
||||||
|
|
||||||
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
||||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
|
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
|
||||||
toAccount.getEntityIdentifier(),
|
toAccount.getEntityId(),
|
||||||
new BigDecimal(80))));
|
new BigDecimal(80))));
|
||||||
|
|
||||||
eventually(
|
eventually(
|
||||||
new Producer<EntityWithMetadata<MoneyTransfer>>() {
|
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
|
||||||
@Override
|
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
eventually(
|
eventually(
|
||||||
new Producer<AccountInfo>() {
|
() -> accountQueryService.findByAccountId(fromAccount.getEntityId()),
|
||||||
@Override
|
accountInfo -> Assert.assertEquals(70*100, accountInfo.getBalance()));
|
||||||
public Observable<AccountInfo> produce() {
|
|
||||||
return accountQueryService.findByAccountId(fromAccount.getEntityIdentifier());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Verifier<AccountInfo>() {
|
|
||||||
@Override
|
|
||||||
public void verify(AccountInfo accountInfo) {
|
|
||||||
Assert.assertEquals(70*100, accountInfo.getBalance());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
eventually(
|
eventually(
|
||||||
new Producer<AccountInfo>() {
|
() -> accountQueryService.findByAccountId(toAccount.getEntityId()),
|
||||||
@Override
|
accountInfo -> Assert.assertEquals(380*100, accountInfo.getBalance()));
|
||||||
public Observable<AccountInfo> produce() {
|
|
||||||
return accountQueryService.findByAccountId(toAccount.getEntityIdentifier());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Verifier<AccountInfo>() {
|
|
||||||
@Override
|
|
||||||
public void verify(AccountInfo accountInfo) {
|
|
||||||
Assert.assertEquals(380*100, accountInfo.getBalance());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
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.accounts.AccountConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
|
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.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideAccountConfiguration.class})
|
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class,
|
||||||
|
QuerySideAccountConfiguration.class})
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
public class AccountQuerySideTestConfiguration {
|
public class AccountQuerySideTestConfiguration {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class AccountChangedEvent implements Event {
|
public class AccountChangedEvent implements Event {
|
||||||
protected BigDecimal amount;
|
protected BigDecimal amount;
|
||||||
protected EntityIdentifier transactionId;
|
protected String transactionId;
|
||||||
|
|
||||||
public AccountChangedEvent(BigDecimal amount, EntityIdentifier transactionId) {
|
public AccountChangedEvent(BigDecimal amount, String transactionId) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.transactionId = transactionId;
|
this.transactionId = transactionId;
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ public class AccountChangedEvent implements Event {
|
|||||||
public AccountChangedEvent() {
|
public AccountChangedEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityIdentifier getTransactionId() {
|
public String getTransactionId() {
|
||||||
return transactionId;
|
return transactionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ public class AccountCreditedEvent extends AccountChangedEvent {
|
|||||||
private AccountCreditedEvent() {
|
private AccountCreditedEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountCreditedEvent(BigDecimal amount, EntityIdentifier transactionId) {
|
public AccountCreditedEvent(BigDecimal amount, String transactionId) {
|
||||||
super(amount, transactionId);
|
super(amount, transactionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
|
|
||||||
public class AccountDebitFailedDueToInsufficientFundsEvent implements Event {
|
public class AccountDebitFailedDueToInsufficientFundsEvent implements Event {
|
||||||
private EntityIdentifier transactionId;
|
private String transactionId;
|
||||||
|
|
||||||
private AccountDebitFailedDueToInsufficientFundsEvent() {
|
private AccountDebitFailedDueToInsufficientFundsEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountDebitFailedDueToInsufficientFundsEvent(EntityIdentifier transactionId) {
|
public AccountDebitFailedDueToInsufficientFundsEvent(String transactionId) {
|
||||||
this.transactionId = transactionId;
|
this.transactionId = transactionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityIdentifier getTransactionId() {
|
public String getTransactionId() {
|
||||||
return transactionId;
|
return transactionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ public class AccountDebitedEvent extends AccountChangedEvent {
|
|||||||
private AccountDebitedEvent() {
|
private AccountDebitedEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountDebitedEvent(BigDecimal amount, EntityIdentifier transactionId) {
|
public AccountDebitedEvent(BigDecimal amount, String transactionId) {
|
||||||
super(amount, transactionId);
|
super(amount, transactionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||||
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account")
|
@io.eventuate.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account")
|
||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
|
|
||||||
public class CreditRecordedEvent implements Event {
|
public class CreditRecordedEvent implements Event {
|
||||||
private TransferDetails details;
|
private TransferDetails details;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
// import io.eventuate.Event;
|
||||||
|
|
||||||
|
import io.eventuate.Event;
|
||||||
|
|
||||||
public class DebitRecordedEvent implements Event {
|
public class DebitRecordedEvent implements Event {
|
||||||
private TransferDetails details;
|
private TransferDetails details;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
|
|
||||||
public class FailedDebitRecordedEvent implements Event {
|
public class FailedDebitRecordedEvent implements Event {
|
||||||
private TransferDetails details;
|
private TransferDetails details;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||||
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
|
|
||||||
public class MoneyTransferCreatedEvent implements Event {
|
public class MoneyTransferCreatedEvent implements Event {
|
||||||
private TransferDetails details;
|
private TransferDetails details;
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
case class TransferDetails(fromAccountId : EntityIdentifier, toAccountId : EntityIdentifier, amount : BigDecimal)
|
case class TransferDetails(fromAccountId : String, toAccountId : String, amount : BigDecimal)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class TransferDetails {
|
public class TransferDetails {
|
||||||
|
|
||||||
private EntityIdentifier fromAccountId;
|
private String fromAccountId;
|
||||||
private EntityIdentifier toAccountId;
|
private String toAccountId;
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
|
|
||||||
private TransferDetails() {
|
private TransferDetails() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransferDetails(EntityIdentifier fromAccountId, EntityIdentifier toAccountId, BigDecimal amount) {
|
public TransferDetails(String fromAccountId, String toAccountId, BigDecimal amount) {
|
||||||
this.fromAccountId = fromAccountId;
|
this.fromAccountId = fromAccountId;
|
||||||
this.toAccountId = toAccountId;
|
this.toAccountId = toAccountId;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityIdentifier getFromAccountId() {
|
public String getFromAccountId() {
|
||||||
return fromAccountId;
|
return fromAccountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityIdentifier getToAccountId() {
|
public String getToAccountId() {
|
||||||
return toAccountId;
|
return toAccountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer")
|
@io.eventuate.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer")
|
||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts;
|
package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts;
|
||||||
|
|
||||||
|
|
||||||
|
import io.eventuate.javaclient.commonimpl.JSonMapper;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||||
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
|
|
||||||
import net.chrisrichardson.utils.json.JSonMapper;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -14,10 +13,10 @@ public class AccountOpenEventSerializationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldSerde() {
|
public void shouldSerde() {
|
||||||
AccountOpenedEvent event = new AccountOpenedEvent(new BigDecimal(55));
|
AccountOpenedEvent event = new AccountOpenedEvent(new BigDecimal(55));
|
||||||
String json = JSonMapper.toJson(event, EventStoreCommonObjectMapping.getObjectMapper());
|
String json = JSonMapper.toJson(event);
|
||||||
System.out.println("json=" + json);
|
System.out.println("json=" + json);
|
||||||
|
|
||||||
AccountOpenedEvent event2 = JSonMapper.fromJSon(AccountOpenedEvent.class, json, EventStoreCommonObjectMapping.getObjectMapper());
|
AccountOpenedEvent event2 = JSonMapper.fromJson(json, AccountOpenedEvent.class);
|
||||||
|
|
||||||
Assert.assertEquals(event.getInitialBalance(), event2.getInitialBalance());
|
Assert.assertEquals(event.getInitialBalance(), event2.getInitialBalance());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
compile "io.springfox:springfox-swagger2:2.2.2"
|
compile "io.springfox:springfox-swagger2:2.2.2"
|
||||||
compile 'io.springfox:springfox-swagger-ui:2.2.2'
|
compile 'io.springfox:springfox-swagger-ui:2.2.2'
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.context.request.async.DeferredResult;
|
import org.springframework.web.context.request.async.DeferredResult;
|
||||||
import rx.Observable;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
import springfox.documentation.schema.WildcardType;
|
import springfox.documentation.schema.WildcardType;
|
||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static springfox.documentation.schema.AlternateTypeRules.newRule;
|
import static springfox.documentation.schema.AlternateTypeRules.newRule;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -27,7 +27,7 @@ public class CommonSwaggerConfiguration {
|
|||||||
.apis(RequestHandlerSelectors.basePackage("net.chrisrichardson.eventstore.javaexamples.banking"))
|
.apis(RequestHandlerSelectors.basePackage("net.chrisrichardson.eventstore.javaexamples.banking"))
|
||||||
.build()
|
.build()
|
||||||
.pathMapping("/")
|
.pathMapping("/")
|
||||||
.genericModelSubstitutes(ResponseEntity.class, Observable.class)
|
.genericModelSubstitutes(ResponseEntity.class, CompletableFuture.class)
|
||||||
.alternateTypeRules(
|
.alternateTypeRules(
|
||||||
newRule(typeResolver.resolve(DeferredResult.class,
|
newRule(typeResolver.resolve(DeferredResult.class,
|
||||||
typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
|
typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||||
|
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.util;
|
|
||||||
|
|
||||||
import org.springframework.web.context.request.async.DeferredResult;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Subscriber;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class DeferredUtils {
|
|
||||||
|
|
||||||
public static <T> DeferredResult<T> toDeferredResult(Observable<T> o) {
|
|
||||||
final DeferredResult<T> d = new DeferredResult<T>();
|
|
||||||
final AtomicReference<T> r = new AtomicReference<T>();
|
|
||||||
|
|
||||||
o.single().subscribe(new Subscriber<T>() {
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
d.setResult(r.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
d.setErrorResult(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(T t) {
|
|
||||||
r.set(t);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.util;
|
|
||||||
|
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
|
||||||
import org.springframework.web.context.request.NativeWebRequest;
|
|
||||||
import org.springframework.web.context.request.async.DeferredResult;
|
|
||||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
|
||||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
|
||||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
|
||||||
|
|
||||||
|
|
||||||
public class ObservableReturnValueHandler implements HandlerMethodReturnValueHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsReturnType(MethodParameter returnType) {
|
|
||||||
return Observable.class.equals(returnType.getParameterType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
|
|
||||||
NativeWebRequest webRequest) throws Exception {
|
|
||||||
|
|
||||||
if (returnValue == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DeferredResult<?> d = DeferredUtils.toDeferredResult((Observable<?>) returnValue);
|
|
||||||
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(d, mavContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
apply plugin: VerifyMongoDBConfigurationPlugin
|
apply plugin: VerifyMongoDBConfigurationPlugin
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "org.scala-lang:scala-library:2.10.2"
|
|
||||||
|
|
||||||
testCompile project(":accounts-command-side-web")
|
testCompile project(":accounts-command-side-web")
|
||||||
testCompile project(":transactions-command-side-web")
|
testCompile project(":transactions-command-side-web")
|
||||||
testCompile project(":accounts-query-side-web")
|
testCompile project(":accounts-query-side-web")
|
||||||
@@ -10,8 +8,6 @@ dependencies {
|
|||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||||
testCompile scalaTestDependency
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|||||||
@@ -6,17 +6,14 @@ import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accou
|
|||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferRequest;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferRequest;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferResponse;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferResponse;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse;
|
||||||
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
|
|
||||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||||
|
|
||||||
@@ -43,14 +40,14 @@ public class EndToEndTest {
|
|||||||
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
{
|
/*{
|
||||||
|
|
||||||
for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
|
for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
|
||||||
if (mc instanceof MappingJackson2HttpMessageConverter) {
|
if (mc instanceof MappingJackson2HttpMessageConverter) {
|
||||||
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(EventStoreCommonObjectMapping.getObjectMapper());
|
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(JSonMapper.objectMapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -92,18 +89,10 @@ public class EndToEndTest {
|
|||||||
private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) {
|
private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) {
|
||||||
final BigDecimal inCents = toCents(expectedBalanceInDollars);
|
final BigDecimal inCents = toCents(expectedBalanceInDollars);
|
||||||
eventually(
|
eventually(
|
||||||
new Producer<GetAccountResponse>() {
|
() -> CompletableFuture.completedFuture(restTemplate.getForEntity(accountsQuerySideBaseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody()),
|
||||||
@Override
|
accountInfo -> {
|
||||||
public Observable<GetAccountResponse> produce() {
|
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
|
||||||
return Observable.just(restTemplate.getForEntity(accountsQuerySideBaseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
|
Assert.assertEquals(inCents, accountInfo.getBalance());
|
||||||
}
|
|
||||||
},
|
|
||||||
new Verifier<GetAccountResponse>() {
|
|
||||||
@Override
|
|
||||||
public void verify(GetAccountResponse accountInfo) {
|
|
||||||
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
|
|
||||||
Assert.assertEquals(inCents, accountInfo.getBalance());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
org.gradle.jvmargs=-XX:MaxPermSize=512m
|
org.gradle.jvmargs=-XX:MaxPermSize=512m
|
||||||
|
|
||||||
eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release
|
eventuateMavenRepoUrl=file:///Users/cer/.m2/testdeploy
|
||||||
|
|
||||||
scalaTestDependency=org.scalatest:scalatest_2.10:2.0
|
springBootVersion=1.3.5.RELEASE
|
||||||
|
|
||||||
springBootVersion=1.2.8.RELEASE
|
eventuateClientVersion=0.1.0-SNAPSHOT
|
||||||
|
|
||||||
eventStoreClientVersion=0.12
|
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-all.zip
|
distributionUrl=http\://services.gradle.org/distributions/gradle-2.11-all.zip
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ dependencies {
|
|||||||
compile "org.springframework.boot:spring-boot-starter-web"
|
compile "org.springframework.boot:spring-boot-starter-web"
|
||||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||||
|
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||||
|
|
||||||
|
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
|
||||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -14,7 +14,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class})
|
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class})
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class BankingWebConfiguration {
|
public class BankingWebConfiguration {
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||||
|
|
||||||
@@ -78,18 +78,10 @@ public class BankingWebIntegrationTest {
|
|||||||
private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) {
|
private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) {
|
||||||
final BigDecimal inCents = toCents(expectedBalanceInDollars);
|
final BigDecimal inCents = toCents(expectedBalanceInDollars);
|
||||||
eventually(
|
eventually(
|
||||||
new Producer<GetAccountResponse>() {
|
() -> CompletableFuture.completedFuture(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody()),
|
||||||
@Override
|
accountInfo -> {
|
||||||
public Observable<GetAccountResponse> produce() {
|
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
|
||||||
return Observable.just(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
|
Assert.assertEquals(inCents, accountInfo.getBalance());
|
||||||
}
|
|
||||||
},
|
|
||||||
new Verifier<GetAccountResponse>() {
|
|
||||||
@Override
|
|
||||||
public void verify(GetAccountResponse accountInfo) {
|
|
||||||
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
|
|
||||||
Assert.assertEquals(inCents, accountInfo.getBalance());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
|
|
||||||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
|
|
||||||
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.3'
|
|
||||||
compile "junit:junit:4.11"
|
compile "junit:junit:4.11"
|
||||||
|
compile "io.reactivex:rxjava:1.1.5"
|
||||||
|
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Aggregate;
|
import io.eventuate.Aggregate;
|
||||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.EventEntityUtil;
|
import io.eventuate.javaclient.spring.EventEntityUtil;
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@@ -17,19 +17,15 @@ public abstract class AbstractEntityEventTest {
|
|||||||
@Override
|
@Override
|
||||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||||
Class eventClass = method.getParameterTypes()[0];
|
Class eventClass = method.getParameterTypes()[0];
|
||||||
String entityClassName = EventEntityUtil.entityClassFor(eventClass);
|
EventEntityUtil.toEntityType(eventClass);
|
||||||
try {
|
|
||||||
Class.forName(entityClassName);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException("for " + entityClassName, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new ReflectionUtils.MethodFilter() {
|
new ReflectionUtils.MethodFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method) {
|
public boolean matches(Method method) {
|
||||||
return method.getName().startsWith("apply") && method.getDeclaringClass() != Aggregate.class && method.getDeclaringClass() != ReflectiveMutableCommandProcessingAggregate.class;
|
return method.getName().startsWith("apply") &&
|
||||||
|
method.getDeclaringClass() != Aggregate.class &&
|
||||||
|
method.getDeclaringClass() != ReflectiveMutableCommandProcessingAggregate.class;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
||||||
|
|
||||||
import rx.Observable;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface Producer<T> {
|
public interface Producer<T> {
|
||||||
public Observable<T> produce();
|
public CompletableFuture<T> produce();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
import rx.Subscriber;
|
||||||
import rx.functions.Action1;
|
import rx.functions.Action1;
|
||||||
import rx.functions.Func1;
|
import rx.functions.Func1;
|
||||||
import rx.functions.Func2;
|
import rx.functions.Func2;
|
||||||
|
import rx.internal.operators.OnSubscribeRefCount;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
public class TestUtil {
|
public class TestUtil {
|
||||||
|
|
||||||
public static <T> T await(Observable<T> o) {
|
public static <T> T await(CompletableFuture<T> o) {
|
||||||
return o.single().timeout(1, TimeUnit.SECONDS).toBlocking().getIterator().next();
|
try {
|
||||||
|
return o.get(1, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException | TimeoutException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +61,7 @@ public class TestUtil {
|
|||||||
@Override
|
@Override
|
||||||
public Observable<Outcome<T>> call(Long aLong) {
|
public Observable<Outcome<T>> call(Long aLong) {
|
||||||
try {
|
try {
|
||||||
return producer.produce().map(new Func1<T, Outcome<T>>() {
|
return fromCompletableFuture(producer.produce()).map(new Func1<T, Outcome<T>>() {
|
||||||
@Override
|
@Override
|
||||||
public Outcome<T> call(T t) {
|
public Outcome<T> call(T t) {
|
||||||
return new Success<T>(t);
|
return new Success<T>(t);
|
||||||
@@ -92,4 +101,21 @@ public class TestUtil {
|
|||||||
throw new RuntimeException((Throwable)possibleException);
|
throw new RuntimeException((Throwable)possibleException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> Observable<T> fromCompletableFuture(CompletableFuture<T> future) {
|
||||||
|
return Observable.create(new Observable.OnSubscribe<T>() {
|
||||||
|
@Override
|
||||||
|
public void call(Subscriber<? super T> subscriber) {
|
||||||
|
future.handle((result, throwable) -> {
|
||||||
|
if (throwable != null)
|
||||||
|
subscriber.onError(throwable);
|
||||||
|
else {
|
||||||
|
subscriber.onNext(result);
|
||||||
|
subscriber.onCompleted();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ apply plugin: 'java'
|
|||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
compile project(":common-backend")
|
compile project(":common-backend")
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile project(":testutil")
|
testCompile project(":testutil")
|
||||||
testCompile "junit:junit:4.11"
|
testCompile "junit:junit:4.11"
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Event;
|
import io.eventuate.Event;
|
||||||
import net.chrisrichardson.eventstore.EventUtil;
|
import io.eventuate.EventUtil;
|
||||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.*;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.Command;
|
import io.eventuate.Command;
|
||||||
|
|
||||||
interface MoneyTransferCommand extends Command {
|
interface MoneyTransferCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EventStore;
|
import io.eventuate.AggregateRepository;
|
||||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
import io.eventuate.EventuateAggregateStore;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.*;
|
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.config.EventStoreSubscriptionsConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import(EventStoreSubscriptionsConfiguration.class)
|
@EnableEventHandlers
|
||||||
@EnableJavaEventHandlers
|
|
||||||
public class MoneyTransferConfiguration {
|
public class MoneyTransferConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -25,7 +22,7 @@ public class MoneyTransferConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AggregateRepository<MoneyTransfer, MoneyTransferCommand> moneyTransferRepository(EventStore eventStore) {
|
public AggregateRepository<MoneyTransfer, MoneyTransferCommand> moneyTransferRepository(EventuateAggregateStore eventStore) {
|
||||||
return new AggregateRepository<MoneyTransfer, MoneyTransferCommand>(MoneyTransfer.class, eventStore);
|
return new AggregateRepository<MoneyTransfer, MoneyTransferCommand>(MoneyTransfer.class, eventStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
import io.eventuate.AggregateRepository;
|
||||||
|
import io.eventuate.EntityWithIdAndVersion;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
||||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
|
||||||
import rx.Observable;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class MoneyTransferService {
|
public class MoneyTransferService {
|
||||||
private final AggregateRepository<MoneyTransfer, MoneyTransferCommand> aggregateRepository;
|
private final AggregateRepository<MoneyTransfer, MoneyTransferCommand> aggregateRepository;
|
||||||
@@ -12,7 +13,7 @@ public class MoneyTransferService {
|
|||||||
this.aggregateRepository = aggregateRepository;
|
this.aggregateRepository = aggregateRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<EntityWithIdAndVersion<MoneyTransfer>> transferMoney(TransferDetails transferDetails) {
|
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> transferMoney(TransferDetails transferDetails) {
|
||||||
return aggregateRepository.save(new CreateMoneyTransferCommand(transferDetails));
|
return aggregateRepository.save(new CreateMoneyTransferCommand(transferDetails));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,31 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||||
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.javaapi.consumer.EventHandlerContext;
|
import io.eventuate.EntityWithIdAndVersion;
|
||||||
|
import io.eventuate.EventHandlerContext;
|
||||||
|
import io.eventuate.EventHandlerMethod;
|
||||||
|
import io.eventuate.EventSubscriber;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
|
|
||||||
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
|
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
@EventSubscriber(id="transferEventHandlers")
|
@EventSubscriber(id="transferEventHandlers")
|
||||||
public class MoneyTransferWorkflow implements CompoundEventHandler {
|
public class MoneyTransferWorkflow {
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<?> recordDebit(EventHandlerContext<AccountDebitedEvent> ctx) {
|
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordDebit(EventHandlerContext<AccountDebitedEvent> ctx) {
|
||||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitCommand());
|
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<?> recordDebitFailed(EventHandlerContext<AccountDebitFailedDueToInsufficientFundsEvent> ctx) {
|
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordDebitFailed(EventHandlerContext<AccountDebitFailedDueToInsufficientFundsEvent> ctx) {
|
||||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitFailedCommand());
|
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitFailedCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandlerMethod
|
@EventHandlerMethod
|
||||||
public Observable<?> recordCredit(EventHandlerContext<AccountCreditedEvent> ctx) {
|
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordCredit(EventHandlerContext<AccountCreditedEvent> ctx) {
|
||||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordCreditCommand());
|
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordCreditCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ dependencies {
|
|||||||
compile "org.springframework.boot:spring-boot-starter-web"
|
compile "org.springframework.boot:spring-boot-starter-web"
|
||||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||||
|
|
||||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||||
|
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
import io.eventuate.javaclient.httpstomp.spring.EventuateHttpStompClientConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({CommandSideWebTransactionsConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
@Import({CommandSideWebTransactionsConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class TransactionsCommandSideServiceConfiguration {
|
public class TransactionsCommandSideServiceConfiguration {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ dependencies {
|
|||||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||||
|
|
||||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,13 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
|
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({MoneyTransferConfiguration.class})
|
@Import({MoneyTransferConfiguration.class})
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
public class CommandSideWebTransactionsConfiguration extends WebMvcConfigurerAdapter {
|
public class CommandSideWebTransactionsConfiguration {
|
||||||
|
|
||||||
class FakeThing {}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
|
||||||
// https://jira.spring.io/browse/SPR-13083
|
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
|
||||||
handlers.add(0, new ObservableReturnValueHandler());
|
|
||||||
adapter.setReturnValueHandlers(handlers);
|
|
||||||
return new FakeThing();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
|
||||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
|
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.common.transactions.TransferDetails;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -9,7 +9,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import rx.Observable;
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/transfers")
|
@RequestMapping("/transfers")
|
||||||
@@ -23,13 +24,13 @@ public class MoneyTransferController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST)
|
@RequestMapping(method = RequestMethod.POST)
|
||||||
public Observable<CreateMoneyTransferResponse> createMoneyTransfer(@Validated @RequestBody CreateMoneyTransferRequest request) {
|
public CompletableFuture<CreateMoneyTransferResponse> createMoneyTransfer(@Validated @RequestBody CreateMoneyTransferRequest request) {
|
||||||
TransferDetails transferDetails = new TransferDetails(
|
TransferDetails transferDetails = new TransferDetails(
|
||||||
new EntityIdentifier(request.getFromAccountId()),
|
request.getFromAccountId(),
|
||||||
new EntityIdentifier(request.getToAccountId()),
|
request.getToAccountId(),
|
||||||
request.getAmount());
|
request.getAmount());
|
||||||
return moneyTransferService.transferMoney(transferDetails)
|
return moneyTransferService.transferMoney(transferDetails)
|
||||||
.map(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdentifier().getId()));
|
.thenApply(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdAndVersion().getEntityId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
|
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
|
||||||
|
|
||||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class})
|
@Import({CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
public class MoneyTransferControllerIntegrationTestConfiguration {
|
public class MoneyTransferControllerIntegrationTestConfiguration {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user