Skip to content

Commit

Permalink
HSEARCH-3654 Update Nested tests to work on JDK11
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Oct 17, 2023
1 parent b7c1b33 commit 1471c67
Show file tree
Hide file tree
Showing 22 changed files with 1,185 additions and 680 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,27 @@ class AndPredicateBaseIT {
static void setup() {
setupHelper.start()
.withIndexes(
ScoreIT.index,
AddScoreIT.index
ScoreConfigured.index,
AddScoreConfigured.index
)
.setup();

final BulkIndexer scoreIndexer = ScoreIT.index.bulkIndexer();
ScoreIT.dataSet.contribute( scoreIndexer );
final BulkIndexer scoreIndexer = ScoreConfigured.index.bulkIndexer();
ScoreConfigured.dataSet.contribute( scoreIndexer );

final BulkIndexer addScoreIndexer = AddScoreIT.index.bulkIndexer();
AddScoreIT.dataSet.contribute( addScoreIndexer );
final BulkIndexer addScoreIndexer = AddScoreConfigured.index.bulkIndexer();
AddScoreConfigured.dataSet.contribute( addScoreIndexer );

scoreIndexer.join();
addScoreIndexer.join();
}

@Nested
class ScoreIT extends AbstractPredicateScoreIT {
class ScoreIT extends ScoreConfigured {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class ScoreConfigured extends AbstractPredicateScoreIT {
private static final DataSet dataSet = new DataSet();

private static final StubMappedIndex index = StubMappedIndex.withoutFields().name( "score" );
Expand All @@ -60,29 +64,29 @@ public static List<? extends Arguments> params() {
@Override
protected PredicateFinalStep predicate(SearchPredicateFactory f, int matchingDocOrdinal,
AbstractPredicateDataSet dataSet, StubMappedIndex index) {
return f.and( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) );
return f.and( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) );
}

@Override
protected PredicateFinalStep predicateWithBoost(SearchPredicateFactory f, int matchingDocOrdinal,
float boost, AbstractPredicateDataSet dataSet,
StubMappedIndex index) {
return f.and( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.and( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.boost( boost );
}

@Override
protected PredicateFinalStep predicateWithConstantScore(SearchPredicateFactory f, int matchingDocOrdinal,
AbstractPredicateDataSet dataSet, StubMappedIndex index) {
return f.and( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.and( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.constantScore();
}

@Override
protected PredicateFinalStep predicateWithConstantScoreAndBoost(SearchPredicateFactory f,
int matchingDocOrdinal, float boost, AbstractPredicateDataSet dataSet,
StubMappedIndex index) {
return f.and( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.and( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.constantScore()
.boost( boost );
}
Expand All @@ -101,7 +105,11 @@ public void contribute(BulkIndexer scoreIndexer) {
}

@Nested
class AddScoreIT extends AbstractPredicateScoreIT {
class AddScoreIT extends AddScoreConfigured {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class AddScoreConfigured extends AbstractPredicateScoreIT {
private static final DataSet dataSet = new DataSet();

private static final StubMappedIndex index = StubMappedIndex.withoutFields().name( "addscore" );
Expand All @@ -114,22 +122,22 @@ public static List<? extends Arguments> params() {
protected PredicateFinalStep predicate(SearchPredicateFactory f, int matchingDocOrdinal,
AbstractPredicateDataSet dataSet, StubMappedIndex index) {
return f.and()
.add( f.id().matching( AddScoreIT.dataSet.docId( matchingDocOrdinal ) ) );
.add( f.id().matching( AddScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) );
}

@Override
protected PredicateFinalStep predicateWithBoost(SearchPredicateFactory f, int matchingDocOrdinal,
float boost, AbstractPredicateDataSet dataSet,
StubMappedIndex index) {
return f.and( f.id().matching( AddScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.and( f.id().matching( AddScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.boost( boost );
}

@Override
protected PredicateFinalStep predicateWithConstantScore(SearchPredicateFactory f, int matchingDocOrdinal,
AbstractPredicateDataSet dataSet, StubMappedIndex index) {
return f.and()
.add( f.id().matching( AddScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
.add( f.id().matching( AddScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.constantScore();
}

Expand All @@ -138,7 +146,7 @@ protected PredicateFinalStep predicateWithConstantScoreAndBoost(SearchPredicateF
int matchingDocOrdinal, float boost, AbstractPredicateDataSet dataSet,
StubMappedIndex index) {
return f.and()
.add( f.id().matching( AddScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
.add( f.id().matching( AddScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.constantScore()
.boost( boost );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

//CHECKSTYLE:OFF HideUtilityClassConstructor ignore the rule since it is a class with nested test classes.
// cannot make a private constructor.

class BoolPredicateBaseIT {
//CHECKSTYLE:ON

Expand All @@ -33,18 +32,22 @@ class BoolPredicateBaseIT {
static void setup() {
setupHelper.start()
.withIndexes(
ScoreIT.index
ScoreConfigured.index
)
.setup();

final BulkIndexer scoreIndexer = ScoreIT.index.bulkIndexer();
ScoreIT.dataSet.contribute( scoreIndexer );
final BulkIndexer scoreIndexer = ScoreConfigured.index.bulkIndexer();
ScoreConfigured.dataSet.contribute( scoreIndexer );

scoreIndexer.join();
}

@Nested
class ScoreIT extends AbstractPredicateScoreIT {
class ScoreIT extends ScoreConfigured {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class ScoreConfigured extends AbstractPredicateScoreIT {
private static final DataSet dataSet = new DataSet();

private static final StubMappedIndex index = StubMappedIndex.withoutFields().name( "score" );
Expand All @@ -56,29 +59,29 @@ public static List<? extends Arguments> params() {
@Override
protected PredicateFinalStep predicate(SearchPredicateFactory f, int matchingDocOrdinal,
AbstractPredicateDataSet dataSet, StubMappedIndex index) {
return f.bool().should( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) );
return f.bool().should( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) );
}

@Override
protected PredicateFinalStep predicateWithBoost(SearchPredicateFactory f, int matchingDocOrdinal,
float boost, AbstractPredicateDataSet dataSet,
StubMappedIndex index) {
return f.bool().should( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.bool().should( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.boost( boost );
}

@Override
protected PredicateFinalStep predicateWithConstantScore(SearchPredicateFactory f, int matchingDocOrdinal,
AbstractPredicateDataSet dataSet, StubMappedIndex index) {
return f.bool().should( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.bool().should( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.constantScore();
}

@Override
protected PredicateFinalStep predicateWithConstantScoreAndBoost(SearchPredicateFactory f,
int matchingDocOrdinal, float boost, AbstractPredicateDataSet dataSet,
StubMappedIndex index) {
return f.bool().should( f.id().matching( ScoreIT.dataSet.docId( matchingDocOrdinal ) ) )
return f.bool().should( f.id().matching( ScoreConfigured.dataSet.docId( matchingDocOrdinal ) ) )
.constantScore().boost( boost );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

//CHECKSTYLE:OFF HideUtilityClassConstructor ignore the rule since it is a class with nested test classes.
// cannot make a private constructor.

class ExistsPredicateBaseIT {
//CHECKSTYLE:ON

Expand All @@ -40,44 +39,47 @@ class ExistsPredicateBaseIT {
static void setup() {
setupHelper.start()
.withIndexes(
SingleFieldIT.index,
InObjectFieldIT.mainIndex, InObjectFieldIT.missingFieldIndex,
ScoreIT.index,
InvalidFieldIT.index,
SearchableIT.searchableYesIndex, SearchableIT.searchableNoIndex,
TypeCheckingNoConversionIT.index, TypeCheckingNoConversionIT.compatibleIndex,
TypeCheckingNoConversionIT.rawFieldCompatibleIndex, TypeCheckingNoConversionIT.missingFieldIndex,
TypeCheckingNoConversionIT.incompatibleIndex,
ScaleCheckingIT.index, ScaleCheckingIT.compatibleIndex, ScaleCheckingIT.incompatibleIndex
SingleFieldConfigured.index,
InObjectFieldConfigured.mainIndex, InObjectFieldConfigured.missingFieldIndex,
ScoreConfigured.index,
InvalidFieldConfigured.index,
SearchableConfigured.searchableYesIndex, SearchableConfigured.searchableNoIndex,
TypeCheckingNoConversionConfigured.index, TypeCheckingNoConversionConfigured.compatibleIndex,
TypeCheckingNoConversionConfigured.rawFieldCompatibleIndex,
TypeCheckingNoConversionConfigured.missingFieldIndex,
TypeCheckingNoConversionConfigured.incompatibleIndex,
ScaleCheckingConfigured.index, ScaleCheckingConfigured.compatibleIndex,
ScaleCheckingConfigured.incompatibleIndex
)
.setup();

final BulkIndexer singleFieldIndexer = SingleFieldIT.index.bulkIndexer();
SingleFieldIT.dataSets.forEach( d -> d.contribute( SingleFieldIT.index, singleFieldIndexer ) );
final BulkIndexer singleFieldIndexer = SingleFieldConfigured.index.bulkIndexer();
SingleFieldConfigured.dataSets.forEach( d -> d.contribute( SingleFieldConfigured.index, singleFieldIndexer ) );

final BulkIndexer inObjectFieldMainIndexer = InObjectFieldIT.mainIndex.bulkIndexer();
final BulkIndexer inObjectFieldMissingFieldIndexer = InObjectFieldIT.missingFieldIndex.bulkIndexer();
InObjectFieldIT.dataSets.forEach( d -> d.contribute( InObjectFieldIT.mainIndex, inObjectFieldMainIndexer,
InObjectFieldIT.missingFieldIndex, inObjectFieldMissingFieldIndexer ) );
final BulkIndexer inObjectFieldMainIndexer = InObjectFieldConfigured.mainIndex.bulkIndexer();
final BulkIndexer inObjectFieldMissingFieldIndexer = InObjectFieldConfigured.missingFieldIndex.bulkIndexer();
InObjectFieldConfigured.dataSets
.forEach( d -> d.contribute( InObjectFieldConfigured.mainIndex, inObjectFieldMainIndexer,
InObjectFieldConfigured.missingFieldIndex, inObjectFieldMissingFieldIndexer ) );

final BulkIndexer scoreIndexer = ScoreIT.index.bulkIndexer();
ScoreIT.dataSets.forEach( d -> d.contribute( scoreIndexer ) );
final BulkIndexer scoreIndexer = ScoreConfigured.index.bulkIndexer();
ScoreConfigured.dataSets.forEach( d -> d.contribute( scoreIndexer ) );

final BulkIndexer typeCheckingMainIndexer = TypeCheckingNoConversionIT.index.bulkIndexer();
final BulkIndexer typeCheckingCompatibleIndexer = TypeCheckingNoConversionIT.compatibleIndex.bulkIndexer();
final BulkIndexer typeCheckingMainIndexer = TypeCheckingNoConversionConfigured.index.bulkIndexer();
final BulkIndexer typeCheckingCompatibleIndexer = TypeCheckingNoConversionConfigured.compatibleIndex.bulkIndexer();
final BulkIndexer typeCheckingRawFieldCompatibleIndexer =
TypeCheckingNoConversionIT.rawFieldCompatibleIndex.bulkIndexer();
final BulkIndexer typeCheckingMissingFieldIndexer = TypeCheckingNoConversionIT.missingFieldIndex.bulkIndexer();
TypeCheckingNoConversionIT.dataSets
.forEach( d -> d.contribute( TypeCheckingNoConversionIT.index, typeCheckingMainIndexer,
TypeCheckingNoConversionIT.compatibleIndex, typeCheckingCompatibleIndexer,
TypeCheckingNoConversionIT.rawFieldCompatibleIndex, typeCheckingRawFieldCompatibleIndexer,
TypeCheckingNoConversionIT.missingFieldIndex, typeCheckingMissingFieldIndexer ) );

final BulkIndexer scaleCheckingMainIndexer = ScaleCheckingIT.index.bulkIndexer();
final BulkIndexer scaleCheckingCompatibleIndexer = ScaleCheckingIT.compatibleIndex.bulkIndexer();
ScaleCheckingIT.dataSet.contribute( ScaleCheckingIT.index, scaleCheckingMainIndexer,
ScaleCheckingIT.compatibleIndex, scaleCheckingCompatibleIndexer );
TypeCheckingNoConversionConfigured.rawFieldCompatibleIndex.bulkIndexer();
final BulkIndexer typeCheckingMissingFieldIndexer = TypeCheckingNoConversionConfigured.missingFieldIndex.bulkIndexer();
TypeCheckingNoConversionConfigured.dataSets
.forEach( d -> d.contribute( TypeCheckingNoConversionConfigured.index, typeCheckingMainIndexer,
TypeCheckingNoConversionConfigured.compatibleIndex, typeCheckingCompatibleIndexer,
TypeCheckingNoConversionConfigured.rawFieldCompatibleIndex, typeCheckingRawFieldCompatibleIndexer,
TypeCheckingNoConversionConfigured.missingFieldIndex, typeCheckingMissingFieldIndexer ) );

final BulkIndexer scaleCheckingMainIndexer = ScaleCheckingConfigured.index.bulkIndexer();
final BulkIndexer scaleCheckingCompatibleIndexer = ScaleCheckingConfigured.compatibleIndex.bulkIndexer();
ScaleCheckingConfigured.dataSet.contribute( ScaleCheckingConfigured.index, scaleCheckingMainIndexer,
ScaleCheckingConfigured.compatibleIndex, scaleCheckingCompatibleIndexer );

singleFieldIndexer.join(
inObjectFieldMainIndexer, inObjectFieldMissingFieldIndexer, scoreIndexer,
Expand All @@ -92,7 +94,11 @@ private static <F> ExistsPredicateTestValues<F> testValues(FieldTypeDescriptor<F
}

@Nested
class SingleFieldIT<F> extends AbstractPredicateSingleFieldIT<ExistsPredicateTestValues<F>> {
class SingleFieldIT<F> extends SingleFieldConfigured<F> {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class SingleFieldConfigured<F> extends AbstractPredicateSingleFieldIT<ExistsPredicateTestValues<F>> {

private static final SimpleMappedIndex<IndexBinding> index =
SimpleMappedIndex.of( root -> new IndexBinding( root, supportedFieldTypes ) )
Expand All @@ -119,7 +125,11 @@ protected PredicateFinalStep predicate(SearchPredicateFactory f, String fieldPat
}

@Nested
class ScoreIT<F> extends AbstractPredicateScoreIT {
class ScoreIT<F> extends ScoreConfigured<F> {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class ScoreConfigured<F> extends AbstractPredicateScoreIT {

private static final SimpleMappedIndex<IndexBinding> index = SimpleMappedIndex.of( IndexBinding::new )
.name( "score" );
Expand Down Expand Up @@ -208,7 +218,12 @@ public void contribute(BulkIndexer scoreIndexer) {
}

@Nested
class InObjectFieldIT<F> extends AbstractPredicateFieldInObjectFieldIT<ExistsPredicateTestValues<F>> {
class InObjectFieldIT<F> extends InObjectFieldConfigured<F> {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class InObjectFieldConfigured<F>
extends AbstractPredicateFieldInObjectFieldIT<ExistsPredicateTestValues<F>> {
private static final SimpleMappedIndex<IndexBinding> mainIndex =
SimpleMappedIndex.of( root -> new IndexBinding( root, supportedFieldTypes ) )
.name( "nesting" );
Expand Down Expand Up @@ -242,11 +257,15 @@ protected PredicateFinalStep predicate(SearchPredicateFactory f, String fieldPat
}

@Nested
class InvalidFieldIT extends AbstractPredicateInvalidFieldIT {
class InvalidFieldIT extends InvalidFieldConfigured {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class InvalidFieldConfigured extends AbstractPredicateInvalidFieldIT {
private static final SimpleMappedIndex<IndexBinding> index = SimpleMappedIndex.of( IndexBinding::new )
.name( "invalidField" );

public InvalidFieldIT() {
protected InvalidFieldConfigured() {
super( index );
}

Expand All @@ -272,7 +291,11 @@ protected String predicateNameInErrorMessage() {
}

@Nested
class SearchableIT extends AbstractPredicateSearchableIT {
class SearchableIT extends SearchableConfigured {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class SearchableConfigured extends AbstractPredicateSearchableIT {

private static final SimpleMappedIndex<SearchableYesIndexBinding> searchableYesIndex =
SimpleMappedIndex.of( root -> new SearchableYesIndexBinding( root, supportedFieldTypes ) )
Expand Down Expand Up @@ -313,7 +336,11 @@ protected String predicateNameInErrorMessage() {
}

@Nested
class TypeCheckingNoConversionIT<F>
class TypeCheckingNoConversionIT<F> extends TypeCheckingNoConversionConfigured<F> {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class TypeCheckingNoConversionConfigured<F>
extends AbstractPredicateTypeCheckingNoConversionIT<ExistsPredicateTestValues<F>> {
private static final SimpleMappedIndex<IndexBinding> index =
SimpleMappedIndex.of( root -> new IndexBinding( root, supportedFieldTypes ) )
Expand Down Expand Up @@ -384,7 +411,11 @@ protected String predicateNameInErrorMessage() {
}

@Nested
class ScaleCheckingIT extends AbstractPredicateScaleCheckingIT {
class ScaleCheckingIT extends ScaleCheckingConfigured {
// JDK 11 does not allow static fields in non-static inner class and JUnit does not allow running @Nested tests in static inner classes...
}

abstract static class ScaleCheckingConfigured extends AbstractPredicateScaleCheckingIT {
private static final DataSet dataSet = new DataSet();

private static final SimpleMappedIndex<IndexBinding> index = SimpleMappedIndex.of( IndexBinding::new )
Expand All @@ -395,7 +426,7 @@ class ScaleCheckingIT extends AbstractPredicateScaleCheckingIT {
SimpleMappedIndex.of( IncompatibleIndexBinding::new )
.name( "scaleChecking_incompatible" );

public ScaleCheckingIT() {
public ScaleCheckingConfigured() {
super( index, compatibleIndex, incompatibleIndex, dataSet );
}

Expand Down
Loading

0 comments on commit 1471c67

Please sign in to comment.