- 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
37 lines
921 B
Java
37 lines
921 B
Java
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 BankAccountConcurrentDepositTest {
|
|
|
|
@Test
|
|
void concurrentDeposits() throws Exception {
|
|
|
|
BankAccount account = new BankAccount(1, 0);
|
|
|
|
int threads = 100;
|
|
int perThread = 1000;
|
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(threads);
|
|
CountDownLatch latch = new CountDownLatch(threads);
|
|
|
|
for (int i = 0; i < threads; i++) {
|
|
executor.submit(() -> {
|
|
for (int j = 0; j < perThread; j++) {
|
|
account.deposit(1);
|
|
}
|
|
latch.countDown();
|
|
});
|
|
}
|
|
|
|
latch.await();
|
|
executor.shutdown();
|
|
|
|
assertEquals(threads * perThread, account.getBalance());
|
|
}
|
|
} |