From: Pierre Date: Fri, 29 Sep 2023 07:56:23 +0000 (+0200) Subject: SONAR-20592 add uuid to order by clause X-Git-Tag: 10.3.0.82913~309 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=837129dc06f1d186bc9b369d34857659a54d4102;p=sonarqube.git SONAR-20592 add uuid to order by clause --- 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