feat(tests): add redesigned concurrent banking test suite aligned with TransactionProcessor architecture
- Introduce BankAccount-focused concurrency tests based on Transaction → Processor → Account flow - Add stress tests for high-contention deposits, withdrawals, and bidirectional transfers - Validate atomicity and consistency across multi-threaded execution scenarios - Include deadlock detection tests under heavy transfer contention - Align all test cases with updated module structure and BankAccount concurrency contract
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package banking;
|
||||
|
||||
import dev.banking.model.*;
|
||||
import dev.banking.processor.TransactionProcessor;
|
||||
import dev.banking.service.BankingSystem;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class BankingSystemEndToEndStressTest {
|
||||
|
||||
@Test
|
||||
void fullSystemStressTest() throws Exception {
|
||||
|
||||
BankAccount a = new BankAccount(1, 1_000_000);
|
||||
BankAccount b = new BankAccount(2, 1_000_000);
|
||||
|
||||
Map<Integer, BankAccount> accounts = new HashMap<>();
|
||||
accounts.put(1, a);
|
||||
accounts.put(2, b);
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(8);
|
||||
TransactionProcessor processor = new TransactionProcessor(accounts);
|
||||
BankingSystem system = new BankingSystem(executor, processor);
|
||||
|
||||
List<Transaction> txs = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 50_000; i++) {
|
||||
txs.add(new TransferTransaction(1, 2, 1));
|
||||
txs.add(new TransferTransaction(2, 1, 1));
|
||||
}
|
||||
|
||||
system.processTransactions(txs);
|
||||
|
||||
executor.shutdown();
|
||||
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user