@Override
    public String lock(final Path file) throws BackgroundException {
        try {
            final FileLockRequest request = new FileLockRequest();
            request.setExpire(new DateTime().plusMillis(new HostPreferences(session.getHost()).getInteger("storegate.lock.ttl")));
            request.setOwner(session.getHost().getCredentials().getUsername());
            final FileLock lock = new FileLocksApi(this.session.getClient()).fileLocksCreateLock(fileid.getFileId(file
            ), request);
            return lock.getLockId();
        }
        catch(ApiException e) {
            throw new StoregateExceptionMappingService(fileid).map("Failure to write attributes of {0}", e, file);
        }
    }
@Test
    public void testLock() throws Exception {
        final StoregateIdProvider nodeid = new StoregateIdProvider(session);
        final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir(new Path(
            String.format("/My files/%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
        final Path fileInRoom = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        new StoregateTouchFeature(session, nodeid).touch(fileInRoom, new TransferStatus());
        assertTrue(new DefaultFindFeature(session).find(fileInRoom));
        final String lock = new StoregateLockFeature(session, nodeid).lock(fileInRoom);
        assertNotNull(lock);
        try {
            new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(fileInRoom), new DisabledLoginCallback(), new Delete.DisabledCallback());
            fail();
        }
        catch(LockedException e) {
            // expected
        }
        new StoregateLockFeature(session, nodeid).unlock(fileInRoom, lock);
        new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(fileInRoom), new DisabledLoginCallback(), new Delete.DisabledCallback());
        assertFalse(new DefaultFindFeature(session).find(fileInRoom));
        new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }