mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 18:55:58 +02:00
Use reflection to inject the attempt number
This CL is to address the public static field in RepeatableRunner for caller to get the current attempt number. We tried to have a JUnit TestRule to achieve the purpose but it ended up with having a RuleChain in each class where we already have multiple rules and need to add the retry rule. This is because we have to make sure the retry rule is the last one to wrap the test statement so that the actual retry can include the actions defined in other rules. Having a rule chain is not scalable and confuses engineer so we gave it up. Instead, we decided to expand the current RepeatableRunner to use reflection to inject the attempt number to the test class. Doing it this way can reduce the burden from the caller and it also gets rid of the global state from the previous public static field. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=240789045
This commit is contained in:
parent
308d5eb76b
commit
c8aa6005f2
9 changed files with 132 additions and 45 deletions
|
@ -31,14 +31,16 @@ public class ActualScreenshot {
|
|||
public static final String IMAGE_FORMAT = "png";
|
||||
private String imageKey;
|
||||
private BufferedImage bufferedImage;
|
||||
private int attempt;
|
||||
|
||||
private ActualScreenshot(String imageKey, BufferedImage bufferedImage) {
|
||||
private ActualScreenshot(String imageKey, BufferedImage bufferedImage, int attempt) {
|
||||
this.imageKey = imageKey;
|
||||
this.bufferedImage = bufferedImage;
|
||||
this.attempt = attempt;
|
||||
}
|
||||
|
||||
/** Creates an ActualScreenshot from the given image format and byte array. */
|
||||
public static ActualScreenshot create(String imageKey, byte[] imageBytes) {
|
||||
public static ActualScreenshot create(String imageKey, int attempt, byte[] imageBytes) {
|
||||
checkNotNull(imageKey);
|
||||
checkNotNull(imageBytes);
|
||||
byte[] imageBytesClone = Arrays.copyOf(imageBytes, imageBytes.length);
|
||||
|
@ -47,7 +49,7 @@ public class ActualScreenshot {
|
|||
try {
|
||||
imageReader.setInput(checkNotNull(ImageIO.createImageInputStream(imageInputStream)));
|
||||
BufferedImage bufferedImage = checkNotNull(imageReader.read(0));
|
||||
return new ActualScreenshot(imageKey, bufferedImage);
|
||||
return new ActualScreenshot(imageKey, bufferedImage, attempt);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
|
@ -55,7 +57,7 @@ public class ActualScreenshot {
|
|||
|
||||
/** {@link BufferedImage#getSubimage(int, int, int, int)} */
|
||||
public ActualScreenshot getSubimage(int x, int y, int w, int h) {
|
||||
return new ActualScreenshot(imageKey, bufferedImage.getSubimage(x, y, w, h));
|
||||
return new ActualScreenshot(imageKey, bufferedImage.getSubimage(x, y, w, h), attempt);
|
||||
}
|
||||
|
||||
/** {@link BufferedImage#getWidth()} */
|
||||
|
@ -82,9 +84,9 @@ public class ActualScreenshot {
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns the imageKey of the screenshot. */
|
||||
public String getImageKey() {
|
||||
return imageKey;
|
||||
/** Returns the attempt number of the test. */
|
||||
public int getAttempt() {
|
||||
return attempt;
|
||||
}
|
||||
|
||||
/** Returns the concat of imageKey and imageFormat. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue