Skip to content

Commit 264587b

Browse files
committed
fix ind1
1 parent aeb91a1 commit 264587b

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

jdk_11_maven/em/external/rest/ind1/src/main/java/em/external/org/ind1/ExternalEvoMasterController.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
77
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
88
import org.evomaster.client.java.controller.db.DbCleaner;
9+
import org.evomaster.client.java.controller.db.SqlScriptRunner;
910
import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;
1011
import org.evomaster.client.java.controller.internal.db.DbSpecification;
1112
import org.evomaster.client.java.controller.problem.ProblemInfo;
1213
import org.evomaster.client.java.controller.problem.RestProblem;
1314
import org.testcontainers.containers.GenericContainer;
1415

16+
import java.io.InputStream;
17+
import java.io.InputStreamReader;
1518
import java.sql.Connection;
1619
import java.sql.DriverManager;
1720
import java.sql.SQLException;
@@ -74,6 +77,10 @@ public static void main(String[] args) {
7477
private Connection sqlConnection;
7578
private List<DbSpecification> dbSpecification;
7679

80+
private String INIT_DB_SCRIPT_PATH = "/init_db.sql";
81+
82+
private String initSQLScript;
83+
7784
private static final GenericContainer postgres = new GenericContainer("postgres:9")
7885
.withExposedPorts(5432)
7986
.withEnv("POSTGRES_HOST_AUTH_METHOD","trust")
@@ -105,6 +112,12 @@ public ExternalEvoMasterController(
105112
this.packagesToInstrument = packagesToInstrument;
106113
setControllerPort(controllerPort);
107114
setJavaCommand(command);
115+
116+
try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) {
117+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
118+
} catch (Exception e) {
119+
throw new RuntimeException(e);
120+
}
108121
}
109122

110123

@@ -174,19 +187,27 @@ public void postStart() {
174187

175188
try {
176189
sqlConnection = DriverManager.getConnection(dbUrl(), "postgres", "");
190+
191+
/*
192+
ensure the data in db is empty
193+
*/
194+
DbCleaner.clearDatabase_Postgres(sqlConnection,
195+
"subscriptions",
196+
Arrays.asList("flyway_schema_history"));
197+
177198
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.POSTGRES,sqlConnection)
178-
.withSchemas("subscriptions").withDisabledSmartClean());
199+
.withSchemas("subscriptions").withInitSqlScript(initSQLScript));
179200
} catch (Exception e) {
180201
throw new RuntimeException(e);
181202
}
182203
}
183204

184205
@Override
185206
public void resetStateOfSUT() {
186-
DbCleaner.clearDatabase_Postgres(sqlConnection,
187-
"subscriptions",
188-
Arrays.asList("flyway_schema_history"));
189-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/init_db.sql");
207+
// DbCleaner.clearDatabase_Postgres(sqlConnection,
208+
// "subscriptions",
209+
// Arrays.asList("flyway_schema_history"));
210+
// SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/init_db.sql");
190211
}
191212

192213
@Override

0 commit comments

Comments
 (0)