@Test public void test_that_calculateLifetime_uses_supplied_lifetime_if_start_and_end_time_not_provided() { long lifetimeInMinutes = 5L; Instant now = Instant.now(); Instant later = null; CanaryAnalysisExecutionRequest request = CanaryAnalysisExecutionRequest.builder().lifetimeDurationMins(5L).build(); Duration actual = stage.calculateLifetime(now, later, request); Duration expected = Duration.ofMinutes(lifetimeInMinutes); assertEquals("The duration should be 5 minutes", expected, actual); }
protected Duration calculateLifetime( Instant start, Instant endTime, CanaryAnalysisExecutionRequest canaryAnalysisExecutionRequest) { Duration lifetime; if (endTime != null) { lifetime = Duration.ofMinutes(start.until(endTime, MINUTES)); } else if (canaryAnalysisExecutionRequest.getLifetimeDuration() != null) { lifetime = canaryAnalysisExecutionRequest.getLifetimeDuration(); } else { throw new IllegalArgumentException( "Canary StageExecution configuration must include either `endTime` or `lifetimeDuration`."); } return lifetime; }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected Duration calculateLifetime( Instant start, Instant endTime, CanaryAnalysisExecutionRequest canaryAnalysisExecutionRequest) { Duration lifetime; if (endTime != null) { lifetime = Duration.ofMinutes(start.until(endTime, MINUTES)); } else if (canaryAnalysisExecutionRequest.getLifetimeDuration() != null) { lifetime = canaryAnalysisExecutionRequest.getLifetimeDuration(); } else { throw new IllegalArgumentException( "Canary StageExecution configuration must include either `endTime` or `lifetimeDuration`."); } return lifetime; } }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected Duration calculateLifetime( Instant start, Instant endTime, CanaryAnalysisExecutionRequest canaryAnalysisExecutionRequest) { Duration lifetime; if (endTime != null) { lifetime = Duration.ofMinutes(start.until(endTime, MINUTES)); } else if (canaryAnalysisExecutionRequest.getLifetimeDuration() != null) { lifetime = canaryAnalysisExecutionRequest.getLifetimeDuration(); } else { throw new IllegalArgumentException( "Canary StageExecution configuration must include either `endTime` or `lifetimeDuration`."); } return lifetime; } @Autowired  SetupAndExecuteCanariesStage(Clock clock, ObjectMapper kayentaObjectMapper); }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected Duration calculateLifetime( Instant start, Instant endTime, CanaryAnalysisExecutionRequest canaryAnalysisExecutionRequest) { Duration lifetime; if (endTime != null) { lifetime = Duration.ofMinutes(start.until(endTime, MINUTES)); } else if (canaryAnalysisExecutionRequest.getLifetimeDuration() != null) { lifetime = canaryAnalysisExecutionRequest.getLifetimeDuration(); } else { throw new IllegalArgumentException( "Canary StageExecution configuration must include either `endTime` or `lifetimeDuration`."); } return lifetime; } @Autowired  SetupAndExecuteCanariesStage(Clock clock, ObjectMapper kayentaObjectMapper); @Override void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder builder); @Override void beforeStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void onFailureStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void afterStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Nonnull @Override String getType(); }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected Duration calculateLifetime( Instant start, Instant endTime, CanaryAnalysisExecutionRequest canaryAnalysisExecutionRequest) { Duration lifetime; if (endTime != null) { lifetime = Duration.ofMinutes(start.until(endTime, MINUTES)); } else if (canaryAnalysisExecutionRequest.getLifetimeDuration() != null) { lifetime = canaryAnalysisExecutionRequest.getLifetimeDuration(); } else { throw new IllegalArgumentException( "Canary StageExecution configuration must include either `endTime` or `lifetimeDuration`."); } return lifetime; } @Autowired  SetupAndExecuteCanariesStage(Clock clock, ObjectMapper kayentaObjectMapper); @Override void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder builder); @Override void beforeStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void onFailureStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void afterStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Nonnull @Override String getType(); static final String STAGE_TYPE; static final String STAGE_DESCRIPTION; }