-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSessionlessTransactionsTest.java
More file actions
67 lines (57 loc) · 2.42 KB
/
SessionlessTransactionsTest.java
File metadata and controls
67 lines (57 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.example.txn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Duration;
import oracle.jdbc.pool.OracleDataSource;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.oracle.OracleContainer;
import static org.assertj.core.api.Assertions.assertThat;
class SessionlessTransactionsTest {
private static final OracleContainer oracleContainer = new OracleContainer("gvenzl/oracle-free:23.26.1-slim-faststart")
.withStartupTimeout(Duration.ofMinutes(5))
.withUsername("testuser")
.withPassword("testpwd")
.withInitScript("orders.sql");
private static OracleDataSource dataSource;
@BeforeAll
static void startContainer() throws SQLException {
oracleContainer.start();
dataSource = new OracleDataSource();
dataSource.setURL(oracleContainer.getJdbcUrl());
dataSource.setUser(oracleContainer.getUsername());
dataSource.setPassword(oracleContainer.getPassword());
}
@AfterAll
static void stopContainer() {
oracleContainer.stop();
}
@Test
void processesOrderAcrossSessions() throws Exception {
OrderService orderService = new OrderService(dataSource);
System.out.println("beginning order processing");
orderService.processOrder();
try (Connection connection = dataSource.getConnection();
PreparedStatement stmt = connection.prepareStatement(
"select status from order_processing order by id")) {
try (ResultSet rs = stmt.executeQuery()) {
assertThat(rs.next()).isTrue();
assertThat(rs.getString("status")).isEqualTo("created");
assertThat(rs.next()).isTrue();
String nextStatus = rs.getString("status");
if (nextStatus.equals("inventory_reserved")) {
assertThat(rs.next()).isTrue();
assertThat(rs.getString("status")).isEqualTo("completed");
System.out.println("processed order");
} else {
assertThat(rs.getString("status")).isEqualTo("failed");
assertThat(rs.next()).isFalse();
System.out.println("failed order");
}
}
}
}
}