From bc326b211bdae41ac9c9fcd2ca6cc813347f0847 Mon Sep 17 00:00:00 2001 From: Benoit DUMONT Date: Fri, 4 Aug 2023 14:51:34 +0200 Subject: [PATCH] Fixed the Job that CANCELLED execution queue entries so that it does not not consider the timeout from the time it was inserted to the queue but the time when the execution was triggered. #2472 --- .../crud/dao/ITestCaseExecutionQueueDAO.java | 22 +++++++++++++------ .../dao/impl/TestCaseExecutionQueueDAO.java | 20 ++++++++--------- .../D2/include/en/changelog_4.17_en.adoc | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/source/src/main/java/org/cerberus/core/crud/dao/ITestCaseExecutionQueueDAO.java b/source/src/main/java/org/cerberus/core/crud/dao/ITestCaseExecutionQueueDAO.java index a66a35fefc..d63913353f 100644 --- a/source/src/main/java/org/cerberus/core/crud/dao/ITestCaseExecutionQueueDAO.java +++ b/source/src/main/java/org/cerberus/core/crud/dao/ITestCaseExecutionQueueDAO.java @@ -62,8 +62,8 @@ public interface ITestCaseExecutionQueueDAO { /** * Read TestCaseExecutionInQueue By Tag * - * @param tag Tag used to filter execution. - * @param stateList List of State to filter. + * @param tag Tag used to filter execution. + * @param stateList List of State to filter. * @param withDependencies * @return AnswerList that contains a list of TestCaseExecutionInQueue * object enriched with TestCase and Application objects @@ -150,13 +150,15 @@ public interface ITestCaseExecutionQueueDAO { TestCaseExecutionQueue findByKeyWithDependencies(long id) throws CerberusException; /** - * @param object the {@link org.cerberus.core.crud.entity.AppService} to Create + * @param object the {@link org.cerberus.core.crud.entity.AppService} to + * Create * @return {@link AnswerItem} */ AnswerItem create(TestCaseExecutionQueue object); /** - * @param object the {@link org.cerberus.core.crud.entity.AppService} to Update + * @param object the {@link org.cerberus.core.crud.entity.AppService} to + * Update * @return {@link AnswerItem} */ Answer update(TestCaseExecutionQueue object); @@ -264,6 +266,11 @@ public interface ITestCaseExecutionQueueDAO { Answer updateToCancelledForce(long id, String comment); /** + * This method moves queue State to CANCELLED any queue entry that has been + * in a running state for a too long period without any State change. It + * prevents execution that stops in an unexpected way to keep a slot + * resource in the queue for nothing. + * * @param timeOutInS * @param comment * @return @@ -278,7 +285,8 @@ public interface ITestCaseExecutionQueueDAO { Answer updateToErrorForce(long id, String comment); /** - * @param object the {@link org.cerberus.core.crud.entity.AppService} to Delete + * @param object the {@link org.cerberus.core.crud.entity.AppService} to + * Delete * @return {@link AnswerItem} */ Answer delete(TestCaseExecutionQueue object); @@ -293,10 +301,10 @@ public interface ITestCaseExecutionQueueDAO { * Uses data of ResultSet to create object {@link TestCaseExecutionQueue} * * @param resultSet ResultSet relative to select from table - * TestCaseExecutionInQueue + * TestCaseExecutionInQueue * @return object {@link TestCaseExecutionQueue} * @throws SQLException when trying to get value from - * {@link java.sql.ResultSet#getString(String)} + * {@link java.sql.ResultSet#getString(String)} * @see TestCaseExecutionQueue */ TestCaseExecutionQueue loadFromResultSet(ResultSet resultSet) throws SQLException, FactoryCreationException; diff --git a/source/src/main/java/org/cerberus/core/crud/dao/impl/TestCaseExecutionQueueDAO.java b/source/src/main/java/org/cerberus/core/crud/dao/impl/TestCaseExecutionQueueDAO.java index 000151f483..c8d9e23671 100644 --- a/source/src/main/java/org/cerberus/core/crud/dao/impl/TestCaseExecutionQueueDAO.java +++ b/source/src/main/java/org/cerberus/core/crud/dao/impl/TestCaseExecutionQueueDAO.java @@ -786,8 +786,8 @@ public AnswerList readDistinctValuesByCriteria(String columnName, String LOG.debug("SQL : " + query.toString()); } try (Connection connection = databaseSpring.connect(); - PreparedStatement preStat = connection.prepareStatement(query.toString()); - Statement stm = connection.createStatement();) { + PreparedStatement preStat = connection.prepareStatement(query.toString()); + Statement stm = connection.createStatement();) { int i = 1; if (!StringUtil.isEmpty(searchTerm)) { @@ -805,7 +805,7 @@ public AnswerList readDistinctValuesByCriteria(String columnName, String } try (ResultSet resultSet = preStat.executeQuery(); - ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) { + ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) { //gets the data while (resultSet.next()) { distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues")); @@ -1227,7 +1227,7 @@ public TestCaseExecutionQueue findByKeyWithDependencies(long id) throws Cerberus + "WHERE `" + COLUMN_ID + "` = ?"; try (Connection connection = this.databaseSpring.connect(); - PreparedStatement selectStatement = connection.prepareStatement(query);) { + PreparedStatement selectStatement = connection.prepareStatement(query);) { selectStatement.setLong(1, id); try (ResultSet result = selectStatement.executeQuery();) { if (!result.next()) { @@ -1269,7 +1269,7 @@ public AnswerItem create(TestCaseExecutionQueue object) } try (Connection connection = this.databaseSpring.connect(); - PreparedStatement preStat = connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);) { + PreparedStatement preStat = connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);) { int i = 1; preStat.setString(i++, object.getSystem()); @@ -1876,7 +1876,7 @@ public void updateToError(long id, String comment) throws CerberusException { } try (Connection connection = databaseSpring.connect(); - PreparedStatement updateStateAndCommentStatement = connection.prepareStatement(query)) { + PreparedStatement updateStateAndCommentStatement = connection.prepareStatement(query)) { updateStateAndCommentStatement.setString(1, comment); updateStateAndCommentStatement.setLong(2, id); @@ -1907,7 +1907,7 @@ public void updateToErrorFromQuWithDep(long id, String comment) throws CerberusE } try (Connection connection = databaseSpring.connect(); - PreparedStatement updateStateAndCommentStatement = connection.prepareStatement(query)) { + PreparedStatement updateStateAndCommentStatement = connection.prepareStatement(query)) { updateStateAndCommentStatement.setString(1, comment); updateStateAndCommentStatement.setLong(2, id); @@ -2077,7 +2077,7 @@ public AnswerItem updateToCancelledOldRecord(Integer timeOutInS, String String query = "UPDATE testcaseexecutionqueue " + "SET `" + COLUMN_STATE + "` = 'CANCELLED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " - + "WHERE TO_SECONDS(now()) - TO_SECONDS(DateCreated) > ? " + + "WHERE TO_SECONDS(now()) - TO_SECONDS(`" + COLUMN_DATEMODIF + "`) > ? " + "AND `" + COLUMN_STATE + "` IN ('WAITING','STARTING','EXECUTING')"; // Debug message on SQL. @@ -2360,11 +2360,11 @@ private TestCaseExecutionQueueToTreat loadQueueToTreatFromResultSet(ResultSet re * Uses data of ResultSet to create object {@link TestCaseExecutionQueue} * * @param resultSet ResultSet relative to select from table - * TestCaseExecutionInQueue + * TestCaseExecutionInQueue * @return object {@link TestCaseExecutionQueue} with objects * {@link ResultSet} and {@link Application} * @throws SQLException when trying to get value from - * {@link java.sql.ResultSet#getString(String)} + * {@link java.sql.ResultSet#getString(String)} * @see TestCaseExecutionQueue */ private TestCaseExecutionQueue loadWithDependenciesFromResultSet(ResultSet resultSet) throws SQLException, FactoryCreationException { diff --git a/source/src/main/resources/documentation/D2/include/en/changelog_4.17_en.adoc b/source/src/main/resources/documentation/D2/include/en/changelog_4.17_en.adoc index ddd9cc60ae..2aee8eacca 100644 --- a/source/src/main/resources/documentation/D2/include/en/changelog_4.17_en.adoc +++ b/source/src/main/resources/documentation/D2/include/en/changelog_4.17_en.adoc @@ -3,6 +3,7 @@ * Fixed scrollTo action. #2458 * Fixed wrong status on manual test execution. #2455 * Fixed impossibility to delete all property with the same name. #2454 +* Fixed the Job that CANCELLED execution queue entries so that it does not not consider the timeout from the time it was inserted to the queue but the time when the execution was triggered. #2472 *Improvements / New features* [square]