Files
HW-09-Advanced-Multithreading/src/test/java/banking/BankAccountTransferDeadlockTest.java
T
Aryan 74963fbf29 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
2026-06-05 21:53:35 +03:30

35 lines
870 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.assertTimeoutPreemptively;
import java.time.Duration;
public class BankAccountTransferDeadlockTest {
@Test
void deadlockFreeTransfers() {
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> {
BankAccount a = new BankAccount(1, 1_000_000);
BankAccount b = new BankAccount(2, 1_000_000);
ExecutorService executor = Executors.newFixedThreadPool(50);
for (int i = 0; i < 50_000; i++) {
executor.submit(() -> a.transfer(b, 1));
executor.submit(() -> b.transfer(a, 1));
}
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
});
}
}