77import io .teaql .core .businessid .BusinessIdGenerationRequest ;
88import io .teaql .core .businessid .BusinessIdPlan ;
99import io .teaql .runtime .businessid .DailySequenceBusinessIdProfile ;
10+ import io .teaql .core .sql .dialect .OracleDialect ;
1011import java .sql .Connection ;
1112import java .sql .DriverManager ;
1213import java .time .LocalDate ;
2425import org .junit .Assume ;
2526import org .junit .Test ;
2627
27- /** Live, independent-connection Business ID allocation across PostgreSQL and MySQL . */
28+ /** Live, independent-connection Business ID allocation across SQL providers . */
2829public class JdbcBusinessIdLiveDialectIT {
2930 private static final LocalDate BUSINESS_DATE = LocalDate .of (2026 , 9 , 20 );
3031 private static final int ALLOCATIONS_PER_INSTANCE = 40 ;
@@ -39,6 +40,65 @@ public void mysqlAllocatesAcrossInstancesAndRestart() throws Exception {
3940 verify ("MYSQL" );
4041 }
4142
43+ @ Test
44+ public void sqlServerAllocatesAcrossInstancesAndRestart () throws Exception {
45+ verify ("MSSQL" );
46+ }
47+
48+ @ Test
49+ public void dm8AllocatesAcrossInstancesAndRestart () throws Exception {
50+ verify ("DM8" );
51+ }
52+
53+ @ Test
54+ public void oracleAllocatesAcrossInstancesAndRestart () throws Exception {
55+ verify ("ORACLE" );
56+ }
57+
58+ @ Test
59+ public void sqlServerConcurrentSchemaStartupIsIdempotent () throws Exception {
60+ String url = System .getenv ("TEAQL_TEST_MSSQL_URL" );
61+ String user = System .getenv ("TEAQL_TEST_MSSQL_USER" );
62+ String password = System .getenv ("TEAQL_TEST_MSSQL_PASSWORD" );
63+ if (url == null || user == null || password == null ) {
64+ if (Boolean .parseBoolean (System .getenv ("TEAQL_REQUIRE_LIVE_DB" ))) {
65+ Assert .fail ("MSSQL Business ID live gate requires URL, USER, and PASSWORD" );
66+ }
67+ Assume .assumeTrue ("MSSQL live database is not configured" , false );
68+ }
69+ Assert .assertTrue ("Use a dedicated teaql_live_* database for MSSQL" ,
70+ url .contains ("teaql_live_" ));
71+ String table = "bid_schema_" + UUID .randomUUID ().toString ().substring (0 , 8 );
72+ CountDownLatch start = new CountDownLatch (1 );
73+ ExecutorService workers = Executors .newFixedThreadPool (2 );
74+ try {
75+ List <Future <?>> futures = new ArrayList <>();
76+ for (int worker = 0 ; worker < 2 ; worker ++) {
77+ futures .add (workers .submit (() -> {
78+ try (Connection connection = DriverManager .getConnection (url , user , password )) {
79+ JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator (
80+ BusinessIdRuntimeExampleTest .database (connection ), table );
81+ UserContext context = BusinessIdRuntimeExampleTest .context (
82+ BUSINESS_DATE , allocator );
83+ context .putAttribute (SchemaExecutor .class .getName (),
84+ BusinessIdRuntimeExampleTest .noOpSchemaExecutor ());
85+ Assert .assertTrue (start .await (15 , TimeUnit .SECONDS ));
86+ context .ensureSchema ();
87+ return null ;
88+ }
89+ }));
90+ }
91+ start .countDown ();
92+ for (Future <?> future : futures ) future .get (30 , TimeUnit .SECONDS );
93+ } finally {
94+ workers .shutdownNow ();
95+ }
96+ try (Connection connection = DriverManager .getConnection (url , user , password )) {
97+ Assert .assertEquals (4 , BusinessIdRuntimeExampleTest .database (connection )
98+ .getTableColumns (table ).size ());
99+ }
100+ }
101+
42102 private void verify (String dialect ) throws Exception {
43103 String prefix = "TEAQL_TEST_" + dialect + "_" ;
44104 String url = System .getenv (prefix + "URL" );
@@ -50,8 +110,16 @@ private void verify(String dialect) throws Exception {
50110 }
51111 Assume .assumeTrue (dialect + " live database is not configured" , false );
52112 }
53- Assert .assertTrue ("Use a dedicated teaql_live_* database for " + dialect ,
54- url .contains ("teaql_live_" ));
113+ if ("DM8" .equals (dialect )) {
114+ Assert .assertEquals ("Use only an isolated disposable DM8 instance" ,
115+ "true" , System .getenv ("TEAQL_TEST_DM8_ISOLATED" ));
116+ } else if ("ORACLE" .equals (dialect )) {
117+ Assert .assertTrue ("Use only a dedicated TEAQL_LIVE_* Oracle user" ,
118+ user .toUpperCase (java .util .Locale .ROOT ).startsWith ("TEAQL_LIVE_" ));
119+ } else {
120+ Assert .assertTrue ("Use a dedicated teaql_live_* database for " + dialect ,
121+ url .contains ("teaql_live_" ));
122+ }
55123
56124 BusinessIdDefinition definition = BusinessIdDefinition .dailySequence (
57125 "order_number" , "CO" , "commerce_order" );
@@ -61,12 +129,12 @@ private void verify(String dialect) throws Exception {
61129 "commerce_order" , BUSINESS_DATE ));
62130
63131 try (Connection schemaConnection = DriverManager .getConnection (url , user , password )) {
64- JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator (
65- BusinessIdRuntimeExampleTest .database (schemaConnection ));
132+ JdbcBusinessIdAllocator allocator = allocator (schemaConnection , dialect );
66133 UserContext context = BusinessIdRuntimeExampleTest .context (BUSINESS_DATE , allocator );
67134 context .putAttribute (SchemaExecutor .class .getName (),
68135 BusinessIdRuntimeExampleTest .noOpSchemaExecutor ());
69136 context .ensureSchema ();
137+ context .ensureSchema ();
70138 }
71139
72140 CountDownLatch start = new CountDownLatch (1 );
@@ -76,8 +144,7 @@ private void verify(String dialect) throws Exception {
76144 for (int worker = 0 ; worker < 2 ; worker ++) {
77145 futures .add (workers .submit (() -> {
78146 try (Connection connection = DriverManager .getConnection (url , user , password )) {
79- JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator (
80- BusinessIdRuntimeExampleTest .database (connection ));
147+ JdbcBusinessIdAllocator allocator = allocator (connection , dialect );
81148 Assert .assertTrue ("Concurrent start timed out" ,
82149 start .await (15 , TimeUnit .SECONDS ));
83150 List <Long > sequences = new ArrayList <>();
@@ -103,10 +170,19 @@ private void verify(String dialect) throws Exception {
103170 }
104171
105172 try (Connection restarted = DriverManager .getConnection (url , user , password )) {
106- JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator (
107- BusinessIdRuntimeExampleTest .database (restarted ));
173+ JdbcBusinessIdAllocator allocator = allocator (restarted , dialect );
108174 Assert .assertEquals (2L * ALLOCATIONS_PER_INSTANCE + 1 ,
109175 allocator .allocate (plan ).sequence ());
110176 }
111177 }
178+
179+ private static JdbcBusinessIdAllocator allocator (Connection connection , String dialect ) {
180+ if ("ORACLE" .equals (dialect )) {
181+ return new JdbcBusinessIdAllocator (
182+ BusinessIdRuntimeExampleTest .database (connection ),
183+ JdbcBusinessIdAllocator .DEFAULT_TABLE ,
184+ new OracleDialect ());
185+ }
186+ return new JdbcBusinessIdAllocator (BusinessIdRuntimeExampleTest .database (connection ));
187+ }
112188}
0 commit comments