Search in sources :

Example 6 with Tuple3

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

the class MoveOverwriteCollectionTest method store.

private Tuple3<Collection, Collection, Collection> store(final DBBroker broker) throws Exception {
    try (final Txn transaction = broker.getBrokerPool().getTransactionManager().beginTransaction()) {
        final Collection test1 = createCollection(transaction, broker, TEST_COLLECTION_URI);
        final Collection test2 = createCollection(transaction, broker, SUB_TEST_COLLECTION_URI);
        final Collection test3 = createCollection(transaction, broker, TEST3_COLLECTION_URI);
        broker.storeDocument(transaction, doc1Name, new StringInputSource(XML1), MimeType.XML_TYPE, test1);
        broker.storeDocument(transaction, doc2Name, new StringInputSource(XML2), MimeType.XML_TYPE, test2);
        broker.storeDocument(transaction, doc3Name, new StringInputSource(XML3), MimeType.XML_TYPE, test3);
        transaction.commit();
        return new Tuple3<>(test1, test2, test3);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) Tuple3(com.evolvedbinary.j8fu.tuple.Tuple3) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 7 with Tuple3

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

the class FluentBrokerAPITest method all.

@Test
public void all() 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);
    expect(mockCollection.getURI()).andReturn(TEST_COLLECTION_URI);
    expect(mockDocument.getFileURI()).andReturn(docUri);
    // 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 BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
    final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
    final Tuple3<Long, String, Long> result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).execute(collectionOp).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).execute(collectionDocOp).withoutCollection().execute(documentOp).doAll();
    assertEquals(collectionCreated, result._1.longValue());
    assertEquals(TEST_COLLECTION_URI.append(docUri), result._2);
    assertEquals(docLastModified, result._3.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) LockedDocument(org.exist.dom.persistent.LockedDocument) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) Test(org.junit.Test)

Aggregations

Tuple3 (com.evolvedbinary.j8fu.tuple.Tuple3)7 LockException (org.exist.util.LockException)5 XmldbURI (org.exist.xmldb.XmldbURI)5 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 MultiLock (uk.ac.ic.doc.slurp.multilock.MultiLock)4 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 Tuple2 (com.evolvedbinary.j8fu.tuple.Tuple2)2 Arrays (java.util.Arrays)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Collection (org.exist.collections.Collection)2 LockType (org.exist.storage.lock.Lock.LockType)2 Configuration (org.exist.util.Configuration)2 WeakLazyStripes (org.exist.util.WeakLazyStripes)2 Try (com.evolvedbinary.j8fu.Try)1 TaggedTryUnchecked (com.evolvedbinary.j8fu.Try.TaggedTryUnchecked)1 Tuple (com.evolvedbinary.j8fu.tuple.Tuple.Tuple)1 FileNotFoundException (java.io.FileNotFoundException)1 FilterInputStream (java.io.FilterInputStream)1