Skip to content

Commit

Permalink
[test] add test that triggers defragmentation after update
Browse files Browse the repository at this point in the history
- add constructor to ExistXmldbEmbeddedServer that allows passing in configuration properties
- create new test that updates a document with fragmentation limit set to -1
  • Loading branch information
line-o committed Apr 30, 2024
1 parent 301a4e1 commit ad6636f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<list><item>initial</item></list>");
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 <item>new node</item> 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());
}

}

0 comments on commit ad6636f

Please sign in to comment.