Skip to content

Commit

Permalink
HSEARCH-1270 Test outer transaction flush nested flush and rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Aug 22, 2019
1 parent 6d458c3 commit 4fa2752
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Expand Up @@ -56,4 +56,22 @@ public void innerTransactionRollback() {
// Check that inner transaction data has NOT been pushed to the index:
assertFalse( innerBook.isPresent() );
}

@Test
@TestForIssue( jiraKey = "HSEARCH-1270" )
public void innerTransactionRollback_flushBeforeInner() {
String outerIsbn = "0-4206-9749-7";
String innerIsbn = "0-1111-9749-7";

innerTransactionRollbackService.doOuterFlushBeforeInner( outerIsbn, innerIsbn );

Optional<Book> outerBook = documentService.getByIsbn( outerIsbn );
Optional<Book> innerBook = documentService.getByIsbn( innerIsbn );

// Check that outer transaction data has been pushed to the index:
assertTrue( outerBook.isPresent() );

// Check that inner transaction data has NOT been pushed to the index:
assertFalse( innerBook.isPresent() );
}
}
Expand Up @@ -64,6 +64,23 @@ public void doOuter(String outerIsbn, String nestedIsbn) {
entityManager.flush();
}

public void doOuterFlushBeforeInner(String outerIsbn, String nestedIsbn) {
// This data is supposed to be pushed to the index:
Book book = new Book( 739, outerIsbn, "The Late Mattia Pascal", "Luigi Pirandello", "Describes the human life conditions...", "misfortune" );
entityManager.persist( book );

// flush before the execution of the inner transaction
entityManager.flush();

try {
self.doInner( nestedIsbn );
}
catch (MakeRollbackException e) {
// Do not rollback the outer transaction
}
entityManager.flush();
}

private static class MakeRollbackException extends RuntimeException {
public MakeRollbackException(String message) {
super( message );
Expand Down

0 comments on commit 4fa2752

Please sign in to comment.