diff --git a/exist-core/src/main/java/org/exist/test/ExistXmldbEmbeddedServer.java b/exist-core/src/main/java/org/exist/test/ExistXmldbEmbeddedServer.java index c39ea1f8452..cd54c9e7b4d 100644 --- a/exist-core/src/main/java/org/exist/test/ExistXmldbEmbeddedServer.java +++ b/exist-core/src/main/java/org/exist/test/ExistXmldbEmbeddedServer.java @@ -42,6 +42,7 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Map; +import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -98,6 +99,17 @@ public ExistXmldbEmbeddedServer(final boolean asGuest, final boolean disableAuto this.asGuest = asGuest; } + /** + * @param asGuest Use the guest account, default is the admin account + * @param disableAutoDeploy Whether auto-deployment of XARs should be disabled + * @param useTemporaryStorage Whether the data and journal folder should use temporary storage + * @param settings set properties + */ + public ExistXmldbEmbeddedServer(final boolean asGuest, final boolean disableAutoDeploy, final boolean useTemporaryStorage, final Properties settings) { + this.existEmbeddedServer = new ExistEmbeddedServer(null, null, settings, disableAutoDeploy, useTemporaryStorage); + this.asGuest = asGuest; + } + @Override protected void before() throws Throwable { startDb(); diff --git a/exist-core/src/test/java/org/exist/xquery/update/UpdateInsertTriggersDefrag.java b/exist-core/src/test/java/org/exist/xquery/update/UpdateInsertTriggersDefrag.java new file mode 100644 index 00000000000..398500a190c --- /dev/null +++ b/exist-core/src/test/java/org/exist/xquery/update/UpdateInsertTriggersDefrag.java @@ -0,0 +1,57 @@ +package org.exist.xquery.update; + +import org.exist.test.ExistXmldbEmbeddedServer; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.xmldb.api.base.Collection; +import org.xmldb.api.base.ResourceSet; +import org.xmldb.api.modules.CollectionManagementService; +import org.xmldb.api.modules.XMLResource; +import org.xmldb.api.modules.XQueryService; + +import static org.exist.util.PropertiesBuilder.propertiesBuilder; +import static org.exist.storage.DBBroker.PROPERTY_XUPDATE_FRAGMENTATION_FACTOR; +import static org.exist.test.TestConstants.TEST_COLLECTION_URI; +import static org.exist.test.TestConstants.TEST_XML_URI; +import static org.junit.Assert.assertEquals; + +public class UpdateInsertTriggersDefrag { + @ClassRule + public static final ExistXmldbEmbeddedServer exist = new ExistXmldbEmbeddedServer(false, true, true, + propertiesBuilder().put(PROPERTY_XUPDATE_FRAGMENTATION_FACTOR, -1).build()); + private final String path = TEST_COLLECTION_URI + "/" + TEST_XML_URI.toString(); + private Collection testCollection; + private CollectionManagementService collectionService; + + @Before + public void setUp() throws Exception { + collectionService = (CollectionManagementService) exist.getRoot().getService("CollectionManagementService","1.0"); + + testCollection = collectionService.createCollection(TEST_COLLECTION_URI.lastSegment().toString()); + final XMLResource doc = (XMLResource) testCollection.createResource(TEST_XML_URI.toString(), XMLResource.RESOURCE_TYPE); + + doc.setContent("initial"); + testCollection.storeResource(doc); + } + + @After + public void tearDown() throws Exception { + collectionService.removeCollection(testCollection.getName()); + testCollection.close(); + } + + @Test + public void triggerDefragAfterUpdate() throws Exception { + final XQueryService queryService = (XQueryService) testCollection.getService("XPathQueryService", "1.0"); + + final String update = "update insert new node into doc('" + path + "')//list"; + final ResourceSet updateResult = queryService.queryResource(path, update); + assertEquals("Update expression returns an empty sequence", 0, updateResult.getSize()); + + final ResourceSet itemResult = queryService.queryResource(path, "//item"); + assertEquals("Both items are returned", 2, itemResult.getSize()); + } + +}