Skip to content

Commit

Permalink
HSEARCH-4565 Add more tests for @IndexedEmbedded cycles
Browse files Browse the repository at this point in the history
Not directly related to this ticket, but that's just to be safe.
  • Loading branch information
yrodiere committed Jun 21, 2022
1 parent d080081 commit 71bdd6a
Showing 1 changed file with 63 additions and 0 deletions.
Expand Up @@ -1548,6 +1548,69 @@ class IndexedEntity {
+ " (@GenericField, @FullTextField, custom bridges, ...) is defined for that type." ) );
}

@Test
public void cycle() {
class Model {
@Indexed(index = INDEX_NAME)
class EntityA {
@DocumentId
Integer id;
@IndexedEmbedded
EntityB b;
}
class EntityB {
Integer id;
@IndexedEmbedded
EntityA a;
}
}

assertThatThrownBy( () -> setupHelper.start()
.withAnnotatedEntityTypes( Model.EntityA.class )
.setup() )
.isInstanceOf( SearchException.class )
.satisfies( FailureReportUtils.hasFailureReport()
.typeContext( Model.EntityA.class.getName() )
.pathContext( ".b<no value extractors>.a<no value extractors>.b" )
.failure( "Infinite @IndexedEmbedded recursion involving path 'b.a.b.' on type '"
+ Model.EntityA.class.getName() + "'" )
);
}

@Test
public void cycle_nonRoot() {
class Model {
@Indexed(index = INDEX_NAME)
class EntityA {
@DocumentId
Integer id;
@IndexedEmbedded
EntityB b;
}
class EntityB {
Integer id;
@IndexedEmbedded
EntityC c;
}
class EntityC {
Integer id;
@IndexedEmbedded
EntityB b;
}
}

assertThatThrownBy( () -> setupHelper.start()
.withAnnotatedEntityTypes( Model.EntityA.class )
.setup() )
.isInstanceOf( SearchException.class )
.satisfies( FailureReportUtils.hasFailureReport()
.typeContext( Model.EntityA.class.getName() )
.pathContext( ".b<no value extractors>.c<no value extractors>.b<no value extractors>.c" )
.failure( "Infinite @IndexedEmbedded recursion involving path 'c.b.c.' on type '"
+ Model.EntityB.class.getName() + "'" )
);
}

private <E> void doTestEmbeddedRuntime(SearchMapping mapping,
Function<Integer, E> newEntityFunction,
Consumer<StubDocumentNode.Builder> expectedDocumentContributor) {
Expand Down

0 comments on commit 71bdd6a

Please sign in to comment.