@BeforeClass(groups = "slow") public void beforeClass() throws Exception { if (hasFailed()) { return; } final Injector g = Guice.createInjector(Stage.PRODUCTION, new TestUtilModuleWithEmbeddedDB(configSource, clock)); g.injectMembers(this); Assert.assertTrue(locker.isFree("a", "b")); }
@Test(groups = "slow") public void testSimpleLocking() throws IOException, LockFailedException { final String lockName = UUID.randomUUID().toString(); final GlobalLock lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 3); dbi.inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(final Handle conn, final TransactionStatus status) throws Exception { conn.execute("insert into dummy2 (dummy_id) values ('" + UUID.randomUUID().toString() + "')"); return null; } }); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), false); boolean gotException = false; try { locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 1); } catch (LockFailedException e) { gotException = true; } Assert.assertTrue(gotException); lock.release(); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), true); } }
@BeforeClass(groups = "slow") public void beforeClass() throws Exception { if (hasFailed()) { return; } final Injector g = Guice.createInjector(Stage.PRODUCTION, new TestUtilModuleWithEmbeddedDB(configSource, clock)); g.injectMembers(this); Assert.assertTrue(locker.isFree("a", "b")); }
@Test(groups = "slow") public void testSimpleLocking() throws IOException, LockFailedException { final String lockName = UUID.randomUUID().toString(); final GlobalLock lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 3); dbi.inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(final Handle conn, final TransactionStatus status) throws Exception { conn.execute("insert into dummy2 (dummy_id) values ('" + UUID.randomUUID().toString() + "')"); return null; } }); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), false); boolean gotException = false; try { locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 1); } catch (LockFailedException e) { gotException = true; } Assert.assertTrue(gotException); lock.release(); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), true); } }