DefaultAppScaleManager implements AppScaleManager { static Optional<AutoScalePolicyException> extractAutoScalePolicyException(Throwable exception) { Throwable e = exception; while (e != null) { if (AutoScalePolicyException.class.isAssignableFrom(e.getClass())) { return Optional.of((AutoScalePolicyException) e); } e = e.getCause(); } return Optional.empty(); } @Inject  DefaultAppScaleManager(AppScalePolicyStore appScalePolicyStore, CloudAlarmClient cloudAlarmClient,
                                  AppAutoScalingClient applicationAutoScalingClient,
                                  V3JobOperations v3JobOperations,
                                  Registry registry,
                                  AppScaleManagerConfiguration appScaleManagerConfiguration,
                                  TitusRuntime titusRuntime); private  DefaultAppScaleManager(AppScalePolicyStore appScalePolicyStore, CloudAlarmClient cloudAlarmClient,
                                   AppAutoScalingClient applicationAutoScalingClient,
                                   V3JobOperations v3JobOperations,
                                   Registry registry,
                                   AppScaleManagerConfiguration appScaleManagerConfiguration,
                                   ExecutorService awsInteractionExecutor,
                                   TitusRuntime titusRuntime); @VisibleForTesting  DefaultAppScaleManager(AppScalePolicyStore appScalePolicyStore, CloudAlarmClient cloudAlarmClient,
                                  AppAutoScalingClient applicationAutoScalingClient,
                                  V3JobOperations v3JobOperations,
                                  Registry registry,
                                  AppScaleManagerConfiguration appScaleManagerConfiguration,
                                  Scheduler awsInteractionScheduler,
                                  TitusRuntime titusRuntime); @Activator Completable enterActiveMode(); @PreDestroy void shutdown(); @Override Observable<String> createAutoScalingPolicy(AutoScalingPolicy autoScalingPolicy); @Override Completable updateAutoScalingPolicy(AutoScalingPolicy autoScalingPolicy); @Override Observable<AutoScalingPolicy> getScalingPoliciesForJob(String jobId); @Override Observable<AutoScalingPolicy> getScalingPolicy(String policyRefId); @Override Observable<AutoScalingPolicy> getAllScalingPolicies(); @Override Completable removeAutoScalingPolicy(String policyRefId); static final long INITIAL_RETRY_DELAY_SEC; static final long MAX_RETRY_DELAY_SEC; }
@Test public void checkNestedExceptionHandling() throws Exception { RuntimeException exceptionContainingUnknownPolicy = new RuntimeException (new RuntimeException( new RuntimeException( new RuntimeException(AutoScalePolicyException.unknownScalingPolicy("policyId", "Not found"))))); Optional<AutoScalePolicyException> autoScalePolicyException = DefaultAppScaleManager.extractAutoScalePolicyException(exceptionContainingUnknownPolicy); AutoScalingPolicyTests.waitForCondition(() -> autoScalePolicyException.isPresent()); Assertions.assertThat(autoScalePolicyException.isPresent()).isTrue(); AutoScalingPolicyTests.waitForCondition(() -> autoScalePolicyException.get().getErrorCode() == AutoScalePolicyException.ErrorCode.UnknownScalingPolicy); Assertions.assertThat(autoScalePolicyException.get().getErrorCode()).isEqualTo(AutoScalePolicyException.ErrorCode.UnknownScalingPolicy); RuntimeException runtimeException = new RuntimeException(new RuntimeException(new Exception("Bad input"))); Optional<AutoScalePolicyException> notAutoScalePolicyException = DefaultAppScaleManager.extractAutoScalePolicyException(runtimeException); AutoScalingPolicyTests.waitForCondition(() -> !notAutoScalePolicyException.isPresent()); Assertions.assertThat(notAutoScalePolicyException.isPresent()).isFalse(); }