2828import java .util .Iterator ;
2929import java .util .List ;
3030import java .util .Map ;
31+ import java .util .Objects ;
3132import java .util .Set ;
3233import java .util .concurrent .Callable ;
3334import java .util .concurrent .CompletableFuture ;
@@ -354,7 +355,7 @@ else if (child.getExecutionMode() == SAME_THREAD) {
354355 sameThreadTasks .add (child );
355356 }
356357 else {
357- queueEntries .add (workQueue . createEntry (child , index ++));
358+ queueEntries .add (new WorkQueue . Entry (child , index ++));
358359 }
359360 }
360361
@@ -656,16 +657,11 @@ private static class WorkQueue implements Iterable<WorkQueue.Entry> {
656657 private final Set <Entry > queue = new ConcurrentSkipListSet <>();
657658
658659 Entry add (TestTask task , int index ) {
659- Entry entry = createEntry (task , index );
660+ Entry entry = new Entry (task , index );
660661 LOGGER .trace (() -> "forking: " + entry .task );
661662 return doAdd (entry );
662663 }
663664
664- Entry createEntry (TestTask task , int index ) {
665- var uniqueId = task .getTestDescriptor ().getUniqueId ();
666- return new Entry (uniqueId , task , new CompletableFuture <>(), index );
667- }
668-
669665 void addAll (Collection <Entry > entries ) {
670666 entries .forEach (this ::doAdd );
671667 }
@@ -696,19 +692,25 @@ public Iterator<Entry> iterator() {
696692 return queue .iterator ();
697693 }
698694
699- private record Entry (UniqueId id , TestTask task , CompletableFuture <@ Nullable Void > future , int index )
700- implements Comparable <Entry > {
695+ private static final class Entry implements Comparable <Entry > {
696+
697+ private final TestTask task ;
698+ private final CompletableFuture <@ Nullable Void > future ;
699+ private final int index ;
701700
702701 @ SuppressWarnings ("FutureReturnValueIgnored" )
703- Entry {
704- future .whenComplete ((__ , t ) -> {
702+ Entry (TestTask task , int index ) {
703+ this .future = new CompletableFuture <>();
704+ this .future .whenComplete ((__ , t ) -> {
705705 if (t == null ) {
706- LOGGER .trace (() -> "completed normally: " + this . task () );
706+ LOGGER .trace (() -> "completed normally: " + task );
707707 }
708708 else {
709- LOGGER .trace (t , () -> "completed exceptionally: " + this . task () );
709+ LOGGER .trace (t , () -> "completed exceptionally: " + task );
710710 }
711711 });
712+ this .task = task ;
713+ this .index = index ;
712714 }
713715
714716 @ Override
@@ -721,11 +723,11 @@ public int compareTo(Entry that) {
721723 if (result != 0 ) {
722724 return result ;
723725 }
724- result = Integer .compare (that .index (), this . index () );
726+ result = Integer .compare (that .index , index );
725727 if (result != 0 ) {
726728 return result ;
727729 }
728- return compareBy (that .id (), this .id ());
730+ return compareBy (that .uniqueId (), this .uniqueId ());
729731 }
730732
731733 private int compareBy (UniqueId a , UniqueId b ) {
@@ -753,13 +755,46 @@ private int compareBy(UniqueId.Segment a, UniqueId.Segment b) {
753755 }
754756
755757 private int getLevel () {
756- return this . id .getSegments ().size ();
758+ return uniqueId () .getSegments ().size ();
757759 }
758760
759761 private boolean isContainer () {
760762 return task .getTestDescriptor ().isContainer ();
761763 }
762764
765+ private UniqueId uniqueId () {
766+ return task .getTestDescriptor ().getUniqueId ();
767+ }
768+
769+ CompletableFuture <@ Nullable Void > future () {
770+ return future ;
771+ }
772+
773+ @ Override
774+ public boolean equals (Object obj ) {
775+ if (obj == this ) {
776+ return true ;
777+ }
778+ if (obj == null || obj .getClass () != this .getClass ()) {
779+ return false ;
780+ }
781+ var that = (Entry ) obj ;
782+ return Objects .equals (this .uniqueId (), that .uniqueId ()) && this .index == that .index ;
783+ }
784+
785+ @ Override
786+ public int hashCode () {
787+ return Objects .hash (uniqueId (), index );
788+ }
789+
790+ @ Override
791+ public String toString () {
792+ return new ToStringBuilder (this ) //
793+ .append ("task" , task ) //
794+ .append ("index" , index ) //
795+ .toString ();
796+ }
797+
763798 }
764799 }
765800
0 commit comments