MongoLockService implements LockService { @Override public boolean releaseLock() { final Document releaseDocument = new LockEntryDocBuilder().release().build(); final Document result = getLockCollection().findOneAndUpdate( new Document(LockEntryDocBuilder.LOCK_ENTRY, true), new Document("$set", releaseDocument)); return result != null && result.getBoolean(LockEntryDocBuilder.LOCKED, false) == true; } MongoLockService(MongoDatabase database); @Override boolean acquireLock(); @Override boolean releaseLock(); @Override LockEntry getLockInformation(); @Override void destroyLock(); static final String MIGRAMONGO_LOCK_COLLECTION; }
@Test public void shouldNotReleaseLockIfNotAcquiredFirst() throws Exception { assertThat(lockService.releaseLock(), is(false)); }