24
24
import org .awaitility .Awaitility ;
25
25
import org .firebirdsql .management .FBManager ;
26
26
import org .firebirdsql .management .PageSizeConstants ;
27
- import org .junit .jupiter .api .AfterAll ;
28
- import org .junit .jupiter .api .BeforeAll ;
27
+ import org .junit .jupiter .api .AfterEach ;
28
+ import org .junit .jupiter .api .BeforeEach ;
29
29
import org .junit .jupiter .api .Test ;
30
30
import org .junit .jupiter .api .condition .EnabledInNativeImage ;
31
31
import org .testcontainers .containers .GenericContainer ;
47
47
@ Testcontainers
48
48
class FirebirdTest {
49
49
50
- private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.firebird." ;
50
+ private final String systemPropKeyPrefix = "fixture.test-native.yaml.database.firebird." ;
51
51
52
- private static final String PASSWORD = "masterkey" ;
52
+ private final String password = "masterkey" ;
53
53
54
54
@ SuppressWarnings ("resource" )
55
55
@ Container
56
- private static final GenericContainer <?> CONTAINER = new GenericContainer <>("ghcr.io/fdcastel/firebird:5.0.1" )
57
- .withEnv ("FIREBIRD_ROOT_PASSWORD" , PASSWORD )
56
+ private final GenericContainer <?> container = new GenericContainer <>("ghcr.io/fdcastel/firebird:5.0.1" )
57
+ .withEnv ("FIREBIRD_ROOT_PASSWORD" , password )
58
58
.withEnv ("FIREBIRD_USER" , "alice" )
59
- .withEnv ("FIREBIRD_PASSWORD" , PASSWORD )
59
+ .withEnv ("FIREBIRD_PASSWORD" , password )
60
60
.withEnv ("FIREBIRD_DATABASE" , "mirror.fdb" )
61
61
.withEnv ("FIREBIRD_DATABASE_DEFAULT_CHARSET" , "UTF8" )
62
62
.withExposedPorts (3050 );
63
63
64
- private static DataSource logicDataSource ;
64
+ private DataSource logicDataSource ;
65
65
66
66
private String jdbcUrlPrefix ;
67
67
68
68
private TestShardingService testShardingService ;
69
69
70
- @ BeforeAll
71
- static void beforeAll () {
72
- assertThat (System .getProperty (SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url" ), is (nullValue ()));
73
- assertThat (System .getProperty (SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url" ), is (nullValue ()));
74
- assertThat (System .getProperty (SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url" ), is (nullValue ()));
70
+ @ BeforeEach
71
+ void beforeEach () {
72
+ assertThat (System .getProperty (systemPropKeyPrefix + "ds0.jdbc-url" ), is (nullValue ()));
73
+ assertThat (System .getProperty (systemPropKeyPrefix + "ds1.jdbc-url" ), is (nullValue ()));
74
+ assertThat (System .getProperty (systemPropKeyPrefix + "ds2.jdbc-url" ), is (nullValue ()));
75
75
}
76
76
77
- @ AfterAll
78
- static void afterAll () throws SQLException {
77
+ @ AfterEach
78
+ void afterEach () throws SQLException {
79
79
try (Connection connection = logicDataSource .getConnection ()) {
80
80
connection .unwrap (ShardingSphereConnection .class ).getContextManager ().close ();
81
81
}
82
- System .clearProperty (SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url" );
83
- System .clearProperty (SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url" );
84
- System .clearProperty (SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url" );
82
+ System .clearProperty (systemPropKeyPrefix + "ds0.jdbc-url" );
83
+ System .clearProperty (systemPropKeyPrefix + "ds1.jdbc-url" );
84
+ System .clearProperty (systemPropKeyPrefix + "ds2.jdbc-url" );
85
85
}
86
86
87
87
@ Test
88
88
void assertShardingInLocalTransactions () throws Exception {
89
- jdbcUrlPrefix = "jdbc:firebird://localhost:" + CONTAINER .getMappedPort (3050 ) + "//var/lib/firebird/data/" ;
89
+ jdbcUrlPrefix = "jdbc:firebird://localhost:" + container .getMappedPort (3050 ) + "//var/lib/firebird/data/" ;
90
90
logicDataSource = createDataSource ();
91
91
testShardingService = new TestShardingService (logicDataSource );
92
92
initEnvironment ();
@@ -109,7 +109,7 @@ private void initEnvironment() throws SQLException {
109
109
private Connection openConnection () throws SQLException {
110
110
Properties props = new Properties ();
111
111
props .setProperty ("user" , "alice" );
112
- props .setProperty ("password" , PASSWORD );
112
+ props .setProperty ("password" , password );
113
113
return DriverManager .getConnection (jdbcUrlPrefix + "mirror.fdb" , props );
114
114
}
115
115
@@ -131,22 +131,22 @@ private DataSource createDataSource() throws Exception {
131
131
try (FBManager fbManager = new FBManager ()) {
132
132
fbManager .setServer ("localhost" );
133
133
fbManager .setUserName ("alice" );
134
- fbManager .setPassword (PASSWORD );
134
+ fbManager .setPassword (password );
135
135
fbManager .setFileName ("/var/lib/firebird/data/mirror.fdb" );
136
136
fbManager .setPageSize (PageSizeConstants .SIZE_16K );
137
137
fbManager .setDefaultCharacterSet ("UTF8" );
138
- fbManager .setPort (CONTAINER .getMappedPort (3050 ));
138
+ fbManager .setPort (container .getMappedPort (3050 ));
139
139
fbManager .start ();
140
- fbManager .createDatabase ("/var/lib/firebird/data/demo_ds_0.fdb" , "alice" , PASSWORD );
141
- fbManager .createDatabase ("/var/lib/firebird/data/demo_ds_1.fdb" , "alice" , PASSWORD );
142
- fbManager .createDatabase ("/var/lib/firebird/data/demo_ds_2.fdb" , "alice" , PASSWORD );
140
+ fbManager .createDatabase ("/var/lib/firebird/data/demo_ds_0.fdb" , "alice" , password );
141
+ fbManager .createDatabase ("/var/lib/firebird/data/demo_ds_1.fdb" , "alice" , password );
142
+ fbManager .createDatabase ("/var/lib/firebird/data/demo_ds_2.fdb" , "alice" , password );
143
143
}
144
144
HikariConfig config = new HikariConfig ();
145
145
config .setDriverClassName ("org.apache.shardingsphere.driver.ShardingSphereDriver" );
146
146
config .setJdbcUrl ("jdbc:shardingsphere:classpath:test-native/yaml/jdbc/databases/firebird.yaml?placeholder-type=system_props" );
147
- System .setProperty (SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url" , jdbcUrlPrefix + "demo_ds_0.fdb" );
148
- System .setProperty (SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url" , jdbcUrlPrefix + "demo_ds_1.fdb" );
149
- System .setProperty (SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url" , jdbcUrlPrefix + "demo_ds_2.fdb" );
147
+ System .setProperty (systemPropKeyPrefix + "ds0.jdbc-url" , jdbcUrlPrefix + "demo_ds_0.fdb" );
148
+ System .setProperty (systemPropKeyPrefix + "ds1.jdbc-url" , jdbcUrlPrefix + "demo_ds_1.fdb" );
149
+ System .setProperty (systemPropKeyPrefix + "ds2.jdbc-url" , jdbcUrlPrefix + "demo_ds_2.fdb" );
150
150
return new HikariDataSource (config );
151
151
}
152
152
}
0 commit comments