Browse Source

SONAR-18386 Add ANALYZE to test to avoid timeout on purge audit

tags/9.9.1.69595
Léo Geoffroy 1 year ago
parent
commit
1886a1601a

+ 20
- 0
server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java View File

@@ -19,6 +19,8 @@
*/
package org.sonar.db.audit;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
@@ -26,6 +28,7 @@ import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.core.util.UuidFactoryImpl;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.dialect.PostgreSql;

import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
@@ -62,6 +65,14 @@ public class AuditDaoTest {
@Test
public void purge_has_limit() {
prepareRowsWithDeterministicCreatedAt(100_001);
//SONAR-18386 In order to prevent database to hang forever, we let it digest the inserted data
if (db.getDbClient().getDatabase().getDialect().getId().equals(PostgreSql.ID)) {
try (Statement statement = db.getSession().getSqlSession().getConnection().createStatement()) {
statement.execute("ANALYZE audits");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
long purged = testAuditDao.deleteBefore(dbSession, 200_000);
assertThat(purged).isEqualTo(100_000);
assertThat(db.countRowsOfTable(dbSession, "audits")).isOne();
@@ -73,6 +84,14 @@ public class AuditDaoTest {
@Test
public void purge_with_threshold() {
prepareRowsWithDeterministicCreatedAt(100_000);
//SONAR-18386 In order to prevent database to hang forever, we let it digest the inserted data
if (db.getDbClient().getDatabase().getDialect().getId().equals(PostgreSql.ID)) {
try (Statement statement = db.getSession().getSqlSession().getConnection().createStatement()) {
statement.execute("ANALYZE audits");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
long purged = testAuditDao.deleteBefore(dbSession, 50_000);
assertThat(purged).isEqualTo(49_999);
assertThat(db.countRowsOfTable(dbSession, "audits")).isEqualTo(50_001);
@@ -141,5 +160,6 @@ public class AuditDaoTest {
AuditDto auditDto = AuditTesting.newAuditDto(i);
testAuditDao.insert(dbSession, auditDto);
}
dbSession.commit();
}
}

Loading…
Cancel
Save