@@ -362,6 +362,57 @@ static Map<String, StreamMetadata> metadata(Broker leader, List<Broker> replicas
362
362
return metadata ("stream" , leader , replicas );
363
363
}
364
364
365
+ private static String currentVersion (String currentVersion ) {
366
+ // versions built from source: 3.7.0+rc.1.4.gedc5d96
367
+ if (currentVersion .contains ("+" )) {
368
+ currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("+" ));
369
+ }
370
+ // alpha (snapshot) versions: 3.7.0~alpha.449-1
371
+ if (currentVersion .contains ("~" )) {
372
+ currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("~" ));
373
+ }
374
+ // alpha (snapshot) versions: 3.7.1-alpha.40
375
+ if (currentVersion .contains ("-" )) {
376
+ currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("-" ));
377
+ }
378
+ return currentVersion ;
379
+ }
380
+
381
+ static boolean atLeastVersion (String expectedVersion , String currentVersion ) {
382
+ if (currentVersion .contains ("alpha-stream" )) {
383
+ return true ;
384
+ }
385
+ try {
386
+ currentVersion = currentVersion (currentVersion );
387
+ return "0.0.0" .equals (currentVersion ) || versionCompare (currentVersion , expectedVersion ) >= 0 ;
388
+ } catch (RuntimeException e ) {
389
+ LoggerFactory .getLogger (TestUtils .class )
390
+ .warn ("Unable to parse broker version {}" , currentVersion , e );
391
+ throw e ;
392
+ }
393
+ }
394
+
395
+ /**
396
+ * https://stackoverflow.com/questions/6701948/efficient-way-to-compare-version-strings-in-java
397
+ */
398
+ static int versionCompare (String str1 , String str2 ) {
399
+ String [] vals1 = str1 .split ("\\ ." );
400
+ String [] vals2 = str2 .split ("\\ ." );
401
+ int i = 0 ;
402
+ // set index to first non-equal ordinal or length of shortest version string
403
+ while (i < vals1 .length && i < vals2 .length && vals1 [i ].equals (vals2 [i ])) {
404
+ i ++;
405
+ }
406
+ // compare first non-equal ordinal number
407
+ if (i < vals1 .length && i < vals2 .length ) {
408
+ int diff = Integer .valueOf (vals1 [i ]).compareTo (Integer .valueOf (vals2 [i ]));
409
+ return Integer .signum (diff );
410
+ }
411
+ // the strings are equal or one string is a substring of the other
412
+ // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
413
+ return Integer .signum (vals1 .length - vals2 .length );
414
+ }
415
+
365
416
@ Target ({ElementType .TYPE , ElementType .METHOD })
366
417
@ Retention (RetentionPolicy .RUNTIME )
367
418
@ Documented
@@ -420,6 +471,31 @@ interface RunnableWithException {
420
471
void run () throws Exception ;
421
472
}
422
473
474
+ static class CountDownLatchConditions {
475
+
476
+ static Condition <CountDownLatch > completed () {
477
+ return completed (Duration .ofSeconds (10 ));
478
+ }
479
+
480
+ static Condition <CountDownLatch > completed (int timeoutInSeconds ) {
481
+ return completed (Duration .ofSeconds (timeoutInSeconds ));
482
+ }
483
+
484
+ static Condition <CountDownLatch > completed (Duration timeout ) {
485
+ return new Condition <>(
486
+ latch -> {
487
+ try {
488
+ return latch .await (timeout .toMillis (), TimeUnit .MILLISECONDS );
489
+ } catch (InterruptedException e ) {
490
+ Thread .interrupted ();
491
+ throw new RuntimeException (e );
492
+ }
493
+ },
494
+ "completed in %d ms" ,
495
+ timeout .toMillis ());
496
+ }
497
+ }
498
+
423
499
public static class StreamTestInfrastructureExtension
424
500
implements BeforeAllCallback , AfterAllCallback , BeforeEachCallback , AfterEachCallback {
425
501
@@ -641,57 +717,6 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
641
717
}
642
718
}
643
719
644
- private static String currentVersion (String currentVersion ) {
645
- // versions built from source: 3.7.0+rc.1.4.gedc5d96
646
- if (currentVersion .contains ("+" )) {
647
- currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("+" ));
648
- }
649
- // alpha (snapshot) versions: 3.7.0~alpha.449-1
650
- if (currentVersion .contains ("~" )) {
651
- currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("~" ));
652
- }
653
- // alpha (snapshot) versions: 3.7.1-alpha.40
654
- if (currentVersion .contains ("-" )) {
655
- currentVersion = currentVersion .substring (0 , currentVersion .indexOf ("-" ));
656
- }
657
- return currentVersion ;
658
- }
659
-
660
- static boolean atLeastVersion (String expectedVersion , String currentVersion ) {
661
- if (currentVersion .contains ("alpha-stream" )) {
662
- return true ;
663
- }
664
- try {
665
- currentVersion = currentVersion (currentVersion );
666
- return "0.0.0" .equals (currentVersion ) || versionCompare (currentVersion , expectedVersion ) >= 0 ;
667
- } catch (RuntimeException e ) {
668
- LoggerFactory .getLogger (TestUtils .class )
669
- .warn ("Unable to parse broker version {}" , currentVersion , e );
670
- throw e ;
671
- }
672
- }
673
-
674
- /**
675
- * https://stackoverflow.com/questions/6701948/efficient-way-to-compare-version-strings-in-java
676
- */
677
- static int versionCompare (String str1 , String str2 ) {
678
- String [] vals1 = str1 .split ("\\ ." );
679
- String [] vals2 = str2 .split ("\\ ." );
680
- int i = 0 ;
681
- // set index to first non-equal ordinal or length of shortest version string
682
- while (i < vals1 .length && i < vals2 .length && vals1 [i ].equals (vals2 [i ])) {
683
- i ++;
684
- }
685
- // compare first non-equal ordinal number
686
- if (i < vals1 .length && i < vals2 .length ) {
687
- int diff = Integer .valueOf (vals1 [i ]).compareTo (Integer .valueOf (vals2 [i ]));
688
- return Integer .signum (diff );
689
- }
690
- // the strings are equal or one string is a substring of the other
691
- // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
692
- return Integer .signum (vals1 .length - vals2 .length );
693
- }
694
-
695
720
static class CountDownLatchAssert implements AssertDelegateTarget {
696
721
697
722
private static final Duration TIMEOUT = Duration .ofSeconds (10 );
0 commit comments