@Test public void should_getStatus_after_trial_period() { when(customerIdProvider.getCustomerId()).thenReturn(1L); PricePlanDefaults ppd = PricePlanDefaults.TEST; Instant collectionStartedAt = now.minus(3, DAYS); Instant trialPeriodEndsAt = now.minus(1, MILLIS); CustomerData customerData = CustomerData.builder() .customerId(1L) .customerName("customerName") .pricePlan(PricePlan.of(ppd).toBuilder().retentionPeriodDays(-1).build()) .source("source") .collectionStartedAt(collectionStartedAt) .trialPeriodEndsAt(trialPeriodEndsAt) .build(); when(customerService.getCustomerDataByCustomerId(eq(1L))).thenReturn(customerData); when(customerService.countMethods(eq(1L))).thenReturn(1000); GetStatusResponse status = dashboardService.getStatus(); assertNotNull(status); assertThat(status.getCollectedSinceMillis(), is(collectionStartedAt.toEpochMilli())); assertThat(status.getTrialPeriodEndsAtMillis(), is(trialPeriodEndsAt.toEpochMilli())); assertThat(status.getTrialPeriodPercent(), is(100)); assertThat(status.getTrialPeriodExpired(), is(true)); }
@Override @Transactional(readOnly = true) public GetStatusResponse getStatus() { long startedAt = clock.millis(); Long customerId = customerIdProvider.getCustomerId(); CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId); PricePlan pricePlan = customerData.getPricePlan(); List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId); List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan); List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds()); Instant now = clock.instant(); Instant collectionStartedAt = customerData.getCollectionStartedAt(); Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt(); Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt); Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now); Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min( 100, Math.toIntExact( trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis())); return GetStatusResponse.builder() .timestamp(startedAt) .queryTimeMillis(clock.millis() - startedAt) .pricePlan(pricePlan.getName()) .retentionPeriodDays(pricePlan.getRetentionPeriodDays()) .collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()) .maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()) .maxNumberOfMethods(pricePlan.getMaxMethods()) .collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)) .trialPeriodEndsAtMillis( trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()) .trialPeriodExpired(customerData.isTrialPeriodExpired(now)) .trialPeriodPercent(trialPeriodPercent) .numMethods(customerService.countMethods(customerId)) .numAgents(agents.size()) .numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()) .numLiveEnabledAgents( (int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()) .environments(environments) .applications(applications) .agents(agents) .build(); }
DashboardServiceImpl implements DashboardService { @Override @Transactional(readOnly = true) public GetStatusResponse getStatus() { long startedAt = clock.millis(); Long customerId = customerIdProvider.getCustomerId(); CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId); PricePlan pricePlan = customerData.getPricePlan(); List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId); List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan); List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds()); Instant now = clock.instant(); Instant collectionStartedAt = customerData.getCollectionStartedAt(); Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt(); Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt); Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now); Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min( 100, Math.toIntExact( trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis())); return GetStatusResponse.builder() .timestamp(startedAt) .queryTimeMillis(clock.millis() - startedAt) .pricePlan(pricePlan.getName()) .retentionPeriodDays(pricePlan.getRetentionPeriodDays()) .collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()) .maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()) .maxNumberOfMethods(pricePlan.getMaxMethods()) .collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)) .trialPeriodEndsAtMillis( trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()) .trialPeriodExpired(customerData.isTrialPeriodExpired(now)) .trialPeriodPercent(trialPeriodPercent) .numMethods(customerService.countMethods(customerId)) .numAgents(agents.size()) .numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()) .numLiveEnabledAgents( (int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()) .environments(environments) .applications(applications) .agents(agents) .build(); } }
DashboardServiceImpl implements DashboardService { @Override @Transactional(readOnly = true) public GetStatusResponse getStatus() { long startedAt = clock.millis(); Long customerId = customerIdProvider.getCustomerId(); CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId); PricePlan pricePlan = customerData.getPricePlan(); List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId); List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan); List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds()); Instant now = clock.instant(); Instant collectionStartedAt = customerData.getCollectionStartedAt(); Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt(); Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt); Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now); Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min( 100, Math.toIntExact( trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis())); return GetStatusResponse.builder() .timestamp(startedAt) .queryTimeMillis(clock.millis() - startedAt) .pricePlan(pricePlan.getName()) .retentionPeriodDays(pricePlan.getRetentionPeriodDays()) .collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()) .maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()) .maxNumberOfMethods(pricePlan.getMaxMethods()) .collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)) .trialPeriodEndsAtMillis( trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()) .trialPeriodExpired(customerData.isTrialPeriodExpired(now)) .trialPeriodPercent(trialPeriodPercent) .numMethods(customerService.countMethods(customerId)) .numAgents(agents.size()) .numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()) .numLiveEnabledAgents( (int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()) .environments(environments) .applications(applications) .agents(agents) .build(); }  }
DashboardServiceImpl implements DashboardService { @Override @Transactional(readOnly = true) public GetStatusResponse getStatus() { long startedAt = clock.millis(); Long customerId = customerIdProvider.getCustomerId(); CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId); PricePlan pricePlan = customerData.getPricePlan(); List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId); List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan); List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds()); Instant now = clock.instant(); Instant collectionStartedAt = customerData.getCollectionStartedAt(); Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt(); Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt); Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now); Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min( 100, Math.toIntExact( trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis())); return GetStatusResponse.builder() .timestamp(startedAt) .queryTimeMillis(clock.millis() - startedAt) .pricePlan(pricePlan.getName()) .retentionPeriodDays(pricePlan.getRetentionPeriodDays()) .collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()) .maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()) .maxNumberOfMethods(pricePlan.getMaxMethods()) .collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)) .trialPeriodEndsAtMillis( trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()) .trialPeriodExpired(customerData.isTrialPeriodExpired(now)) .trialPeriodPercent(trialPeriodPercent) .numMethods(customerService.countMethods(customerId)) .numAgents(agents.size()) .numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()) .numLiveEnabledAgents( (int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()) .environments(environments) .applications(applications) .agents(agents) .build(); }  @Override @Transactional(readOnly = true) GetMethodsResponse2 getMethods2(@Valid GetMethodsRequest request); @Override @Transactional(readOnly = true) Optional<MethodDescriptor1> getMethodById(@NotNull Long methodId); @Override @Transactional(readOnly = true) GetStatusResponse getStatus(); @Override @Transactional(readOnly = true) @NotNull GetMethodsFormData getMethodsFormData(); }
DashboardServiceImpl implements DashboardService { @Override @Transactional(readOnly = true) public GetStatusResponse getStatus() { long startedAt = clock.millis(); Long customerId = customerIdProvider.getCustomerId(); CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId); PricePlan pricePlan = customerData.getPricePlan(); List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId); List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan); List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds()); Instant now = clock.instant(); Instant collectionStartedAt = customerData.getCollectionStartedAt(); Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt(); Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt); Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now); Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min( 100, Math.toIntExact( trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis())); return GetStatusResponse.builder() .timestamp(startedAt) .queryTimeMillis(clock.millis() - startedAt) .pricePlan(pricePlan.getName()) .retentionPeriodDays(pricePlan.getRetentionPeriodDays()) .collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()) .maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()) .maxNumberOfMethods(pricePlan.getMaxMethods()) .collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)) .trialPeriodEndsAtMillis( trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()) .trialPeriodExpired(customerData.isTrialPeriodExpired(now)) .trialPeriodPercent(trialPeriodPercent) .numMethods(customerService.countMethods(customerId)) .numAgents(agents.size()) .numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()) .numLiveEnabledAgents( (int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()) .environments(environments) .applications(applications) .agents(agents) .build(); }  @Override @Transactional(readOnly = true) GetMethodsResponse2 getMethods2(@Valid GetMethodsRequest request); @Override @Transactional(readOnly = true) Optional<MethodDescriptor1> getMethodById(@NotNull Long methodId); @Override @Transactional(readOnly = true) GetStatusResponse getStatus(); @Override @Transactional(readOnly = true) @NotNull GetMethodsFormData getMethodsFormData();  }