8000 Integration Test · sithuhlaing/java-design-patterns@82d7e57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82d7e57

Browse files
author
Serdar Hamzaoğulları
committed
Integration Test
1 parent 671230d commit 82d7e57

21 files changed

+181
-46
lines changed

event-sourcing/etc/event-sourcing.ucls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
<operations public="true" package="true" protected="true" private="true" static="true"/>
123123
</display>
124124
</class>
125-
<class id="13" language="java" name="com.iluwatar.event.sourcing.service.AccountService" project="event-sourcing"
125+
<class id="13" language="java" name="AccountService" project="event-sourcing"
126126
file="/event-sourcing/src/main/java/com/iluwatar/event/sourcing/service/AccountService.java" binary="false"
127127
corner="BOTTOM_RIGHT">
128128
<position height="-1" width="-1" x="687" y="68"/>
@@ -132,7 +132,7 @@
132132
<operations public="true" package="true" protected="true" private="true" static="true"/>
133133
</display>
134134
</class>
135-
<class id="14" language="java" name="com.iluwatar.event.sourcing.service.MoneyTransactionService"
135+
<class id="14" language="java" name="MoneyTransactionService"
136136
project="event-sourcing"
137137
file="/event-sourcing/src/main/java/com/iluwatar/event/sourcing/service/MoneyTransactionService.java" binary="false"
138138
corner="BOTTOM_RIGHT">

event-sourcing/src/main/java/com/iluwatar/event/sourcing/service/AccountService.java renamed to event-sourcing/src/main/java/com/iluwatar/event/sourcing/AccountService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23-
package com.iluwatar.event.sourcing.service;
23+
package com.iluwatar.event.sourcing;
2424

2525
import com.iluwatar.event.sourcing.api.EventProcessor;
2626
import com.iluwatar.event.sourcing.event.AccountCreateEvent;
2727
import java.util.Date;
2828

2929
/**
30-
* Created by serdarh on 06.08.2017.
30+
* Created by Serdar Hamzaogullari on 06.08.2017.
3131
*/
3232
public class AccountService {
3333

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23-
package com.iluwatar.event.sourcing.service;
23+
package com.iluwatar.event.sourcing;
2424

2525
import com.iluwatar.event.sourcing.api.EventProcessor;
2626
import com.iluwatar.event.sourcing.event.MoneyDepositEvent;
@@ -30,7 +30,7 @@
3030
import java.util.Date;
3131

3232
/**
33-
* Created by serdarh on 06.08.2017.
33+
* Created by Serdar Hamzaogullari on 06.08.2017.
3434
*/
3535
public class MoneyTransactionService {
3636

event-sourcing/src/main/java/com/iluwatar/event/sourcing/service/SequenceIdGenerator.java renamed to event-sourcing/src/main/java/com/iluwatar/event/sourcing/SequenceIdGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23-
package com.iluwatar.event.sourcing.service;
23+
package com.iluwatar.event.sourcing;
2424

2525
/**
26-
* Created by serdarh on 06.08.2017.
26+
* Created by Serdar Hamzaogullari on 06.08.2017.
2727
*/
2828
public class SequenceIdGenerator {
2929

event-sourcing/src/main/java/com/iluwatar/event/sourcing/api/DomainEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.io.Serializable;
2626

2727
/**
28-
* Created by serdarh on 06.08.2017.
28+
* Created by Serdar Hamzaogullari on 06.08.2017.
2929
*/
3030
public abstract class DomainEvent implements Serializable {
3131

event-sourcing/src/main/java/com/iluwatar/event/sourcing/api/EventProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package com.iluwatar.event.sourcing.api;
2424

2525
/**
26-
* Created by serdarh on 06.08.2017.
26+
* Created by Serdar Hamzaogullari on 06.08.2017.
2727
*/
2828
public interface EventProcessor {
2929

event-sourcing/src/main/java/com/iluwatar/event/sourcing/api/ProcessorJournal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package com.iluwatar.event.sourcing.api;
2424

2525
/**
26-
* Created by serdarh on 06.08.2017.
26+
* Created by Serdar Hamzaogullari on 06.08.2017.
2727
*/
2828
public interface ProcessorJournal {
2929

event-sourcing/src/main/java/com/iluwatar/event/sourcing/app/App.java

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,82 @@
2424

2525
import com.iluwatar.event.sourcing.journal.JsonFileJournal;
2626
import com.iluwatar.event.sourcing.processor.DomainEventProcessor;
27-
import com.iluwatar.event.sourcing.service.AccountService;
28-
import com.iluwatar.event.sourcing.service.MoneyTransactionService;
27+
import com.iluwatar.event.sourcing.AccountService;
28+
import com.iluwatar.event.sourcing.MoneyTransactionService;
2929
import com.iluwatar.event.sourcing.state.AccountAggregate;
3030
import java.math.BigDecimal;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3133

3234
/**
33-
* Created by serdarh on 06.08.2017.
35+
* Event Sourcing : Instead of storing just the current state of the data in a domain, use an
36+
* append-only store to record the full series of actions taken on that data. The store acts as the
37+
* system of record and can be used to materialize the domain objects. This can simplify tasks in
38+
* complex domains, by avoiding the need to synchronize the data model and the business domain,
39+
* while improving performance, scalability, and responsiveness. It can also provide consistency for
40+
* transactional data, and maintain full audit trails and history that can enable compensating
41+
* actions.
42+
*
43+
* This App class is an example usage of Event Sourcing pattern. As an example, two bank account is
44+
* created, then some money deposit and transfer actions are taken so a new state of accounts is
45+
* created. At that point, state is cleared in order to represent a system shot down. After the shot
46+
* down, system state is recovered by re-creating the past events from event journal. Then state is
47+
* printed so a user can view the last state is same with the state before system shot down.
48+
*
49+
* Created by Serdar Hamzaogullari on 06.08.2017.
3450
*/
3551
public class App {
3652

53+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
54+
public static final int ACCOUNT_OF_DAENERYS = 1;
55+
public static final int ACCOUNT_OF_JON = 2;
56+
3757
/**
3858
* The entry point of application.
3959
*
4060
* @param args the input arguments
4161
*/
4262
public static void main(String[] args) {
43-
System.out.println("Running the system first time............");
4463

4564
DomainEventProcessor domainEventProcessor = new DomainEventProcessor();
4665
JsonFileJournal jsonFileJournal = new JsonFileJournal();
47-
jsonFileJournal.reset();
4866
domainEventProcessor.setPrecessorJournal(jsonFileJournal);
49-
50-
System.out.println("Creating th accounts............");
51-
5267
AccountService accountService = new AccountService(domainEventProcessor);
5368
MoneyTransactionService moneyTransactionService = new MoneyTransactionService(
5469
domainEventProcessor);
55-
accountService.createAccount(1, "Daenerys Targaryen");
56-
accountService.createAccount(2, "Jon Snow");
5770

58-
System.out.println("Do some money operations............");
71+
LOGGER.info("Running the system first time............");
72+
jsonFileJournal.reset();
73+
74+
LOGGER.info("Creating th accounts............");
75+
76+
accountService.createAccount(ACCOUNT_OF_DAENERYS, "Daenerys Targaryen");
77+
accountService.createAccount(ACCOUNT_OF_JON, "Jon Snow");
5978

60-
moneyTransactionService.depositMoney(1, new BigDecimal("100000"));
61-
moneyTransactionService.depositMoney(2, new BigDecimal("100"));
79+
LOGGER.info("Do some money operations............");
6280

63-
moneyTransactionService.transferMoney(1, 2, new BigDecimal("10000"));
64-
moneyTransactionService.withdrawalMoney(2, new BigDecimal("1000"));
81+
moneyTransactionService.depositMoney(ACCOUNT_OF_DAENERYS, new BigDecimal("100000"));
82+
moneyTransactionService.depositMoney(ACCOUNT_OF_JON, new BigDecimal("100"));
6583

66-
System.out.println("...............State:............");
67-
System.out.println(AccountAggregate.getAccount(1));
68-
System.out.println(AccountAggregate.getAccount(2));
84+
moneyTransactionService.transferMoney(ACCOUNT_OF_DAENERYS, ACCOUNT_OF_JON, new BigDecimal("10000"));
85+
moneyTransactionService.withdrawalMoney(ACCOUNT_OF_JON, new BigDecimal("1000"));
6986

70-
System.out.println("At that point system goes down state in memory cleared............");
87+
LOGGER.info("...............State:............");
88+
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString());
89+
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_JON).toString());
7190

91+
LOGGER.info("At that point system had a shot down, state in memory is cleared............");
7292
AccountAggregate.resetState();
7393

74-
System.out.println("Recover the syste by the events in journal file............");
94+
LOGGER.info("Recover the system by the events in journal file............");
7595

7696
domainEventProcessor = new DomainEventProcessor();
7797
jsonFileJournal = new JsonFileJournal();
7898
domainEventProcessor.setPrecessorJournal(jsonFileJournal);
7999
domainEventProcessor.recover();
80100

81-
System.out.println("...............State Recovered:............");
82-
System.out.println(AccountAggregate.getAccount(1));
83-
System.out.println(AccountAggregate.getAccount(2));
101+
LOGGER.info("...............Recovered State:............");
102+
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString());
103+
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_JON).toString());
84104
}
85105
}

event-sourcing/src/main/java/com/iluwatar/event/sourcing/domain/Account.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.List;
3434

3535
/**
36-
* Created by serdarh on 06.08.2017.
36+
* Created by Serdar Hamzaogullari on 06.08.2017.
3737
*/
3838
public class Account {
3939

event-sourcing/src/main/java/com/iluwatar/event/sourcing/domain/Transaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.math.BigDecimal;
2626

2727
/**
28-
* Created by serdarh on 06.08.2017.
28+
* Created by Serdar Hamzaogullari on 06.08.2017.
2929
*/
3030
public class Transaction {
3131

0 commit comments

Comments
 (0)
0