@Test public void givenKnownUsageHourOfVirtualMachineWhenModifyingStateOfVirtualMachineThenModificationMustBeAccessibleFromRepositoryInterface() { long organizationId = System.currentTimeMillis(); UsageHour expected = new UsageHour(); expected.setClusterId(123456); expected.setMachineId(654321); expected.setOrganizationId(organizationId); expected.setPlatformId(2); expected.setVirtualMachineState(VirtualMachineState.STARTED); usageHourRepository.store(expected); Collection<UsageHour> usageHours = usageHourRepository.loadUsageHoursByOrganizationId(organizationId); assertEquals(1, usageHours.size()); UsageHour actual = null; for (UsageHour usage : usageHours) { actual = usage; } assertEquals(expected.getClusterId(), actual.getClusterId()); assertEquals(expected.getMachineId(), actual.getMachineId()); assertEquals(expected.getOrganizationId(), actual.getOrganizationId()); assertEquals(expected.getPlatformId(), actual.getPlatformId()); assertEquals( expected.getVirtualMachineState().getValue(), actual.getVirtualMachineState().getValue()); assertNotNull(actual.getTimeStamp()); assertNotSame(expected.getId(), actual.getId()); }
@Test public void givenKnownOrganizationIdAndTimePeriodWhenQueringStateModificationOfVirtualMachinesThenModificationMustBeAccessibleFromRepositoryInterfaceDuringDefinedTimePeriod() { long organizationId = System.currentTimeMillis(); UsageHour expected = new UsageHour(); expected.setClusterId(123456); expected.setMachineId(654321); expected.setOrganizationId(organizationId); expected.setPlatformId(2); expected.setVirtualMachineState(VirtualMachineState.STARTED); usageHourRepository.store(expected); DateTime startTime = new DateTime(1979, 4, 3, 12, 0, 0, 0); DateTime endTime = new DateTime(2079, 4, 3, 12, 0, 0, 0); Collection<UsageHour> usageHours = usageHourRepository.loadUsageHoursByOrganizationIdAndUsagePeriod( organizationId, startTime.toDate(), endTime.toDate()); assertEquals(1, usageHours.size()); UsageHour actual = null; for (UsageHour usage : usageHours) { actual = usage; } assertEquals(expected.getClusterId(), actual.getClusterId()); assertEquals(expected.getMachineId(), actual.getMachineId()); assertEquals(expected.getOrganizationId(), actual.getOrganizationId()); assertEquals(expected.getPlatformId(), actual.getPlatformId()); assertEquals( expected.getVirtualMachineState().getValue(), actual.getVirtualMachineState().getValue()); assertNotNull(actual.getTimeStamp()); assertNotSame(expected.getId(), actual.getId()); }
@Test public void givenKnownOrganizationIdAndTimePeriodWhenQueringStateModificationOfVirtualMachinesThenModificationMustBeAccessibleFromRepositoryInterfaceDuringDefinedTimePeriodAndCertainUptimeTimeSchedulesNeedsBeGiven() { long startTimeMilliseconds = System.currentTimeMillis(); UsageHour usageHour = createUsageHour(startTimeMilliseconds, VirtualMachineState.STOPPED); usageHourRepository.store(usageHour); UsageHour usageHour0 = createUsageHour(startTimeMilliseconds, VirtualMachineState.STARTED); usageHourRepository.store(usageHour0); UsageHour usageHour1 = createUsageHour(startTimeMilliseconds, VirtualMachineState.STOPPED); usageHourRepository.store(usageHour1); UsageHour usageHour2 = createUsageHour(startTimeMilliseconds, VirtualMachineState.STARTED); usageHourRepository.store(usageHour2); UsageHour usageHour3 = createUsageHour(startTimeMilliseconds, VirtualMachineState.PAUSED); usageHourRepository.store(usageHour3); UsageHour usageHour4 = createUsageHour(startTimeMilliseconds, VirtualMachineState.RESUMED); usageHourRepository.store(usageHour4); UsageHour usageHour5 = createUsageHour(startTimeMilliseconds, VirtualMachineState.STOPPED); usageHourRepository.store(usageHour5); UsageHour usageHour6 = createUsageHour(startTimeMilliseconds, VirtualMachineState.STARTED); usageHourRepository.store(usageHour6); UsageHour usageHour7 = createUsageHour(startTimeMilliseconds, VirtualMachineState.STOPPED); usageHourRepository.store(usageHour7); UsageHour usageHour8 = createUsageHour(startTimeMilliseconds, VirtualMachineState.PAUSED); usageHourRepository.store(usageHour8); UsageHour usageHour9 = createUsageHour(startTimeMilliseconds, VirtualMachineState.RESUMED); usageHourRepository.store(usageHour9); UsageHour usageHour10 = createUsageHour(startTimeMilliseconds, VirtualMachineState.TERMINATED); usageHourRepository.store(usageHour10); DateTime startTime = new DateTime(startTimeMilliseconds); DateTime endTime = new DateTime(System.currentTimeMillis()); Collection<UsageHour> usageHours = usageHourRepository.loadUsageHoursByOrganizationIdAndUsagePeriod( startTimeMilliseconds, startTime.toDate(), endTime.toDate()); assertEquals(12, usageHours.size()); UsagePeriod usagePeriod = new UsagePeriod(); usagePeriod.setUsageHours(usageHours); usagePeriod.setStartTime(startTime.toDate()); usagePeriod.setEndTime(endTime.toDate()); usagePeriod.loadUptimeHours(); float uptime = usagePeriod.getUptime(); System.out.println("Uptime in seconds : " + uptime / 1000); System.out.println("Uptime in minutes : " + uptime / 1000 / 60); System.out.println("Uptime in hours : " + uptime / 1000 / 60 / 60); }