2121public class GrpcTransportRule extends ProxyGrpcTransport implements TestRule {
2222 private static final Logger logger = LoggerFactory .getLogger (GrpcTransportRule .class );
2323
24- private final AtomicReference <GrpcTransport > proxy = new AtomicReference <>();
24+ private final AtomicReference <GrpcTransport > proxy ;
25+ private final boolean skipOnUnavailable ;
26+
27+ private GrpcTransportRule (AtomicReference <GrpcTransport > proxy , boolean skipOnUnavailable ) {
28+ this .proxy = proxy ;
29+ this .skipOnUnavailable = skipOnUnavailable ;
30+ }
31+
32+ public GrpcTransportRule () {
33+ this (new AtomicReference <>(), true );
34+ }
35+
36+ public GrpcTransportRule failIfUnavailable () {
37+ return new GrpcTransportRule (proxy , false );
38+ }
2539
2640 @ Override
2741 public Statement apply (Statement base , Description description ) {
@@ -30,17 +44,20 @@ public Statement apply(Statement base, Description description) {
3044 return new Statement () {
3145 @ Override
3246 public void evaluate () throws Throwable {
47+ String path = description .getDisplayName ();
48+ if (description .getMethodName () != null ) {
49+ path += "/" + description .getMethodName ();
50+ }
51+
3352 if (!factory .isEnabled ()) {
34- logger .info ("Test {} skipped because ydb helper is not available" , description .getDisplayName ());
53+ if (!skipOnUnavailable ) {
54+ throw new AssertionError ("Ydb helper is not available " + path );
55+ }
56+ logger .info ("Test {} skipped because ydb helper is not available" , path );
3557 Assume .assumeFalse ("YDB Helper is not available" , true );
3658 return ;
3759 }
3860
39- String path = description .getClassName ();
40- if (description .getMethodName () != null ) {
41- path += "/" + description .getMethodName ();
42- }
43-
4461 logger .debug ("create ydb helper for test {}" , path );
4562 try (YdbHelper helper = factory .createHelper ()) {
4663 try (GrpcTransport transport = helper .createTransport ()) {
0 commit comments