From a7f8115ab14c20e1e3a6693f894e1d9a50628280 Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Mon, 29 Jun 2026 12:34:45 -0700 Subject: [PATCH] PHOENIX-7946 CDCQueryIT IllegalArgumentException in testSelectWithTimeRange Co-authored-by: Claude Opus 4.8[1m] --- .../apache/phoenix/end2end/CDCQueryIT.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java index 385e4401ec2..79a1e136ce0 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCQueryIT.java @@ -777,18 +777,29 @@ public void testSelectWithTimeRange() throws Exception { lastDeletionTSpos = uniqueTimestamps.size() - 1; } } - Random rand = new Random(); - int randMinTSpos = rand.nextInt(lastDeletionTSpos - 1); - int randMaxTSpos = - randMinTSpos + 1 + rand.nextInt(uniqueTimestamps.size() - (randMinTSpos + 1)); + // Always verify the full range. verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, changes, 0, System.currentTimeMillis()); - verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, - changes, randMinTSpos, randMaxTSpos); - verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, - changes, randMinTSpos, lastDeletionTSpos); - verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, - changes, lastDeletionTSpos, randMaxTSpos); + // The random sub-range checks below require a deletion at a unique-timestamp position of + // at least 2 so that Random.nextInt(lastDeletionTSpos - 1) receives a positive bound, plus + // at least one unique timestamp after randMinTSpos so the second nextInt bound is positive + // too. When the generated change set does not satisfy this (no deletions, or a deletion + // only at position 0 or 1), skip the random sub-range exercise; the full-range + // verification above still covers the data. + if (lastDeletionTSpos != null && lastDeletionTSpos >= 2) { + Random rand = new Random(); + int randMinTSpos = rand.nextInt(lastDeletionTSpos - 1); + int remainingTSCount = uniqueTimestamps.size() - (randMinTSpos + 1); + if (remainingTSCount > 0) { + int randMaxTSpos = randMinTSpos + 1 + rand.nextInt(remainingTSCount); + verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, + changes, randMinTSpos, randMaxTSpos); + verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, + changes, randMinTSpos, lastDeletionTSpos); + verifyChangesViaSCN(tenantId, conn, cdcFullName, pkColumns, datatableName, dataColumns, + changes, lastDeletionTSpos, randMaxTSpos); + } + } } }