@Test public void approve() throws Exception { StateRecord r1 = ledger.findOrCreate(HashId.createRandom()); assertFalse(r1.isApproved()); r1.approve(); assertEquals(ItemState.APPROVED, r1.getState()); assert (r1.isApproved()); r1.reload(); assert (r1.isApproved()); assertThrows(IllegalStateException.class, () -> { r1.approve(); return null; }); }
@Test public void approve() throws Exception { StateRecord r1 = ledger.findOrCreate(HashId.createRandom()); assertFalse(r1.isApproved()); r1.approve(); assertEquals(ItemState.APPROVED, r1.getState()); assert (r1.isApproved()); r1.reload(); assert (r1.isApproved()); assertThrows(IllegalStateException.class, () -> { r1.approve(); return null; }); }
@Test public void checkLockOwner() throws Exception { ledger.enableCache(true); StateRecord existing = ledger.findOrCreate(HashId.createRandom()); existing.approve(); StateRecord r = ledger.findOrCreate(HashId.createRandom()); StateRecord r1 = r.lockToRevoke(existing.getId()); existing.reload(); r.reload(); assertSameRecords(existing, r1); assertEquals(ItemState.LOCKED, existing.getState()); assertEquals(r.getRecordId(), existing.getLockedByRecordId()); StateRecord currentOwner = ledger.getLockOwnerOf(existing); System.out.println("existing: " + existing.getId()); System.out.println("locker: " + r.getId()); System.out.println("locked: " + r1.getId()); System.out.println("currentOwner: " + currentOwner.getId()); assertSameRecords(r, currentOwner); }
@Test public void lockForRevoking() throws Exception { ledger.enableCache(true); StateRecord existing = ledger.findOrCreate(HashId.createRandom()); existing.approve(); StateRecord existing2 = ledger.findOrCreate(HashId.createRandom()); existing2.approve(); StateRecord r = ledger.findOrCreate(HashId.createRandom()); StateRecord r1 = r.lockToRevoke(existing.getId()); existing.reload(); r.reload(); assertSameRecords(existing, r1); assertEquals(ItemState.LOCKED, existing.getState()); assertEquals(r.getRecordId(), existing.getLockedByRecordId()); StateRecord r2 = r.lockToRevoke(existing.getId()); existing.reload(); r.reload(); assertSameRecords(existing, r1); assertSameRecords(existing, r2); assertSame(r1, r2); assertEquals(ItemState.LOCKED, existing.getState()); assertEquals(r.getRecordId(), existing.getLockedByRecordId()); StateRecord r3 = r.lockToRevoke(existing2.getId()); existing2.reload(); assertSameRecords(existing2, r3); assertEquals(ItemState.LOCKED, existing2.getState()); assertEquals(r.getRecordId(), existing2.getLockedByRecordId()); }
@Test public void revoke() throws Exception { StateRecord r1 = ledger.findOrCreate(HashId.createRandom()); assertFalse(r1.isApproved()); assertTrue(r1.isPending()); assertFalse(r1.isArchived()); r1.approve(); r1.reload(); assertTrue(r1.isApproved()); assertFalse(r1.isPending()); assertFalse(r1.isArchived()); r1.setState(ItemState.LOCKED); r1.revoke(); assertFalse(r1.isPending()); assertFalse(r1.isApproved()); assertTrue(r1.isArchived()); }
@Test public void revoke() throws Exception { StateRecord r1 = ledger.findOrCreate(HashId.createRandom()); assertFalse(r1.isApproved()); assertTrue(r1.isPending()); assertFalse(r1.isArchived()); r1.approve(); r1.reload(); assertTrue(r1.isApproved()); assertFalse(r1.isPending()); assertFalse(r1.isArchived()); r1.setState(ItemState.LOCKED); r1.revoke(); assertFalse(r1.isPending()); assertFalse(r1.isApproved()); assertTrue(r1.isArchived()); }
@Test public void lockForRevoking() throws Exception { ledger.enableCache(true); StateRecord existing = ledger.findOrCreate(HashId.createRandom()); existing.approve(); StateRecord existing2 = ledger.findOrCreate(HashId.createRandom()); existing2.approve(); StateRecord r = ledger.findOrCreate(HashId.createRandom()); StateRecord r1 = r.lockToRevoke(existing.getId()); existing.reload(); r.reload(); assertSameRecords(existing, r1); assertEquals(ItemState.LOCKED, existing.getState()); assertEquals(r.getRecordId(), existing.getLockedByRecordId()); // we lock again the same record, everything should be still ok: StateRecord r2 = r.lockToRevoke(existing.getId()); assertNotNull(r2); existing.reload(); r.reload(); assertSameRecords(existing, r1); assertSameRecords(existing, r2); assertSame(r1, r2); assertEquals(ItemState.LOCKED, existing.getState()); assertEquals(r.getRecordId(), existing.getLockedByRecordId()); StateRecord r3 = r.lockToRevoke(existing2.getId()); existing2.reload(); assertSameRecords(existing2, r3); assertEquals(ItemState.LOCKED, existing2.getState()); assertEquals(r.getRecordId(), existing2.getLockedByRecordId()); }