Skip to content

Commit

Permalink
HSEARCH-2916 Use a pessimistic lock in performance tests to avoid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere authored and Sanne committed Oct 25, 2017
1 parent eee6dbd commit a0a8f30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -8,6 +8,7 @@

import java.util.Random;

import org.hibernate.LockMode;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.test.performance.model.Book;
import org.hibernate.search.test.performance.scenario.TestScenarioContext;
Expand All @@ -27,7 +28,8 @@ public UpdateBookRatingTask(TestScenarioContext ctx) {
@Override
protected void execute(FullTextSession fts) {
long bookId = ctx.getRandomBookId();
Book book = (Book) fts.get( Book.class, bookId );
// See HSEARCH-2916, we often had concurrent write errors here
Book book = (Book) fts.get( Book.class, bookId, LockMode.PESSIMISTIC_WRITE );
if ( book != null ) {
book.setRating( Math.abs( RANDOM_RATING.nextFloat() ) * MAX_RATING );
}
Expand Down
Expand Up @@ -6,6 +6,7 @@
*/
package org.hibernate.search.test.performance.task;

import org.hibernate.LockMode;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.test.performance.model.Book;
import org.hibernate.search.test.performance.scenario.TestScenarioContext;
Expand All @@ -22,7 +23,8 @@ public UpdateBookTotalSoldTask(TestScenarioContext ctx) {
@Override
protected void execute(FullTextSession fts) {
long bookId = ctx.getRandomBookId();
Book book = (Book) fts.get( Book.class, bookId );
// See HSEARCH-2916, we often had concurrent write errors here
Book book = (Book) fts.get( Book.class, bookId, LockMode.PESSIMISTIC_WRITE );
if ( book != null ) {
book.setTotalSold( book.getTotalSold() + 1 );
}
Expand Down

0 comments on commit a0a8f30

Please sign in to comment.