File tree Expand file tree Collapse file tree
src/test/java/org/avaje/datasource/pool Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4444 <scope >test</scope >
4545 </dependency >
4646
47+ <!-- Override com.h2database version to get schema support -->
48+ <dependency >
49+ <groupId >com.h2database</groupId >
50+ <artifactId >h2</artifactId >
51+ <version >1.4.193</version >
52+ <scope >test</scope >
53+ </dependency >
54+
4755 </dependencies >
4856
4957 <build >
Original file line number Diff line number Diff line change 88import java .sql .Connection ;
99import java .sql .PreparedStatement ;
1010import java .sql .SQLException ;
11+ import java .sql .Statement ;
12+
13+ import javax .sql .DataSource ;
1114
1215import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
1316
@@ -116,4 +119,29 @@ public void getDelegate() throws SQLException {
116119 assertThat (underlying ).isInstanceOf (org .h2 .jdbc .JdbcConnection .class );
117120 connection .close ();
118121 }
122+
123+ @ Test
124+ public void testSchemaSwitch () throws SQLException {
125+ Connection conn = pool .getConnection ();
126+ Statement stmt = conn .createStatement ();
127+ stmt .executeUpdate ("CREATE SCHEMA TENANT_1" );
128+ stmt .executeUpdate ("CREATE SCHEMA TENANT_2" );
129+ stmt .executeUpdate ("CREATE TABLE TENANT_1.LOCAL_MODEL (id integer)" );
130+ stmt .executeUpdate ("CREATE TABLE TENANT_2.LOCAL_MODEL (id integer)" );
131+ stmt .close ();
132+
133+ conn .setSchema ("TENANT_1" );
134+ PreparedStatement ps1 = conn .prepareStatement ("SELECT * from local_model" );
135+ ps1 .close ();
136+ PreparedStatement ps2 = conn .prepareStatement ("SELECT * from local_model" );
137+ ps2 .close ();
138+
139+ conn .setSchema ("TENANT_2" );
140+ PreparedStatement ps3 = conn .prepareStatement ("SELECT * from local_model" );
141+ ps3 .close ();
142+
143+
144+ assertThat (ps1 ).isSameAs (ps2 ); // test if pstmtCache is working
145+ assertThat (ps1 ).isNotSameAs (ps3 ); // test if datasource recognize schema change
146+ }
119147}
You can’t perform that action at this time.
0 commit comments