StateRecord r = record.lockToRevoke(revokingItem.getId()); if (r == null) { checkingItem.addError(Errors.BAD_REVOKE, revokingItem.getId().toString(), "can't revoke");
StateRecord r = record.lockToRevoke(a.getId()); if (r == null) { checkingItem.addError(Errors.BAD_REVOKE, a.getId().toString(), "can't revoke");
@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 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()); }