@Test public void testNexChargeTime() { final Queue<Double> vmTimes = new LinkedList<>(Arrays.asList(0d, 30d * MINUTE, 100d * MINUTE)); VMex vmMock = new VMex("TestVM", 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 EC2OnDemandPolicy(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(90d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01); assertEquals(90d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01); assertEquals(150d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01); vmMock.setStatus(VMStatus.TERMINATED); assertEquals(-1d, policyMock.nexChargeTime(vmMock), 0.01); }
@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() + HOUR * ((int) (elapsedTime / HOUR) + 1); } return result; }
EC2OnDemandPolicy 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() + HOUR * ((int) (elapsedTime / HOUR) + 1); } return result; } }
EC2OnDemandPolicy 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() + HOUR * ((int) (elapsedTime / HOUR) + 1); } return result; } EC2OnDemandPolicy(final Map<Pair<String, String>, BigDecimal> prices); }
EC2OnDemandPolicy 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() + HOUR * ((int) (elapsedTime / HOUR) + 1); } return result; } EC2OnDemandPolicy(final Map<Pair<String, String>, BigDecimal> prices); @Override BigDecimal billSingleVm(final VMex vm); @Override BigDecimal billSingleVmUntil(VMex vm, double endTime); @Override double nexChargeTime(final Vm vm); }
EC2OnDemandPolicy 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() + HOUR * ((int) (elapsedTime / HOUR) + 1); } return result; } EC2OnDemandPolicy(final Map<Pair<String, String>, BigDecimal> prices); @Override BigDecimal billSingleVm(final VMex vm); @Override BigDecimal billSingleVmUntil(VMex vm, double endTime); @Override double nexChargeTime(final Vm vm);  }