44import org .junit .jupiter .api .Test ;
55
66import java .sql .Connection ;
7+ import java .sql .DriverManager ;
78import java .sql .PreparedStatement ;
89import java .sql .SQLException ;
10+ import java .sql .Statement ;
911import java .util .Properties ;
1012
1113class SqlServerContainerTest {
@@ -27,6 +29,27 @@ void start() {
2729 container .stopRemove ();
2830 }
2931
32+ /**
33+ * startWithDropCreate does not work, when the container is running and there is a connection open.
34+ */
35+ @ Disabled
36+ @ Test
37+ void start_dropCreate_withLeakingConnection () throws Exception {
38+ SqlServerContainer container = SqlServerContainer .builder (SQLSERVER_VER )
39+ .containerName ("temp_sqlserver" )
40+ .port (2433 )
41+ .collation ("Latin1_General_100_BIN2" )
42+ .build ();
43+ container .startWithDropCreate ();
44+ try (Connection conn = DriverManager .getConnection (container .jdbcUrl (), container .dbConfig .getUsername (), container .dbConfig .getPassword ())) {
45+ // drop during open connection
46+ container .startWithDropCreate ();
47+ } finally {
48+ container .stopRemove ();
49+
50+ }
51+ }
52+
3053 @ Disabled
3154 @ Test
3255 void start_when_defaultCollation () {
@@ -40,6 +63,19 @@ void start_when_defaultCollation() {
4063 container .stopRemove ();
4164 }
4265
66+ @ Disabled
67+ @ Test
68+ void start_when_explicitDefaultCollation () {
69+ SqlServerContainer container = SqlServerContainer .builder (SQLSERVER_VER )
70+ .containerName ("temp_sqlserver" )
71+ .port (2433 )
72+ .collation ("SQL_Latin1_General_CP1_CI_AS" )
73+ .build ();
74+
75+ container .startWithCreate ();
76+ container .stopRemove ();
77+ }
78+
4379 @ Disabled
4480 @ Test
4581 void start_when_noCollation () {
@@ -65,6 +101,40 @@ void start_when_explicitCollation() {
65101 container .stopRemove ();
66102 }
67103
104+ /**
105+ * When Collation is changed, the server sometimes will not start with dropCreate, because there are async
106+ * processes on container start. We must ensure, that we wait until container is started.
107+ * <p>
108+ * It is very hard to reproduce, I could only reproduce it with "startWithDropCreate" and an active
109+ * screen sharing session... So the test may look a bit messy to get the correct timing.
110+ * <p>
111+ * I observed the output:
112+ * 16:14:42.726 [main] DEBUG io.ebean.test.containers - connectivity confirmed for temp_sqlserver
113+ * <p>
114+ * comparing the timestamp with the docker-logs, the server was in the middle of collation change process.
115+ */
116+ @ Disabled
117+ @ Test
118+ void start_dropCreate_explicitCollationTimmingTest () throws Exception {
119+ SqlServerContainer container = SqlServerContainer .builder (SQLSERVER_VER )
120+ .containerName ("temp_sqlserver" )
121+ .port (2433 )
122+ .collation ("Latin1_General_100_BIN2" )
123+ .build ();
124+ for (int i = 0 ; i < 10 ; i ++) {
125+ container .startWithDropCreate ();
126+ try (Connection conn = DriverManager .getConnection (container .jdbcUrl (), container .dbConfig .getUsername (), container .dbConfig .getPassword ())) {
127+ for (int j = 0 ; j < 10 ; j ++) {
128+ Statement stmt = conn .createStatement ();
129+ stmt .execute ("create table my_test" + j + " (id int)" );
130+ conn .commit ();
131+ }
132+ Thread .sleep (2000 );
133+ container .stopRemove ();
134+ }
135+ }
136+ }
137+
68138 @ Disabled
69139 @ Test
70140 void viaContainerFactory () {
0 commit comments