Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.cloud.storage.it.runner.annotations.Backend;
import com.google.cloud.storage.it.runner.annotations.CrossRun;
import com.google.cloud.storage.it.runner.annotations.CrossRun.AllowClassRule;
import com.google.cloud.storage.it.runner.annotations.ParallelFriendly;
import com.google.cloud.storage.it.runner.annotations.Parameterized;
import com.google.cloud.storage.it.runner.annotations.Parameterized.Parameter;
Expand All @@ -31,6 +32,7 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import java.util.stream.Stream;
import org.junit.ClassRule;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
Expand Down Expand Up @@ -136,9 +138,13 @@ private static List<Runner> computeRunners(Class<?> klass, Registry registry)
}

if (crossRun != null) {
// TODO
// add warning message if @ClassRule or @BeforeClass/AfterClass are used, as these will run
// multiple times due to the class being run for each crossRun result.
List<FrameworkField> classRules = testClass.getAnnotatedFields(ClassRule.class);
AllowClassRule allowClassRule = testClass.getAnnotation(AllowClassRule.class);
if (allowClassRule == null && !classRules.isEmpty()) {
String msg =
"@CrossRun used along with @ClassRule. This can be dangerous, multiple class scopes will be created for cross running, possibly breaking expectations on rule scope. If the use of a @ClassRule is still desirable, please annotate your class with @CrossRun.AllowClassRule";
throw new InitializationError(msg);
}
return SneakyException.unwrap(
() ->
ImmutableSet.copyOf(crossRun.backends()).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,18 @@

TransportCompatibility.Transport[] transports() default {};
}

/**
* When using {@link CrossRun} a class scope will be created for each permutation, this can break
* expectations of scope/lifecycle for {@link org.junit.ClassRule}s. In an abundance of caution,
* we consider the use of a {@link org.junit.ClassRule} along with {@link CrossRun} an invalid
* class definition.
*
* <p>In order to allow the use of a {@link org.junit.ClassRule} along with the caveats mentioned
* above, a class can be annotated with {@link AllowClassRule} to suppress the error and proceed
* running the test class with the rule.
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface AllowClassRule {}
}