From 837129dc06f1d186bc9b369d34857659a54d4102 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 29 Sep 2023 09:56:23 +0200 Subject: [PATCH] SONAR-20592 add uuid to order by clause --- .../it/java/org/sonar/db/audit/AuditDaoIT.java | 18 +++++++++++++++++- .../org/sonar/db/audit/AuditMapper.xml | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/audit/AuditDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/audit/AuditDaoIT.java index f1c5c0a1fa3..25bf6c6f7a2 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/audit/AuditDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/audit/AuditDaoIT.java @@ -143,7 +143,8 @@ public class AuditDaoIT { public void selectByPeriodPaginated_whenRowsInAnyOrder_returnOrderedByCreatedAt(){ List createdAts = LongStream.range(1, 51).mapToObj(p -> p).collect(Collectors.toList()); Collections.shuffle(createdAts); - createdAts.stream().map(createdAt -> AuditTesting.newAuditDto(createdAt)) + createdAts.stream() + .map(createdAt -> AuditTesting.newAuditDto(createdAt)) .forEach(auditDto -> testAuditDao.insert(dbSession, auditDto)); List auditDtos = testAuditDao.selectByPeriodPaginated(dbSession, 1, 51, 1); @@ -151,6 +152,21 @@ public class AuditDaoIT { assertThat(auditDtos).hasSize(50); assertThat(auditDtos).extracting(p -> p.getCreatedAt()).isSorted(); } + @Test + public void selectByPeriodPaginated_whenRowsWithIdenticalCreatedAt_returnOrderedByCreatedAtAndUuids(){ + AuditDto auditDto1 = AuditTesting.newAuditDto(100L); + auditDto1.setUuid("uuid1"); + testAuditDao.insert(dbSession, auditDto1); + AuditDto auditDto2 = AuditTesting.newAuditDto(100L); + auditDto2.setUuid("uuid2"); + testAuditDao.insert(dbSession, auditDto2); + + List auditDtos = testAuditDao.selectByPeriodPaginated(dbSession, 99, 101, 1); + + assertThat(auditDtos).hasSize(2); + assertThat(auditDtos).extracting(p -> p.getCreatedAt()).isSorted(); + assertThat(auditDtos).extracting(p -> p.getUuid()).isSorted(); + } private void prepareRowsWithDeterministicCreatedAt(int size) { for (int i = 1; i <= size; i++) { diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml index b8c7ea1423d..1d04faa0b62 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml @@ -31,7 +31,7 @@ from audits a where a.created_at >= #{start} and a.created_at < #{end} - order by created_at asc + order by created_at asc, uuid asc -- 2.39.5