Added primitive assessment.
This commit is contained in:
parent
8dd443295c
commit
7148a63b6f
|
@ -0,0 +1,78 @@
|
|||
package com.gyrobian.assessment;
|
||||
|
||||
import com.gyrobian.database.CachedResultSet;
|
||||
import com.gyrobian.database.ExecutionLog;
|
||||
import com.gyrobian.database.QueryAction;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ExecutionLogComparisonAssessment {
|
||||
|
||||
private boolean sameNumberOfActions;
|
||||
|
||||
private boolean sameNumberOfSelectQueries;
|
||||
|
||||
private List<SQLException> templateExceptions;
|
||||
|
||||
private List<SQLException> testingExceptions;
|
||||
|
||||
private List<String> queryDiscrepancies;
|
||||
|
||||
private ExecutionLogComparisonAssessment() {
|
||||
this.queryDiscrepancies = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an assessment from two execution logs.
|
||||
* @param template The template log to check the testing log against.
|
||||
* @param testing The testing log, to check for errors in.
|
||||
* @return A new assessment object containing details about how these two execution logs differ.
|
||||
*/
|
||||
public static ExecutionLogComparisonAssessment fromExecutionLogs(ExecutionLog template, ExecutionLog testing) {
|
||||
ExecutionLogComparisonAssessment assessment = new ExecutionLogComparisonAssessment();
|
||||
assessment.sameNumberOfActions = template.getActions().size() == testing.getActions().size();
|
||||
assessment.templateExceptions = template.getExceptions();
|
||||
assessment.testingExceptions = testing.getExceptions();
|
||||
|
||||
assessment.sameNumberOfSelectQueries = template.getQueryActions().size() == testing.getQueryActions().size();
|
||||
// If both scripts have the same number of selects, check if they're similar.
|
||||
if (assessment.sameNumberOfSelectQueries) {
|
||||
List<QueryAction> templateQueries = template.getQueryActions();
|
||||
List<QueryAction> testingQueries = testing.getQueryActions();
|
||||
for (int i = 0; i < templateQueries.size(); i++) {
|
||||
CachedResultSet templateResult = templateQueries.get(i).getResultSet();
|
||||
CachedResultSet testingResult = testingQueries.get(i).getResultSet();
|
||||
if (templateResult.getRowCount() != testingResult.getRowCount()) {
|
||||
assessment.queryDiscrepancies.add("Template row count doesn't match testing row count for query " + i + ".");
|
||||
}
|
||||
if (templateResult.getColumnNames().length != testingResult.getColumnNames().length) {
|
||||
assessment.queryDiscrepancies.add("Template query has different number of columns, compared to testing query, for query " + i + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return assessment;
|
||||
}
|
||||
|
||||
public boolean hasSameNumberOfActions() {
|
||||
return sameNumberOfActions;
|
||||
}
|
||||
|
||||
public boolean hasSameNumberOfSelectQueries() {
|
||||
return sameNumberOfSelectQueries;
|
||||
}
|
||||
|
||||
public List<SQLException> getTemplateExceptions() {
|
||||
return templateExceptions;
|
||||
}
|
||||
|
||||
public List<SQLException> getTestingExceptions() {
|
||||
return testingExceptions;
|
||||
}
|
||||
|
||||
public List<String> getQueryDiscrepancies() {
|
||||
return queryDiscrepancies;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.gyrobian.database;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,14 +28,41 @@ public class ExecutionLog {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return True if there's an exception somewhere in this execution log, or false otherwise.
|
||||
* @return The list of all exceptions encountered.
|
||||
*/
|
||||
public boolean containsExceptions() {
|
||||
for (ExecutionAction action : this.getActions()) {
|
||||
public List<SQLException> getExceptions() {
|
||||
List<SQLException> exceptions = new ArrayList<>();
|
||||
this.actions.forEach(action -> {
|
||||
if (action.getException() != null) {
|
||||
return true;
|
||||
exceptions.add(action.getException());
|
||||
}
|
||||
});
|
||||
return exceptions;
|
||||
}
|
||||
return false;
|
||||
|
||||
/**
|
||||
* @return The list of all schema update actions encountered.
|
||||
*/
|
||||
public List<UpdateAction> getSchemaUpdateActions() {
|
||||
List<UpdateAction> updateActions = new ArrayList<>();
|
||||
this.actions.forEach(action -> {
|
||||
if (action instanceof UpdateAction) {
|
||||
updateActions.add((UpdateAction) action);
|
||||
}
|
||||
});
|
||||
return updateActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The list of all query actions encountered.
|
||||
*/
|
||||
public List<QueryAction> getQueryActions() {
|
||||
List<QueryAction> queryActions = new ArrayList<>();
|
||||
this.actions.forEach(action -> {
|
||||
if (action instanceof QueryAction) {
|
||||
queryActions.add((QueryAction) action);
|
||||
}
|
||||
});
|
||||
return queryActions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.gyrobian.listener;
|
||||
|
||||
import com.gyrobian.assessment.ExecutionLogComparisonAssessment;
|
||||
import com.gyrobian.database.ExecutionLog;
|
||||
import com.gyrobian.view.AssessmentDisplay;
|
||||
import com.gyrobian.view.ExecutionLogDisplay;
|
||||
|
@ -40,22 +41,20 @@ public class AssessExecutionsListener implements ActionListener {
|
|||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ExecutionLog lastTemplateExecution = this.templateExecutionLogDisplay.getLastExecutionLogDisplayed();
|
||||
ExecutionLog lastTestingExecution = this.testingExecutionLogDisplay.getLastExecutionLogDisplayed();
|
||||
if (lastTemplateExecution == null || lastTestingExecution == null) {
|
||||
this.assessmentDisplay.appendToDocument("Could not find a recent execution for one of the scripts, re-running...\n", null);
|
||||
triggerButton(this.executeTemplateButton, this);
|
||||
triggerButton(this.executeTestingButton, this);
|
||||
lastTemplateExecution = this.templateExecutionLogDisplay.getLastExecutionLogDisplayed();
|
||||
lastTestingExecution = this.testingExecutionLogDisplay.getLastExecutionLogDisplayed();
|
||||
ExecutionLog lastTemplateExecution = this.templateExecutionLogDisplay.getLastExecutionLogDisplayed();
|
||||
ExecutionLog lastTestingExecution = this.testingExecutionLogDisplay.getLastExecutionLogDisplayed();
|
||||
|
||||
if (lastTemplateExecution == null || lastTestingExecution == null) {
|
||||
JOptionPane.showMessageDialog(this.assessmentDisplay, "Could not execute both scripts.", "Assessment Error", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.assessmentDisplay.setText(null);
|
||||
|
||||
ExecutionLogComparisonAssessment assessment = ExecutionLogComparisonAssessment.fromExecutionLogs(lastTemplateExecution, lastTestingExecution);
|
||||
this.assessmentDisplay.displayAssessment(assessment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,37 @@
|
|||
package com.gyrobian.view;
|
||||
|
||||
import com.gyrobian.assessment.ExecutionLogComparisonAssessment;
|
||||
|
||||
/**
|
||||
* A text pane that's specially suited for displaying the results of assessing two execution logs.
|
||||
*/
|
||||
public class AssessmentDisplay extends AppendableJTextPane {
|
||||
|
||||
public void displayAssessment(ExecutionLogComparisonAssessment assessment) {
|
||||
if (assessment.hasSameNumberOfActions()) {
|
||||
this.appendToDocument("Scripts perform the same number of actions.\n", null);
|
||||
} else {
|
||||
this.appendToDocument("Warning! Scripts do not perform the same number of actions. This does not explicitly mean the testing script is wrong, but may indicate so.\n", null);
|
||||
}
|
||||
|
||||
if (assessment.hasSameNumberOfSelectQueries()) {
|
||||
this.appendToDocument("Scripts perform the same number of SELECT queries.\n", null);
|
||||
} else {
|
||||
this.appendToDocument("Warning! Scripts do not perform the same number of SELECT queries. While not a 100% indicator, it is very likely that the testing script is incorrect.\n", null);
|
||||
}
|
||||
|
||||
if (assessment.getTemplateExceptions().size() > 0) {
|
||||
this.appendToDocument("Warning! Template script throws exceptions! Check execution output.\n", null);
|
||||
}
|
||||
if (assessment.getTestingExceptions().size() > 0) {
|
||||
this.appendToDocument("Warning! Testing script throws exceptions! Check execution output. This is indicative of an incorrect script.\n", null);
|
||||
}
|
||||
|
||||
if (assessment.getQueryDiscrepancies().size() > 0) {
|
||||
this.appendToDocument("Warning! There are discrepancies in the results of SELECT queries done by the template and testing scripts.\n", null);
|
||||
for (String message : assessment.getQueryDiscrepancies()) {
|
||||
this.appendToDocument("\t" + message + "\n", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue