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