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.result.ILogSaver;
19 import com.android.tradefed.result.ITestInvocationListener;
20 import com.android.tradefed.result.LogSaverResultForwarder;
21 
22 import java.util.List;
23 
24 /** Forwarder that also handles passing the current attempt we are at. */
25 public class RetryLogSaverResultForwarder extends LogSaverResultForwarder {
26 
27     private int mAttemptNumber = 0;
28 
RetryLogSaverResultForwarder( ILogSaver logSaver, List<ITestInvocationListener> listeners)29     public RetryLogSaverResultForwarder(
30             ILogSaver logSaver, List<ITestInvocationListener> listeners) {
31         super(logSaver, listeners);
32     }
33 
34     @Override
testRunStarted(String runName, int testCount)35     public void testRunStarted(String runName, int testCount) {
36         super.testRunStarted(runName, testCount, mAttemptNumber);
37     }
38 
39     @Override
testRunStarted(String runName, int testCount, int attemptNumber)40     public void testRunStarted(String runName, int testCount, int attemptNumber) {
41         // We enforce our attempt number
42         super.testRunStarted(runName, testCount, mAttemptNumber);
43     }
44 
45     @Override
testRunStarted(String runName, int testCount, int attemptNumber, long startTime)46     public void testRunStarted(String runName, int testCount, int attemptNumber, long startTime) {
47         // We enforce our attempt number
48         super.testRunStarted(runName, testCount, mAttemptNumber, startTime);
49     }
50 
51     /** Increment the attempt number. */
incrementAttempt()52     public void incrementAttempt() {
53         mAttemptNumber++;
54     }
55 }
56