forked from eXist-db/exist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] add test that triggers defragmentation after update
- 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
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
exist-core/src/test/java/org/exist/xquery/update/UpdateInsertTriggersDefrag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |