use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getCheckpointStatistics.
public List<Statistic> getCheckpointStatistics(float timeOffset, String testcaseIds, String actionNames, Set<String> expectedSingleActionUIDs, Set<String> expectedCombinedActionUIDs) throws DatabaseAccessException {
List<Statistic> allStatistics = new ArrayList<Statistic>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).add("checkpoint names", actionNames).format();
Map<String, Integer> fakeStatisticIds = new HashMap<String, Integer>();
/*
* The DB does not contain combined statistics, so we must create them.
*
* All statistics with same name are combined in one statistic(no matter how many queues are).
* In cases when there are more than one hits at same timestamp, we do not sum the values, but we
* pass the same number of statistics for this timestamp - users see balloon marker on Test Explorer
*/
Map<String, Statistic> combinedStatistics = new HashMap<String, Statistic>();
Map<String, Integer> combinedStatisticHitsAtSameTimestamp = new HashMap<String, Integer>();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_checkpoint_statistics(?, ?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, testcaseIds);
callableStatement.setString(3, actionNames);
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
// add new statistic
Statistic statistic = new Statistic();
statistic.name = rs.getString("statsName");
statistic.parentName = rs.getString("queueName");
statistic.unit = "ms";
statistic.value = rs.getFloat("value");
statistic.timestamp = rs.getLong("statsAxisTimestamp");
// Checkpoints will be collected and displayed for testcase
statistic.machineId = 0;
statistic.testcaseId = rs.getInt("testcaseId");
statistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_CHECKPOINTS, fakeStatisticIds, statistic);
// add to single statistics
if (expectedSingleActionUIDs.contains(statistic.getUid())) {
allStatistics.add(statistic);
}
// add to combined statistics
if (expectedCombinedActionUIDs.contains(statistic.getCombinedStatisticUid())) {
String statisticKey = statistic.timestamp + "->" + statistic.name;
Integer timesHaveThisStatisticAtThisTimestamp = combinedStatisticHitsAtSameTimestamp.get(statisticKey);
Statistic combinedStatistic;
if (timesHaveThisStatisticAtThisTimestamp == null) {
// create a new combined statistic
combinedStatistic = new Statistic();
combinedStatistic.name = statistic.name;
combinedStatistic.parentName = Statistic.COMBINED_STATISTICS_CONTAINER;
combinedStatistic.unit = statistic.unit;
combinedStatistic.timestamp = statistic.timestamp;
combinedStatistic.machineId = statistic.machineId;
combinedStatistic.testcaseId = statistic.testcaseId;
// this is the first such statistic at this timestamp
timesHaveThisStatisticAtThisTimestamp = 1;
} else {
// create another copy of this statistic
combinedStatistic = combinedStatistics.get(statisticKey + "->" + timesHaveThisStatisticAtThisTimestamp).newInstance();
// we already had such statistic at this timestamp
timesHaveThisStatisticAtThisTimestamp++;
}
combinedStatistic.value = statistic.value;
combinedStatistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_CHECKPOINTS, fakeStatisticIds, combinedStatistic);
// remember how many times we got same statistic at same timestamp
combinedStatisticHitsAtSameTimestamp.put(statisticKey, timesHaveThisStatisticAtThisTimestamp);
// Remember this statistic in the list
// The way we create the map key assures the proper time ordering
combinedStatistics.put(statisticKey + "->" + timesHaveThisStatisticAtThisTimestamp, combinedStatistic);
}
numberRecords++;
}
if (combinedStatistics.size() > 0) {
// sort the combined statistics by their timestamps
List<Statistic> sortedStatistics = new ArrayList<Statistic>(combinedStatistics.values());
Collections.sort(sortedStatistics, new Comparator<Statistic>() {
@Override
public int compare(Statistic stat1, Statistic stat2) {
return (int) (stat1.timestamp - stat2.timestamp);
}
});
// add the combined statistics to the others
allStatistics.addAll(sortedStatistics);
}
logQuerySuccess(sqlLog, "action response statistics", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return allStatistics;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getSystemStatisticDescriptions.
public List<StatisticDescription> getSystemStatisticDescriptions(float timeOffset, String testcaseIds, Map<String, String> testcaseAliases) throws DatabaseAccessException {
List<StatisticDescription> statisticDescriptions = new ArrayList<StatisticDescription>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_system_statistic_descriptions(?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, testcaseIds);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
StatisticDescription statisticDescription = new StatisticDescription();
statisticDescription.testcaseId = rs.getInt("testcaseId");
// if user has provided testcase alias - use it instead the original testcase name
if (testcaseAliases != null) {
statisticDescription.testcaseName = testcaseAliases.get(String.valueOf(statisticDescription.testcaseId));
}
if (statisticDescription.testcaseName == null) {
statisticDescription.testcaseName = rs.getString("testcaseName");
}
statisticDescription.testcaseStarttime = rs.getInt("testcaseStarttime");
statisticDescription.machineId = rs.getInt("machineId");
statisticDescription.machineName = rs.getString("machineName");
statisticDescription.statisticTypeId = rs.getInt("statsTypeId");
statisticDescription.statisticName = rs.getString("name");
statisticDescription.unit = rs.getString("units");
statisticDescription.params = rs.getString("params");
statisticDescription.parent = rs.getString("parentName");
statisticDescription.internalName = rs.getString("internalName");
statisticDescription.numberMeasurements = rs.getInt("statsNumberMeasurements");
statisticDescription.minValue = rs.getFloat("statsMinValue");
statisticDescription.maxValue = rs.getFloat("statsMaxValue");
statisticDescription.avgValue = rs.getFloat("statsAvgValue");
statisticDescriptions.add(statisticDescription);
numberRecords++;
}
logQuerySuccess(sqlLog, "system statistic descriptions", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return statisticDescriptions;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getCheckpointStatisticDescriptions.
public List<StatisticDescription> getCheckpointStatisticDescriptions(float timeOffset, String testcaseIds, Map<String, String> testcaseAliases) throws DatabaseAccessException {
List<StatisticDescription> statisticDescriptions = new ArrayList<StatisticDescription>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_checkpoint_statistic_descriptions(?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, testcaseIds);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
StatisticDescription statisticDescription = new StatisticDescription();
statisticDescription.testcaseId = rs.getInt("testcaseId");
// if user has provided testcase alias - use it instead the original testcase name
if (testcaseAliases != null) {
statisticDescription.testcaseName = testcaseAliases.get(String.valueOf(statisticDescription.testcaseId));
}
if (statisticDescription.testcaseName == null) {
statisticDescription.testcaseName = rs.getString("testcaseName");
}
statisticDescription.testcaseStarttime = rs.getInt("testcaseStarttime");
// Checkpoints will be collected and displayed for testcase
statisticDescription.machineId = 0;
statisticDescription.machineName = MACHINE_NAME_FOR_ATS_AGENTS;
statisticDescription.queueName = rs.getString("queueName");
statisticDescription.numberMeasurements = rs.getInt("statsNumberMeasurements");
statisticDescription.statisticName = rs.getString("name");
// "statsUnit" field is null for checkpoint statistics, because the action response times are always measured in "ms"
statisticDescription.unit = "ms";
statisticDescriptions.add(statisticDescription);
numberRecords++;
}
logQuerySuccess(sqlLog, "system statistic descriptions", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return statisticDescriptions;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getScenariosCount.
public int getScenariosCount(String whereClause) throws DatabaseAccessException {
String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_scenarios_count(?) }");
callableStatement.setString(1, whereClause);
rs = callableStatement.executeQuery();
int scenariosCount = 0;
while (rs.next()) {
scenariosCount = rs.getInt("scenariosCount");
logQuerySuccess(sqlLog, "scenarios", scenariosCount);
break;
}
return scenariosCount;
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getTestcases.
public List<Testcase> getTestcases(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
List<Testcase> testcases = new ArrayList<Testcase>();
String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_testcases(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending ? "ASC" : "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
Testcase testcase = new Testcase();
testcase.testcaseId = rs.getString("testcaseId");
testcase.scenarioId = rs.getString("scenarioId");
testcase.suiteId = rs.getString("suiteId");
testcase.name = rs.getString("name");
if (dateFormatNoYear) {
testcase.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
testcase.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
} else {
testcase.dateStart = formatDate(rs.getTimestamp("dateStart"));
testcase.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
}
int duration = rs.getInt("duration");
if (duration < 0) {
// this may happen when the test case is not ended and the time of the log server
// is behind with the time of the test executor host
duration = 0;
}
testcase.duration = formatTimeDiffereceFromSecondsToString(duration);
testcase.result = rs.getInt("result");
/*
* -- 0 FAILED
* -- 1 PASSED
* -- 2 SKIPPED
* -- 4 RUNNING
*/
switch(testcase.result) {
case 0:
testcase.state = "FAILED";
break;
case 1:
testcase.state = "PASSED";
break;
case 2:
testcase.state = "SKIPPED";
break;
case 4:
testcase.state = "RUNNING";
break;
default:
//TODO: add warning
testcase.state = "unknown";
}
testcase.userNote = rs.getString("userNote");
testcases.add(testcase);
numberRecords++;
}
logQuerySuccess(sqlLog, "test cases", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return testcases;
}
Aggregations