1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.tradefed.retry; 17 18 import com.android.tradefed.device.DeviceNotAvailableException; 19 import com.android.tradefed.invoker.IInvocationContext; 20 import com.android.tradefed.result.TestRunResult; 21 import com.android.tradefed.testtype.IRemoteTest; 22 23 import java.util.List; 24 25 /** 26 * Interface driving the retry decision and applying the filter on the class for more targeted 27 * retry. 28 */ 29 public interface IRetryDecision { 30 31 /** Whether or not to enable auto-retry. */ isAutoRetryEnabled()32 public boolean isAutoRetryEnabled(); 33 34 /** The {@link com.android.tradefed.retry.RetryStrategy} used during auto-retry. */ getRetryStrategy()35 public RetryStrategy getRetryStrategy(); 36 37 /** Whether or not to reboot the device before the last attempt. */ rebootAtLastAttempt()38 public boolean rebootAtLastAttempt(); 39 40 /** The maximum number of attempts during auto-retry. */ getMaxRetryCount()41 public int getMaxRetryCount(); 42 43 /** Set the current invocation context. */ setInvocationContext(IInvocationContext context)44 public void setInvocationContext(IInvocationContext context); 45 46 /** 47 * Decide whether or not retry should be attempted. Also make any necessary changes to the 48 * {@link IRemoteTest} to be retried (Applying filters, etc.). 49 * 50 * @param test The {@link IRemoteTest} that just ran. 51 * @param attemptJustExecuted The number of the attempt that we just ran. 52 * @param previousResults The list of {@link TestRunResult} of the test that just ran. 53 * @return True if we should retry, False otherwise. 54 * @throws DeviceNotAvailableException Can be thrown during device recovery 55 */ shouldRetry( IRemoteTest test, int attemptJustExecuted, List<TestRunResult> previousResults)56 public boolean shouldRetry( 57 IRemoteTest test, int attemptJustExecuted, List<TestRunResult> previousResults) 58 throws DeviceNotAvailableException; 59 60 /** 61 * {@link #shouldRetry(IRemoteTest, int, List)} will most likely be called before the last retry 62 * attempt, so we might be missing the very last attempt results for statistics purpose. This 63 * method allows those results to be provided for proper statistics calculations. 64 * 65 * @param lastResults 66 */ addLastAttempt(List<TestRunResult> lastResults)67 public void addLastAttempt(List<TestRunResult> lastResults); 68 69 /** Returns the {@link RetryStatistics} representing the retry. */ getRetryStatistics()70 public RetryStatistics getRetryStatistics(); 71 } 72