mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
fix invalid range
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
864afda935
commit
3e830252ab
@ -44,12 +44,16 @@ public class RangeTimeBackoff extends AdapterBase implements BackoffAlgorithm {
|
||||
|
||||
@Override
|
||||
public void waitBeforeRetry() {
|
||||
long time = minTime * 1000L;
|
||||
long time = Math.max(minTime, 0) * 1000L;
|
||||
Thread current = Thread.currentThread();
|
||||
try {
|
||||
asleep.put(current.getName(), current);
|
||||
time = ThreadLocalRandom.current().nextInt(minTime, maxTime) * 1000L;
|
||||
LOG.debug("Waiting " + current.getName() + " for " + time);
|
||||
if (maxTime > minTime) {
|
||||
time = ThreadLocalRandom.current().nextInt(minTime, maxTime) * 1000L;
|
||||
}
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Waiting %s for %d milliseconds", current.getName(), time));
|
||||
}
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException e) {
|
||||
// JMX or other threads may interrupt this thread, but let's log it
|
||||
|
||||
@ -31,8 +31,8 @@ public class RangeTimeBackoffTest {
|
||||
public void testWaitValidValue() {
|
||||
RangeTimeBackoff backoff = new RangeTimeBackoff();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
int min = 5;
|
||||
int max = 10;
|
||||
int min = 1;
|
||||
int max = 3;
|
||||
map.put("minSeconds", String.valueOf(min));
|
||||
map.put("maxSeconds", String.valueOf(max));
|
||||
backoff.configure("RangeTimeBackoff", map);
|
||||
@ -67,4 +67,18 @@ public class RangeTimeBackoffTest {
|
||||
Assert.assertTrue(timeTaken >= RangeTimeBackoff.DEFAULT_MIN_TIME * 1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWaitVMinHigherThanMax() {
|
||||
RangeTimeBackoff backoff = new RangeTimeBackoff();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
int min = 3;
|
||||
int max = 2;
|
||||
map.put("minSeconds", String.valueOf(min));
|
||||
map.put("maxSeconds", String.valueOf(max));
|
||||
backoff.configure("RangeTimeBackoff", map);
|
||||
long startTime = System.currentTimeMillis();
|
||||
backoff.waitBeforeRetry();
|
||||
long timeTaken = System.currentTimeMillis() - startTime;
|
||||
Assert.assertTrue(timeTaken >= min * 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user