From 35ef59abe18e12cae6ca5be699f5f2a31bc461fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Luis=20L=C3=B3pez=20L=C3=B3pez?= Date: Mon, 12 Oct 2026 10:29:38 +0000 Subject: [PATCH] YARN-12023. Make TestCapacityOverTimePolicy independent of the time of day. BaseSharingPolicyTest#generateRLEAlloc folded a reservation onto its period starting at initTime % period, with initTime taken from the wall clock. Its wrap-around arithmetic lost one full period whenever the remainder of the duration wrapped past the period end, e.g. a 25h reservation on a 1-day period generated only ~1h of allocation when the test ran between 23:00 and 24:00 UTC, so the expected PlanningQuotaException for that case was not thrown. Generate floor(duration / period) full periods plus the remainder starting at initTime % period, wrapping it if needed, so the generated allocation always amounts to duration. Also use a fixed initTime, as PeriodicRLESparseResourceAllocation#getRangeOverlapping can return an open-ended allocation when a step lands exactly on the range end, which makes CapacityOverTimePolicy reject some cases for that reason (YARN-12022) instead of the one under test at a few specific times of day. Co-Authored-By: Claude Opus 5.5 --- .../reservation/BaseSharingPolicyTest.java | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java index 1495dd8c2d3e84..c2635e0e97a054 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java @@ -54,6 +54,12 @@ public abstract class BaseSharingPolicyTest { public Class expectedError; + // A fixed start time (2026-10-12T12:30:00Z), so that the test does not + // depend on the time of day it runs at: its offset within the periods + // (12h30m in a day, 30m in 2h) keeps the generated allocations clear of + // the period boundaries. + private static final long INIT_TIME = 1791808200000L; + private long step; private long initTime; @@ -71,7 +77,7 @@ public abstract class BaseSharingPolicyTest { public void setup() { // 1 sec step step = 1000L; - initTime = System.currentTimeMillis(); + initTime = INIT_TIME; minAlloc = Resource.newInstance(1024, 1); res = new DefaultResourceCalculator(); @@ -152,32 +158,36 @@ private RLESparseResourceAllocation generateRLEAlloc(long period) { Resource alloc = Resources.multiply(minAlloc, height * totCont); - // loop in case the periodicity of the reservation is smaller than LCM long rStart = initTime % period; - long rEnd = initTime % period + duration; + if (period <= 1) { + rle.addInterval(new ReservationInterval(rStart, rStart + duration), + alloc); + return rle; + } - // handle wrap-around - if (period > 1 && rEnd > period) { - long diff = rEnd - period; - rEnd = period; + // Fold the duration onto the period, so that the generated allocation + // always amounts to duration * alloc regardless of rStart (i.e., of the + // time of day the test runs at). Each full period covered by the + // duration (e.g., 5h duration on a 2h periodicity) adds alloc over the + // whole period. + long fullPeriods = duration / period; + if (fullPeriods > 0) { + rle.addInterval(new ReservationInterval(0, period), + Resources.multiply(alloc, fullPeriods)); + } - // handle multiple wrap-arounds (e.g., 5h duration on a 2h periodicity) - if(duration > period) { - rle.addInterval(new ReservationInterval(0, period), - Resources.multiply(alloc, duration / period - 1)); - rle.addInterval(new ReservationInterval(0, diff % period), alloc); + // the remainder starts at rStart and may wrap around the period end + long remainder = duration % period; + if (remainder > 0) { + long rEnd = rStart + remainder; + if (rEnd > period) { + rle.addInterval(new ReservationInterval(rStart, period), alloc); + rle.addInterval(new ReservationInterval(0, rEnd - period), alloc); } else { - rle.addInterval(new ReservationInterval(0, diff), alloc); + rle.addInterval(new ReservationInterval(rStart, rEnd), alloc); } } - - if(rStart > rEnd){ - rle.addInterval(new ReservationInterval(rStart, period), alloc); - rle.addInterval(new ReservationInterval(0, rEnd), alloc); - } else { - rle.addInterval(new ReservationInterval(rStart, rEnd), alloc); - } return rle; }