Search in sources :

Example 1 with LocalBinaryResource

use of org.exist.xmldb.LocalBinaryResource in project exist by eXist-db.

the class FilterInputStreamCacheMonitorTest method binaryResult.

@Test
public void binaryResult() throws XMLDBException {
    final FilterInputStreamCacheMonitor monitor = FilterInputStreamCacheMonitor.getInstance();
    // assert no binaries in use yet
    int activeCount = monitor.getActive().size();
    if (activeCount != 0) {
        fail("FilterInputStreamCacheMonitor should have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
    }
    ResourceSet resourceSet = null;
    try {
        resourceSet = existXmldbEmbeddedServer.executeQuery("util:binary-doc('/db/" + TEST_COLLECTION_NAME + "/icon.png')");
        assertEquals(1, resourceSet.getSize());
        try (final EXistResource resource = (EXistResource) resourceSet.getResource(0)) {
            assertTrue(resource instanceof LocalBinaryResource);
            assertTrue(((ExtendedResource) resource).getExtendedContent() instanceof BinaryValue);
            // one active binary (as it is in the result set)
            assertEquals(1, monitor.getActive().size());
        }
        // assert no active binaries as we just closed the resource in the try-with-resources
        activeCount = monitor.getActive().size();
        if (activeCount != 0) {
            fail("FilterInputStreamCacheMonitor should again have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
        }
    } finally {
        resourceSet.clear();
    }
}
Also used : EXistResource(org.exist.xmldb.EXistResource) LocalBinaryResource(org.exist.xmldb.LocalBinaryResource) ExtendedResource(org.exist.xmldb.ExtendedResource) BinaryValue(org.exist.xquery.value.BinaryValue) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 2 with LocalBinaryResource

use of org.exist.xmldb.LocalBinaryResource in project exist by eXist-db.

the class FilterInputStreamCacheMonitorTest method enclosedExpressionCleanup.

@Test
public void enclosedExpressionCleanup() throws XMLDBException {
    final FilterInputStreamCacheMonitor monitor = FilterInputStreamCacheMonitor.getInstance();
    // assert no binaries in use yet
    int activeCount = monitor.getActive().size();
    if (activeCount != 0) {
        fail("FilterInputStreamCacheMonitor should have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
    }
    ResourceSet resourceSet = null;
    try {
        resourceSet = existXmldbEmbeddedServer.executeQuery("let $embedded := <logo><image>{util:binary-doc('/db/" + TEST_COLLECTION_NAME + "/icon.png')}</image></logo>\n" + "return xmldb:store('/db/" + TEST_COLLECTION_NAME + "', 'icon.xml', $embedded)");
        assertEquals(1, resourceSet.getSize());
        try (final EXistResource resource = (EXistResource) resourceSet.getResource(0)) {
            assertFalse(resource instanceof LocalBinaryResource);
            // assert still no active binaries (because they have been cleaned up)
            activeCount = monitor.getActive().size();
            if (activeCount != 0) {
                fail("FilterInputStreamCacheMonitor should again have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
            }
        }
    } finally {
        resourceSet.clear();
    }
}
Also used : EXistResource(org.exist.xmldb.EXistResource) LocalBinaryResource(org.exist.xmldb.LocalBinaryResource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 3 with LocalBinaryResource

use of org.exist.xmldb.LocalBinaryResource in project exist by eXist-db.

the class FilterInputStreamCacheMonitorTest method enclosedExpressionsCleanup.

@Test
public void enclosedExpressionsCleanup() throws XMLDBException {
    final FilterInputStreamCacheMonitor monitor = FilterInputStreamCacheMonitor.getInstance();
    // assert no binaries in use yet
    int activeCount = monitor.getActive().size();
    if (activeCount != 0) {
        fail("FilterInputStreamCacheMonitor should have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
    }
    ResourceSet resourceSet = null;
    try {
        resourceSet = existXmldbEmbeddedServer.executeQuery("let $bin := util:binary-doc('/db/" + TEST_COLLECTION_NAME + "/icon.png')\n" + "let $embedded := <logo><image>{$bin}</image></logo>\n" + "let $embedded-2 := <other>{$bin}</other>\n" + "return xmldb:store('/db/" + TEST_COLLECTION_NAME + "', 'icon.xml', $embedded)");
        assertEquals(1, resourceSet.getSize());
        try (final EXistResource resource = (EXistResource) resourceSet.getResource(0)) {
            assertFalse(resource instanceof LocalBinaryResource);
            // assert still no active binaries (because they have been cleaned up)
            activeCount = monitor.getActive().size();
            if (activeCount != 0) {
                fail("FilterInputStreamCacheMonitor should again have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
            }
        }
    } finally {
        resourceSet.clear();
    }
}
Also used : EXistResource(org.exist.xmldb.EXistResource) LocalBinaryResource(org.exist.xmldb.LocalBinaryResource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Aggregations

EXistResource (org.exist.xmldb.EXistResource)3 LocalBinaryResource (org.exist.xmldb.LocalBinaryResource)3 Test (org.junit.Test)3 ResourceSet (org.xmldb.api.base.ResourceSet)3 ExtendedResource (org.exist.xmldb.ExtendedResource)1 BinaryValue (org.exist.xquery.value.BinaryValue)1