Added missing handling of operator subtractTestNonNegative
This commit is contained in:
parent
4891bf5049
commit
c87c100ac5
|
@ -440,8 +440,18 @@ public class RLESparseResourceAllocation {
|
||||||
if (eB == null || eB.getValue() == null) {
|
if (eB == null || eB.getValue() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (op == RLEOperator.subtract) {
|
if (op == RLEOperator.subtract
|
||||||
return Resources.negate(eB.getValue());
|
|| op == RLEOperator.subtractTestNonNegative) {
|
||||||
|
Resource val = Resources.negate(eB.getValue());
|
||||||
|
// test for negative value and throws
|
||||||
|
if (op == RLEOperator.subtractTestNonNegative
|
||||||
|
&& (Resources.fitsIn(val, ZERO_RESOURCE)
|
||||||
|
&& !Resources.equals(val, ZERO_RESOURCE))) {
|
||||||
|
throw new PlanningException(
|
||||||
|
"RLESparseResourceAllocation: merge failed as the "
|
||||||
|
+ "resulting RLESparseResourceAllocation would be negative");
|
||||||
|
}
|
||||||
|
return val;
|
||||||
} else {
|
} else {
|
||||||
return eB.getValue();
|
return eB.getValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,6 +236,23 @@ public class TestRLESparseResourceAllocation {
|
||||||
// Expected!
|
// Expected!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try with null value of an entry in a
|
||||||
|
a.put(10L, null);
|
||||||
|
b.put(11L, Resource.newInstance(10, 5));
|
||||||
|
|
||||||
|
rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
|
||||||
|
rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
|
||||||
|
|
||||||
|
try {
|
||||||
|
RLESparseResourceAllocation out =
|
||||||
|
RLESparseResourceAllocation.merge(new DefaultResourceCalculator(),
|
||||||
|
Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB,
|
||||||
|
RLEOperator.subtractTestNonNegative, 0, 60);
|
||||||
|
fail();
|
||||||
|
} catch (PlanningException pe) {
|
||||||
|
// Expected!
|
||||||
|
}
|
||||||
|
|
||||||
// trying a case that should work
|
// trying a case that should work
|
||||||
a.put(10L, Resource.newInstance(10, 6));
|
a.put(10L, Resource.newInstance(10, 6));
|
||||||
b.put(11L, Resource.newInstance(5, 6));
|
b.put(11L, Resource.newInstance(5, 6));
|
||||||
|
|
Loading…
Reference in New Issue