Files
HW-09-Advanced-Multithreading/src/test/java/banking/TransactionProcessorMixedTransactionIntegrationTest.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

47 lines
1.4 KiB
Java

package banking;
import dev.banking.model.*;
import dev.banking.processor.TransactionProcessor;
import org.junit.jupiter.api.Test;
import java.util.*;
import java.util.concurrent.*;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
public class TransactionProcessorMixedTransactionIntegrationTest {
@Test
void mixedTransactionsShouldExecuteCorrectly() {
BankAccount a = new BankAccount(1, 1000);
BankAccount b = new BankAccount(2, 2000);
BankAccount c = new BankAccount(3, 1500);
Map<Integer, BankAccount> accounts = new HashMap<>();
accounts.put(1, a);
accounts.put(2, b);
accounts.put(3, c);
TransactionProcessor processor = new TransactionProcessor(accounts);
ExecutorService executor = Executors.newFixedThreadPool(8);
List<Transaction> txs = List.of(
new DepositTransaction(1, 100),
new WithdrawTransaction(2, 50),
new TransferTransaction(1, 2, 30),
new TransferTransaction(2, 3, 70),
new DepositTransaction(3, 200)
);
assertDoesNotThrow(() -> {
for (Transaction tx : txs) {
executor.submit(() -> processor.process(tx));
}
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
});
}
}