Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql-multidb-v3 #1140

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.evomaster.client.java.controller.api.dto.database.schema.DbInfoDto;
import org.evomaster.client.java.controller.api.dto.database.schema.ExtraConstraintsDto;
import org.evomaster.client.java.controller.api.dto.MockDatabaseDto;
import org.evomaster.client.java.controller.api.dto.database.schema.TableIdDto;
import org.evomaster.client.java.controller.api.dto.problem.RPCProblemDto;
import org.evomaster.client.java.controller.api.dto.problem.rpc.*;
import org.evomaster.client.java.sql.DbCleaner;
Expand Down Expand Up @@ -374,9 +375,11 @@ private void computeSQLHeuristics(ExtraHeuristicsDto dto, List<AdditionalInfo> a
if (!additionalInfoList.isEmpty()) {
AdditionalInfo last = additionalInfoList.get(additionalInfoList.size() - 1);
last.getSqlInfoData().stream().forEach(it -> {
// String sql = it.getCommand();
try {
final SqlExecutionLogDto sqlExecutionLogDto = new SqlExecutionLogDto(it.getSqlCommand(), it.hasThrownSqlException(), it.getExecutionTime());
SqlExecutionLogDto sqlExecutionLogDto = new SqlExecutionLogDto(
it.getSqlCommand(),
it.hasThrownSqlException(),
it.getExecutionTime());
sqlHandler.handle(sqlExecutionLogDto);
} catch (Exception e) {
SimpleLogger.error("FAILED TO HANDLE SQL COMMAND: " + it.getSqlCommand());
Expand Down Expand Up @@ -406,7 +409,6 @@ private void computeSQLHeuristics(ExtraHeuristicsDto dto, List<AdditionalInfo> a
accessedTables.addAll(sqlExecutionsDto.deletedData);
accessedTables.addAll(sqlExecutionsDto.insertedData.keySet());
//accessedTables.addAll(executionDto.queriedData.keySet());
// accessedTables.addAll(sqlExecutionsDto.insertedData.keySet());
accessedTables.addAll(sqlExecutionsDto.updatedData.keySet());
}
}
Expand Down Expand Up @@ -495,13 +497,13 @@ public final void cleanAccessedTables(){
// clean accessed tables
Set<String> tableDataToInit = null;
if (!accessedTables.isEmpty()){
List<String> tablesToClean = new ArrayList<>();
getTableToClean(accessedTables, tablesToClean);
List<String> tablesToClean = getTablesToClean(accessedTables);
if (!tablesToClean.isEmpty()){
if (emDbClean.schemaNames != null && !emDbClean.schemaNames.isEmpty()){
emDbClean.schemaNames.forEach(sch-> DbCleaner.clearDatabase(getConnectionIfExist(), sch, null, tablesToClean, emDbClean.dbType));
}else
DbCleaner.clearDatabase(getConnectionIfExist(), null, null, tablesToClean, emDbClean.dbType);
emDbClean.schemaNames.forEach(sch-> DbCleaner.clearDatabase(getConnectionIfExist(), sch, null, tablesToClean, emDbClean.dbType, true));
} else {
DbCleaner.clearDatabase(getConnectionIfExist(), null, null, tablesToClean, emDbClean.dbType, true);
}
tableDataToInit = tablesToClean.stream().filter(a-> tableInitSqlMap.keySet().stream().anyMatch(t-> t.equalsIgnoreCase(a))).collect(Collectors.toSet());
}
}
Expand Down Expand Up @@ -582,7 +584,13 @@ public void addSuccessfulInitSqlInsertion(InsertionDto insertionDto){
successfulInitSqlInsertions.add(insertionDto);
}

private void getTableToClean(List<String> accessedTables, List<String> tablesToClean){
private List<String> getTablesToClean(List<String> accessedTables) {
List<String> tablesToClean = new ArrayList<>();
fillTablesToClean(accessedTables,tablesToClean);
return tablesToClean;
}

private void fillTablesToClean(List<String> accessedTables, List<String> tablesToClean){
for (String t: accessedTables){
if (!findInCollectionIgnoreCase(t, tablesToClean).isPresent()){
if (findInMapIgnoreCase(t, fkMap).isPresent()){
Expand All @@ -591,7 +599,7 @@ private void getTableToClean(List<String> accessedTables, List<String> tablesToC
findInCollectionIgnoreCase(t, e.getValue()).isPresent()
&& !findInCollectionIgnoreCase(e.getKey(), tablesToClean).isPresent()).map(Map.Entry::getKey).collect(Collectors.toList());
if (!fk.isEmpty())
getTableToClean(fk, tablesToClean);
fillTablesToClean(fk, tablesToClean);
}else {
SimpleLogger.uniqueWarn("Cannot find the table "+t+" in ["+String.join(",", fkMap.keySet())+"]");
}
Expand Down Expand Up @@ -644,12 +652,6 @@ private boolean registerInitSqlCommands(Connection connection, DbSpecification d
return false;
}

private void cleanDataInDbConnection(Connection connection, DbSpecification dbSpecification){
if (dbSpecification.schemaNames != null && !dbSpecification.schemaNames.isEmpty()){
dbSpecification.schemaNames.forEach(sch-> DbCleaner.clearDatabase(connection, sch, null, dbSpecification.dbType));
}else
DbCleaner.clearDatabase(connection, null, dbSpecification.dbType);
}

/**
* Extra information about the SQL Database Schema, if any is present.
Expand Down Expand Up @@ -679,10 +681,10 @@ public final DbInfoDto getSqlDatabaseSchema() {

if (fkMap.isEmpty()){
schemaDto.tables.forEach(t->{
fkMap.putIfAbsent(t.name, new ArrayList<>());
fkMap.putIfAbsent(t.id.name, new ArrayList<>());
if (t.foreignKeys!=null && !t.foreignKeys.isEmpty()){
t.foreignKeys.forEach(f->{
fkMap.get(t.name).add(f.targetTable.toUpperCase());
fkMap.get(t.id.name).add(f.targetTable.toUpperCase());
});
}
});
Expand Down Expand Up @@ -1454,7 +1456,10 @@ protected UnitsInfoDto getUnitsInfoDto(UnitsInfoRecorder recorder){
ec.digitsInteger = c.getDigitsInteger();
ec.enumValuesAsStrings = c.getEnumValuesAsStrings() == null ? null : new ArrayList<>(c.getEnumValuesAsStrings());
ExtraConstraintsDto jpa = new ExtraConstraintsDto();
jpa.tableName = c.getTableName();
jpa.tableId = new TableIdDto();
jpa.tableId.name = c.getTableName();
jpa.tableId.schema = null; //TODO
jpa.tableId.catalog = null; //TODO
jpa.columnName = c.getColumnName();
jpa.constraints = ec;
return jpa;
Expand Down Expand Up @@ -1521,7 +1526,7 @@ public void resetDatabase(List<String> tablesToClean) {

if(tablesToClean == null){
// all data will be reset
DbCleaner.clearDatabase(spec.connection, null, null, null, spec.dbType);
DbCleaner.clearDatabase(spec.connection, null, null, null, spec.dbType, true);
try {
reAddAllInitSql();
} catch (SQLException e) {
Expand All @@ -1532,10 +1537,12 @@ public void resetDatabase(List<String> tablesToClean) {

if (tablesToClean.isEmpty()) return;

if (spec.schemaNames == null || spec.schemaNames.isEmpty())
DbCleaner.clearDatabase(spec.connection, null, null, tablesToClean, spec.dbType);
else
spec.schemaNames.forEach(sp-> DbCleaner.clearDatabase(spec.connection, sp, null, tablesToClean, spec.dbType));
DbCleaner.clearTables(spec.connection, tablesToClean, spec.dbType);

// if (spec.schemaNames == null || spec.schemaNames.isEmpty())
// DbCleaner.clearDatabase(spec.connection, null, null, tablesToClean, spec.dbType);
// else
// spec.schemaNames.forEach(sp-> DbCleaner.clearDatabase(spec.connection, sp, null, tablesToClean, spec.dbType));

try {
handleInitSqlInDbClean(tablesToClean, spec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SutInfoDto.OutputFormat getPreferredOutputFormat() {
@Override
public String startSut() {
running = true;
DbCleaner.clearDatabase(sqlConnection, null, DatabaseType.H2);
DbCleaner.clearDatabase_H2(sqlConnection, null, null);
return "foo";
}

Expand Down
Loading
Loading