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:
2026-06-05 21:53:35 +03:30
parent a063274fb9
commit 74963fbf29
8 changed files with 214 additions and 169 deletions
@@ -0,0 +1,42 @@
package banking;
import dev.banking.model.BankAccount;
import org.junit.jupiter.api.Test;
import java.util.concurrent.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class BankAccountDepositWithdrawRaceTest {
@Test
void concurrentDepositWithdraw() throws Exception {
BankAccount account = new BankAccount(1, 1_000_000);
ExecutorService executor = Executors.newFixedThreadPool(100);
CountDownLatch latch = new CountDownLatch(100);
for (int i = 0; i < 50; i++) {
executor.submit(() -> {
for (int j = 0; j < 10_000; j++) {
account.deposit(1);
}
latch.countDown();
});
executor.submit(() -> {
for (int j = 0; j < 10_000; j++) {
account.withdraw(1);
}
latch.countDown();
});
}
latch.await();
executor.shutdown();
assertEquals(1_000_000, account.getBalance());
}
}