Skip to content

Commit bb2df13

Browse files
committed
enable smart db clean for scout api
1 parent 10d7269 commit bb2df13

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

jdk_8_maven/em/embedded/rest/scout-api/src/main/java/em/embedded/se/devscout/scoutapi/EmbeddedEvoMasterController.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,24 @@ public static void main(String[] args) {
4343

4444
private ScoutAPIApplication application;
4545
private Connection sqlConnection;
46-
private final List<String> sqlCommands;
46+
// private final List<String> sqlCommands;
47+
48+
private String INIT_DB_SCRIPT_PATH = "/init_db.sql";
49+
4750
private List<DbSpecification> dbSpecification;
4851

52+
private String initSQLScript;
53+
54+
4955
public EmbeddedEvoMasterController() {
5056
this(40100);
5157
}
5258

5359
public EmbeddedEvoMasterController(int port) {
5460
setControllerPort(port);
5561

56-
try (InputStream in = getClass().getResourceAsStream("/init_db.sql")) {
57-
sqlCommands = (new SqlScriptRunner()).readCommands(new InputStreamReader(in));
62+
try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) {
63+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
5864
} catch (Exception e) {
5965
throw new RuntimeException(e);
6066
}
@@ -88,8 +94,13 @@ public String startSut() {
8894

8995
sqlConnection = application.getConnection();
9096

97+
/*
98+
ensure that the database is clean
99+
*/
100+
DbCleaner.clearDatabase_H2(sqlConnection);
101+
91102
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
92-
.withDisabledSmartClean());
103+
.withInitSqlScript(initSQLScript));
93104

94105
resetStateOfSUT();
95106

@@ -134,8 +145,8 @@ public void resetStateOfSUT() {
134145

135146
deleteDir(new File("./target/temp"));
136147

137-
DbCleaner.clearDatabase_H2(sqlConnection);
138-
SqlScriptRunner.runCommands(sqlConnection, sqlCommands);
148+
// DbCleaner.clearDatabase_H2(sqlConnection);
149+
// SqlScriptRunner.runCommands(sqlConnection, sqlCommands);
139150
}
140151

141152

jdk_8_maven/em/external/rest/scout-api/src/main/java/em/external/se/devscout/scoutapi/ExternalEvoMasterController.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public static void main(String[] args) {
7575

7676
private Connection sqlConnection;
7777
private List<DbSpecification> dbSpecification;
78-
private final List<String> sqlCommands;
78+
// private final List<String> sqlCommands;
79+
80+
private String INIT_DB_SCRIPT_PATH = "/init_db.sql";
81+
82+
private String initSQLScript;
7983
private Server h2;
8084

8185

@@ -105,7 +109,7 @@ public ExternalEvoMasterController(int controllerPort,
105109
createConfigurationFile();
106110

107111
try(InputStream in = getClass().getResourceAsStream("/init_db.sql")) {
108-
sqlCommands = (new SqlScriptRunner()).readCommands(new InputStreamReader(in));
112+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
109113
} catch (Exception e){
110114
throw new RuntimeException(e);
111115
}
@@ -196,8 +200,14 @@ public void postStart() {
196200
try {
197201
Class.forName("org.h2.Driver");
198202
sqlConnection = DriverManager.getConnection(dbUrl(), "sa", "");
199-
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
200-
.withDisabledSmartClean());
203+
204+
/*
205+
ensure that the database is clean
206+
*/
207+
DbCleaner.clearDatabase_H2(sqlConnection);
208+
209+
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection).withInitSqlScript(initSQLScript));
210+
201211
} catch (Exception e) {
202212
throw new RuntimeException(e);
203213
}
@@ -227,8 +237,8 @@ public void resetStateOfSUT() {
227237

228238
deleteDir(new File(tmpDir));
229239

230-
DbCleaner.clearDatabase_H2(sqlConnection);
231-
SqlScriptRunner.runCommands(sqlConnection, sqlCommands);
240+
// DbCleaner.clearDatabase_H2(sqlConnection);
241+
// SqlScriptRunner.runCommands(sqlConnection, sqlCommands);
232242
}
233243

234244
private void deleteDir(File file) {

0 commit comments

Comments
 (0)