@Test public void shouldAcquireLock() throws Exception { assertThat(lockService.acquireLock(), is(true)); }
@Override public boolean acquireLock() { if (getLockCollection().count() == 0) { throw new IllegalStateException( "Cannot acquire lock because lock table has not been initialized. Initialize MongoLockService properly, or call destroyLock"); } final Document lockDocument = new LockEntryDocBuilder().lock().build(); final Document result = getLockCollection() .findOneAndUpdate(new Document(LockEntryDocBuilder.LOCK_ENTRY, true), new Document("$set", lockDocument)); return result != null && result.getBoolean(LockEntryDocBuilder.LOCKED, true) == false; }
MongoLockService implements LockService { @Override public boolean acquireLock() { if (getLockCollection().count() == 0) { throw new IllegalStateException( "Cannot acquire lock because lock table has not been initialized. Initialize MongoLockService properly, or call destroyLock"); } final Document lockDocument = new LockEntryDocBuilder().lock().build(); final Document result = getLockCollection() .findOneAndUpdate(new Document(LockEntryDocBuilder.LOCK_ENTRY, true), new Document("$set", lockDocument)); return result != null && result.getBoolean(LockEntryDocBuilder.LOCKED, true) == false; } }
MongoLockService implements LockService { @Override public boolean acquireLock() { if (getLockCollection().count() == 0) { throw new IllegalStateException( "Cannot acquire lock because lock table has not been initialized. Initialize MongoLockService properly, or call destroyLock"); } final Document lockDocument = new LockEntryDocBuilder().lock().build(); final Document result = getLockCollection() .findOneAndUpdate(new Document(LockEntryDocBuilder.LOCK_ENTRY, true), new Document("$set", lockDocument)); return result != null && result.getBoolean(LockEntryDocBuilder.LOCKED, true) == false; } MongoLockService(MongoDatabase database); }
MongoLockService implements LockService { @Override public boolean acquireLock() { if (getLockCollection().count() == 0) { throw new IllegalStateException( "Cannot acquire lock because lock table has not been initialized. Initialize MongoLockService properly, or call destroyLock"); } final Document lockDocument = new LockEntryDocBuilder().lock().build(); final Document result = getLockCollection() .findOneAndUpdate(new Document(LockEntryDocBuilder.LOCK_ENTRY, true), new Document("$set", lockDocument)); return result != null && result.getBoolean(LockEntryDocBuilder.LOCKED, true) == false; } MongoLockService(MongoDatabase database); @Override boolean acquireLock(); @Override boolean releaseLock(); @Override LockEntry getLockInformation(); @Override void destroyLock(); }
MongoLockService implements LockService { @Override public boolean acquireLock() { if (getLockCollection().count() == 0) { throw new IllegalStateException( "Cannot acquire lock because lock table has not been initialized. Initialize MongoLockService properly, or call destroyLock"); } final Document lockDocument = new LockEntryDocBuilder().lock().build(); final Document result = getLockCollection() .findOneAndUpdate(new Document(LockEntryDocBuilder.LOCK_ENTRY, true), new Document("$set", lockDocument)); return result != null && result.getBoolean(LockEntryDocBuilder.LOCKED, true) == false; } MongoLockService(MongoDatabase database); @Override boolean acquireLock(); @Override boolean releaseLock(); @Override LockEntry getLockInformation(); @Override void destroyLock(); static final String MIGRAMONGO_LOCK_COLLECTION; }