]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20592 add uuid to order by clause
authorPierre <pierre.guillot@sonarsource.com>
Fri, 29 Sep 2023 07:56:23 +0000 (09:56 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 29 Sep 2023 20:02:47 +0000 (20:02 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/audit/AuditDaoIT.java
server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml

index f1c5c0a1fa3b341ef6ea7966ef32e83968926123..25bf6c6f7a2a486af6bf76b5c0b95b2e11f30d9c 100644 (file)
@@ -143,7 +143,8 @@ public class AuditDaoIT {
   public void selectByPeriodPaginated_whenRowsInAnyOrder_returnOrderedByCreatedAt(){
     List<Long> 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<AuditDto> 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<AuditDto> 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++) {
index b8c7ea1423d4206228130d9a8996c0dd53851ab3..1d04faa0b62b31b50f99458bf63a46fc79fa82d6 100644 (file)
@@ -31,7 +31,7 @@
     from audits a
     where
       a.created_at &gt;= #{start} and a.created_at &lt; #{end}
-    order by created_at asc
+    order by created_at asc, uuid asc
     <include refid="org.sonar.db.common.Common.pagination"/>
   </select>