Skip to content

Commit

Permalink
运行测试用例时可以自动创建多个测试数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Jan 25, 2024
1 parent d59ccec commit 2140315
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -56,7 +57,7 @@ protected boolean autoStartTcpServer() {
}

private static boolean tcpServerStarted = false;
private static boolean testDatabaseCreated = false;
private static final HashSet<String> createdDatabases = new HashSet<>();

@Before
public void setUpBefore() {
Expand All @@ -68,12 +69,12 @@ public void setUpBefore() {
}
}
}
if (!testDatabaseCreated && !isEmbedded()) {
if (!createdDatabases.contains(dbName) && !isEmbedded()) {
synchronized (getClass()) {
if (!testDatabaseCreated) {
if (!createdDatabases.contains(dbName)) {
if (!LealoneDatabase.NAME.equalsIgnoreCase(dbName)) {
createTestDatabase();
testDatabaseCreated = true;
createdDatabases.add(dbName);
}
}
}
Expand Down

0 comments on commit 2140315

Please sign in to comment.