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();
}
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));
}
}
}
Aggregations