use of com.axway.ats.log.autodb.CheckpointInfo in project ats-framework by Axway.
the class PGDbWriteAccess method startCheckpoint.
public CheckpointInfo startCheckpoint(String name, long startTimestamp, String transferRateUnit, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to start checkpoint '" + name + "' in load queue " + loadQueueId;
startTimestamp = inUTC(startTimestamp);
final int indexCheckpointSummaryId = 5;
final int indexCheckpointId = 6;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_start_checkpoint(?, ?, ?, ?, ?, ?) }");
callableStatement.setInt(1, loadQueueId);
callableStatement.setString(2, name);
callableStatement.setInt(3, checkpointLogLevel.toInt());
callableStatement.setString(4, transferRateUnit);
callableStatement.registerOutParameter(indexCheckpointSummaryId, Types.INTEGER);
callableStatement.registerOutParameter(indexCheckpointId, Types.BIGINT);
callableStatement.execute();
// we always update the checkpoint summary table
if (callableStatement.getInt(indexCheckpointSummaryId) == 0) {
throw new DatabaseAccessException(errMsg + " - checkpoint summary ID returned was 0");
}
// we update the checkpoint table only in FULL mode
if (checkpointLogLevel == CheckpointLogLevel.FULL && callableStatement.getInt(indexCheckpointId) == 0) {
throw new DatabaseAccessException(errMsg + " - checkpoint ID returned was 0");
}
int checkpointSummaryId = callableStatement.getInt(indexCheckpointSummaryId);
long checkpointId = callableStatement.getLong(indexCheckpointId);
return new CheckpointInfo(name, checkpointSummaryId, checkpointId, startTimestamp);
} catch (Exception e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, callableStatement);
} else {
DbUtils.closeStatement(callableStatement);
}
}
}
use of com.axway.ats.log.autodb.CheckpointInfo in project ats-framework by Axway.
the class DbEventRequestProcessor method endCheckpoint.
private void endCheckpoint(EndCheckpointEvent endCheckpointEvent) throws LoggingException {
// check if checkpoints are enabled at all
if (appenderConfig.getEnableCheckpoints()) {
LoadQueuesState loadQueuesState = eventProcessorState.getLoadQueuesState();
CheckpointInfo runningCheckpointInfo = loadQueuesState.endCheckpoint(endCheckpointEvent.getThread(), endCheckpointEvent.getName(), endCheckpointEvent.getEndTimestamp());
final int testcaseId = eventProcessorState.getTestCaseId();
if (!deletedTestcases.contains(testcaseId)) {
try {
dbAccess.endCheckpoint(runningCheckpointInfo, endCheckpointEvent.getEndTimestamp(), endCheckpointEvent.getTransferSize(), endCheckpointEvent.getResult().toInt(), true);
} catch (LoggingException e) {
handleDeletedTestcase(e, testcaseId);
}
}
}
}
use of com.axway.ats.log.autodb.CheckpointInfo in project ats-framework by Axway.
the class DbEventRequestProcessor method startCheckpoint.
private void startCheckpoint(StartCheckpointEvent startCheckpointEvent) throws LoggingException {
// check if checkpoints are enabled at all
if (appenderConfig.getEnableCheckpoints()) {
LoadQueuesState loadQueuesState = eventProcessorState.getLoadQueuesState();
int loadQueueId = loadQueuesState.getLoadQueueIdForThread(startCheckpointEvent.getThread());
if (loadQueueId > 0) {
final int testcaseId = eventProcessorState.getTestCaseId();
if (!deletedTestcases.contains(testcaseId)) {
try {
CheckpointInfo startedCheckpointInfo = dbAccess.startCheckpoint(startCheckpointEvent.getName(), startCheckpointEvent.getThread(), startCheckpointEvent.getStartTimestamp(), startCheckpointEvent.getTransferUnit(), loadQueueId, true);
loadQueuesState.startCheckpoint(startedCheckpointInfo, startCheckpointEvent.getThread());
} catch (LoggingException e) {
handleDeletedTestcase(e, testcaseId);
}
}
}
}
}
use of com.axway.ats.log.autodb.CheckpointInfo in project ats-framework by Axway.
the class SQLServerDbWriteAccess method startCheckpoint.
public CheckpointInfo startCheckpoint(String name, String threadName, long startTimestamp, String transferUnit, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to start checkpoint '" + name + "' in load queue " + loadQueueId;
startTimestamp = inUTC(startTimestamp);
final int indexCheckpointSummaryId = 5;
final int indexCheckpointId = 6;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_start_checkpoint(?, ?, ?, ?, ?, ?) }");
callableStatement.setInt(1, loadQueueId);
callableStatement.setString(2, name);
callableStatement.setInt(3, checkpointLogLevel.toInt());
callableStatement.setString(4, transferUnit);
callableStatement.registerOutParameter(indexCheckpointSummaryId, Types.INTEGER);
callableStatement.registerOutParameter(indexCheckpointId, Types.BIGINT);
callableStatement.execute();
// we always update the checkpoint summary table
if (callableStatement.getInt(indexCheckpointSummaryId) == 0) {
throw new DatabaseAccessException(errMsg + " - checkpoint summary ID returned was 0");
}
// we update the checkpoint table only in FULL mode
if (checkpointLogLevel == CheckpointLogLevel.FULL && callableStatement.getLong(indexCheckpointId) == 0) {
throw new DatabaseAccessException(errMsg + " - checkpoint ID returned was 0");
}
int checkpointSummaryId = callableStatement.getInt(indexCheckpointSummaryId);
long checkpointId = callableStatement.getLong(indexCheckpointId);
return new CheckpointInfo(name, checkpointSummaryId, checkpointId, startTimestamp);
} catch (Exception e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, callableStatement);
} else {
DbUtils.closeStatement(callableStatement);
}
}
}
use of com.axway.ats.log.autodb.CheckpointInfo in project ats-framework by Axway.
the class SQLServerDbWriteAccess method runDbSanityCheck.
public void runDbSanityCheck() throws DatabaseAccessException {
DatabaseAccessException dbae = null;
final String SANITY_PRODUCT = "SanityCheck(TestProduct)";
final String SANITY_VERSION = "SanityCheck(TestVersion)";
final String SANITY_BUILD = "SanityCheck(TestBuild)";
final String SANITY_RUN = "SanityCheck(TestRun)";
final String SANITY_OS = "SanityCheck(TestOS)";
final String SANITY_SUITE = "SanityCheck(TestSuite)";
final String SANITY_SCENARIO = "SanityCheck(TestScenario)";
final String SANITY_TESTCASE = "SanityCheck(Testcase)";
final String SANITY_LOADQUEUE = "SanityCheck(TestLoadqueue)";
final String SANITY_CHECKPOINT = "SanityCheck(TestCheckpoint)";
final String SANITY_MESSAGE = "SanityCheck(TestMessage)";
final String SANITY_DESCRIPTION = "sanity description";
final String SANITY_HOSTNAME = "SanityCheck(TestHostName)";
boolean originalAutoCommitState = false;
try {
this.connection = getConnection();
// in sanity mode, the connection will be reused
sanityRun = true;
String javaFrameworkVersion = AtsVersion.getAtsVersion();
log.info("ATS framework version is '" + javaFrameworkVersion + "'");
log.info("Checking for ATS log database connection with the following parameters: " + connection.toString());
String databaseVersion = getDatabaseVersion();
log.info("ATS Log database version is '" + databaseVersion + "'");
if (!javaFrameworkVersion.equalsIgnoreCase(databaseVersion)) {
if (AtsSystemProperties.getPropertyAsBoolean(AtsSystemProperties.FAIL_ON_ATS_VERSION_MISMATCH, false)) {
throw new IllegalStateException(String.format("ATS Version mismatch! Database at '%s' is version '%s' while you are using ATS Framework version '%s'!", this.dbConnectionFactory.getURL(), databaseVersion, javaFrameworkVersion));
} else {
log.warn("*** ATS WARNING *** You are using ATS version " + javaFrameworkVersion + " with ATS Log database version " + databaseVersion + ". This might cause incompatibility problems!");
}
}
originalAutoCommitState = connection.getAutoCommit();
// disable auto commit
connection.setAutoCommit(false);
long timestamp = Calendar.getInstance().getTimeInMillis();
// start everything
int runId = startRun(SANITY_RUN, SANITY_OS, SANITY_PRODUCT, SANITY_VERSION, SANITY_BUILD, timestamp, SANITY_HOSTNAME, false);
// insert a run message
insertRunMessage(SANITY_MESSAGE, 5, false, "machine0", "group1-thread2", timestamp, runId, false);
int suiteId = startSuite("SANITY_PACKAGE", SANITY_SUITE, timestamp, runId, false);
// insert a run message
insertSuiteMessage(SANITY_MESSAGE, 5, false, "machine0", "group1-thread2", timestamp, suiteId, false);
int testcaseId = startTestCase(SANITY_SUITE, SANITY_SCENARIO, SANITY_DESCRIPTION, SANITY_TESTCASE, timestamp, suiteId, false);
// insert a test message
insertMessage(SANITY_MESSAGE, 5, false, "machine0", "group1-thread2", timestamp, testcaseId, false);
// insert a checkpoint
int loadQueueId = startLoadQueue(SANITY_LOADQUEUE, 0, "127.0.0.1:8080", "AllAtOnce", 10, "localhost", timestamp, testcaseId, false);
populateCheckpointSummary(loadQueueId, SANITY_CHECKPOINT, "KB", false);
CheckpointInfo startedCheckpointInfo = startCheckpoint(SANITY_CHECKPOINT, "thread1", 1000, "KB", loadQueueId, false);
endCheckpoint(startedCheckpointInfo, 2000, 100, CheckpointResult.PASSED.toInt(), false);
int statisticId1 = populateSystemStatisticDefinition("running users", "", "", "count", "param1_1");
int statisticId2 = populateSystemStatisticDefinition("standby users", "", "", "count", "param2_1");
insertSystemStatistics(testcaseId, "localhost", statisticId1 + "_" + statisticId2, "30_1", System.currentTimeMillis(), false);
endLoadQueue(LoadQueueResult.PASSED.toInt(), timestamp, loadQueueId, false);
// end everything
endTestCase(1, timestamp, testcaseId, false);
endSuite(timestamp, suiteId, false);
endRun(timestamp, runId, false);
} catch (SQLException sqle) {
String errorMessage = "Unable to insert sanity check sample data";
log.error(DbUtils.getFullSqlException(errorMessage, sqle));
dbae = new DatabaseAccessException(errorMessage, sqle);
} finally {
if (dbEventsCache != null) {
// it is in batch mode, we want to cleanup the events cached
// while running the sanity check
dbEventsCache.resetCache();
}
sanityRun = false;
try {
// rollback the connection
if (connection != null && !connection.getAutoCommit()) {
connection.rollback();
}
} catch (SQLException sqle) {
String errorMessage = "Unable to revert sanity check data";
log.error(DbUtils.getFullSqlException(errorMessage, sqle));
if (dbae == null) {
dbae = new DatabaseAccessException(errorMessage, sqle);
} else {
log.error("The transaction could not be rolled back, possible cause '" + dbae.getMessage() + "'");
}
} finally {
try {
if (connection != null) {
connection.setAutoCommit(originalAutoCommitState);
}
} catch (SQLException e) {
// do not hide the possible exception
// in the rollback() catch block
log.error(DbUtils.getFullSqlException("Could not restore connection's autocommit state", e));
} finally {
DbUtils.closeConnection(connection);
}
}
}
// with priority
if (dbae != null) {
throw dbae;
}
}
Aggregations