details: https://code.openbravo.com/erp/devel/pi/rev/9b27c5a81726 changeset: 35236:9b27c5a81726 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Thu Dec 13 12:35:23 2018 +0100 summary: related with issue 39755: fail if timeout is reached + raname function
diffstat: src-test/src/org/openbravo/test/dal/DalLockingTest.java | 30 +++++++++------- 1 files changed, 16 insertions(+), 14 deletions(-) diffs (85 lines): diff -r 2df0dc2f8b08 -r 9b27c5a81726 src-test/src/org/openbravo/test/dal/DalLockingTest.java --- a/src-test/src/org/openbravo/test/dal/DalLockingTest.java Thu Dec 13 12:07:51 2018 +0100 +++ b/src-test/src/org/openbravo/test/dal/DalLockingTest.java Thu Dec 13 12:35:23 2018 +0100 @@ -35,6 +35,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -103,9 +104,9 @@ @Test public void objectShouldBeLockedInDB() throws InterruptedException, ExecutionException { CountDownLatch latch = new CountDownLatch(1); - List<Callable<Void>> threads = Arrays.asList( - getDalCallable(() -> acquireLock(latch), "T1", 200), // - getDalCallable(this::acquireLock, "T2", latch)); + List<Callable<Void>> threads = Arrays.asList( // + doWithDAL(() -> acquireLock(latch), "T1", 200), // + doWithDAL(this::acquireLock, "T2", latch)); executeAndGetResults(threads); assertThat( @@ -118,8 +119,8 @@ ExecutionException { CountDownLatch latch = new CountDownLatch(1); List<Callable<Void>> threads = Arrays.asList( // - getDalCallable(() -> acquireLock(latch), "T1", 200), // - getDalCallable(() -> { + doWithDAL(() -> acquireLock(latch), "T1", 200), // + doWithDAL(() -> { AlertRecipient recipient = OBProvider.getInstance().get(AlertRecipient.class); recipient.setRole(OBContext.getOBContext().getRole()); recipient.setAlertRule(getTestingAlertRule()); @@ -139,14 +140,14 @@ CountDownLatch gotRule = new CountDownLatch(1); CountDownLatch ruleModified = new CountDownLatch(1); List<Callable<Void>> threads = Arrays.asList( // - getDalCallable(() -> { + doWithDAL(() -> { AlertRule ar = getTestingAlertRule(); originalName.append(ar.getName()); gotRule.countDown(); waitUnitl(ruleModified); lockedName.append(OBDal.getInstance().getObjectLockForNoKeyUpdate(ar).getName()); }, "T1", 0), // - getDalCallable(() -> { + doWithDAL(() -> { getTestingAlertRule().setName("Modified"); OBDal.getInstance().commitAndClose(); ruleModified.countDown(); @@ -178,16 +179,15 @@ } } - private Callable<Void> getDalCallable(Runnable r, String name, CountDownLatch waitFor) { - return getDalCallable(r, name, waitFor, 0); + private Callable<Void> doWithDAL(Runnable r, String name, CountDownLatch waitFor) { + return doWithDAL(r, name, waitFor, 0); } - private Callable<Void> getDalCallable(Runnable r, String name, long waitAfter) { - return getDalCallable(r, name, null, waitAfter); + private Callable<Void> doWithDAL(Runnable r, String name, long waitAfter) { + return doWithDAL(r, name, null, waitAfter); } - private Callable<Void> getDalCallable(Runnable r, String name, CountDownLatch waitEvent, - long waitAfter) { + private Callable<Void> doWithDAL(Runnable r, String name, CountDownLatch waitEvent, long waitAfter) { return () -> { boolean errorOccurred = false; try { @@ -245,7 +245,9 @@ return; } try { - event.await(10L, TimeUnit.SECONDS); + if (!event.await(10L, TimeUnit.SECONDS)) { + throw new OBException(new TimeoutException()); + } } catch (InterruptedException e) { throw new OBException(e); } _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits