Search in sources :

Example 16 with Tuple2

use of com.evolvedbinary.j8fu.tuple.Tuple2 in project exist by eXist-db.

the class FluentBrokerAPITest method collectionThenDoc.

@Test
public void collectionThenDoc() throws PermissionDeniedException, EXistException, LockException {
    final XmldbURI docUri = uri("all-test.xml");
    final long collectionCreated = 1234;
    final long docLastModified = 5678;
    final IMocksControl ctrl = createStrictControl();
    ctrl.checkOrder(true);
    final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
    final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
    final Collection mockCollection = ctrl.createMock(Collection.class);
    final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
    final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
    expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
    expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
    expect(mockCollection.getCreated()).andReturn(collectionCreated);
    expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
    expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
    // NOTE: checks that Collection lock is release before Document lock
    mockCollection.close();
    expect(mockDocument.getLastModified()).andReturn(docLastModified);
    mockLockedDocument.close();
    mockBroker.close();
    ctrl.replay();
    final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
    final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
    final Tuple2<Long, Long> result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).execute(collectionOp).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).withoutCollection().execute(documentOp).doAll();
    assertEquals(collectionCreated, result._1.longValue());
    assertEquals(docLastModified, result._2.longValue());
    ctrl.verify();
}
Also used : Tuple3(com.evolvedbinary.j8fu.tuple.Tuple3) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) IMocksControl(org.easymock.IMocksControl) LockMode(org.exist.storage.lock.Lock.LockMode) LockedDocument(org.exist.dom.persistent.LockedDocument) EasyMock.createStrictControl(org.easymock.EasyMock.createStrictControl) BiFunction(java.util.function.BiFunction) Test(org.junit.Test) PermissionDeniedException(org.exist.security.PermissionDeniedException) EasyMock.expect(org.easymock.EasyMock.expect) Function(java.util.function.Function) FluentBrokerAPI.uri(org.exist.storage.FluentBrokerAPI.uri) LockException(org.exist.util.LockException) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) DocumentImpl(org.exist.dom.persistent.DocumentImpl) EXistException(org.exist.EXistException) Lock(org.exist.storage.lock.Lock) Assert.assertEquals(org.junit.Assert.assertEquals) DocumentImpl(org.exist.dom.persistent.DocumentImpl) IMocksControl(org.easymock.IMocksControl) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) LockedDocument(org.exist.dom.persistent.LockedDocument) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) Test(org.junit.Test)

Example 17 with Tuple2

use of com.evolvedbinary.j8fu.tuple.Tuple2 in project exist by eXist-db.

the class BlobStoreImplTest method removeUnique.

@Test
public void removeUnique() throws IOException {
    final Path blobDbx = temporaryFolder.getRoot().toPath().resolve("blob.dbx");
    final Path blobDir = temporaryFolder.newFolder("blob").toPath();
    final List<Tuple2<byte[], MessageDigest>> testFiles = Arrays.asList(generateTestFile(), generateTestFile(), generateTestFile(), generateTestFile(), generateTestFile());
    try (final BlobStore blobStore = newBlobStore(blobDbx, blobDir)) {
        blobStore.open();
        final List<BlobId> addedBlobIds = new ArrayList<>();
        for (final Tuple2<byte[], MessageDigest> testFile : testFiles) {
            addedBlobIds.add(addAndVerify(blobStore, testFile));
        }
        // remove each added blob
        for (final BlobId addedBlobId : addedBlobIds) {
            blobStore.remove(null, addedBlobId);
        }
        // check that each blob was removed
        for (final BlobId addedBlobId : addedBlobIds) {
            assertNull(blobStore.get(null, addedBlobId));
        }
    }
}
Also used : Path(java.nio.file.Path) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) MessageDigest(org.exist.util.crypto.digest.MessageDigest) Test(org.junit.Test)

Aggregations

Tuple2 (com.evolvedbinary.j8fu.tuple.Tuple2)17 XmldbURI (org.exist.xmldb.XmldbURI)10 Function (java.util.function.Function)8 EXistException (org.exist.EXistException)8 Collection (org.exist.collections.Collection)8 Test (org.junit.Test)8 Tuple3 (com.evolvedbinary.j8fu.tuple.Tuple3)7 DocumentImpl (org.exist.dom.persistent.DocumentImpl)7 LockedDocument (org.exist.dom.persistent.LockedDocument)7 Lock (org.exist.storage.lock.Lock)7 LockException (org.exist.util.LockException)7 Path (java.nio.file.Path)6 BiFunction (java.util.function.BiFunction)6 LockMode (org.exist.storage.lock.Lock.LockMode)6 EasyMock.createStrictControl (org.easymock.EasyMock.createStrictControl)5 EasyMock.expect (org.easymock.EasyMock.expect)5 IMocksControl (org.easymock.IMocksControl)5 PermissionDeniedException (org.exist.security.PermissionDeniedException)5 FluentBrokerAPI.uri (org.exist.storage.FluentBrokerAPI.uri)5 Assert.assertEquals (org.junit.Assert.assertEquals)5