GoogleOnDemandPolicy extends BaseCustomerVmBillingPolicy { @Override public double nexChargeTime(final Vm vm) { double result = -1; if (vm instanceof VMex && ((VMex) vm).getStatus() == VMStatus.RUNNING) { VMex vmex = (VMex) vm; double elapsedTime = getCurrentTime() - vmex.getStartTime(); result = vmex.getStartTime() + MINUTE * Math.max(10, (int) (elapsedTime / MINUTE) + 1); } return result; } GoogleOnDemandPolicy(final Map<Pair<String, String>, BigDecimal> prices); @Override BigDecimal billSingleVm(final VMex vm); @Override BigDecimal billSingleVmUntil(VMex vm, double endTime); BigDecimal computeBill(final VMex vm, double duration); @Override double nexChargeTime(final Vm vm);  }
@Test public void testNexChargeTime() { final Queue<Double> vmTimes = new LinkedList<>(Arrays.asList(0d, 30d * MINUTE, 100d * MINUTE)); VMex vmMock = new VMex("Test", broker.getId(), VM_MIPS, 1, VM_RAM, VM_BW, VM_SIZE, "Test", new CloudletSchedulerTimeShared()) { @Override protected double getCurrentTime() { return vmTimes.poll(); } }; final Queue<Double> policyTimes = new LinkedList<>(Arrays.asList(35d * MINUTE + 1, 60d * MINUTE + 1, 91d * MINUTE + 1, 101d * MINUTE + 1)); IVmBillingPolicy policyMock = new GoogleOnDemandPolicy(ImmutableMap.<Pair<String, String>, BigDecimal> of()) { @Override protected double getCurrentTime() { return policyTimes.poll(); } }; assertEquals(-1d, policyMock.nexChargeTime(vmMock), 0.01); vmMock.setStatus(VMStatus.RUNNING); assertEquals(40d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01); assertEquals(61d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01); assertEquals(92d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01); vmMock.setStatus(VMStatus.TERMINATED); assertEquals(-1d, policyMock.nexChargeTime(vmMock), 0.01); }