Skip to content

Commit 1c087d5

Browse files
line-oadamretter
authored andcommitted
[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
1 parent 38ab96e commit 1c087d5

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

exist-core/src/main/java/org/exist/test/ExistXmldbEmbeddedServer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.IOException;
4343
import java.nio.file.Path;
4444
import java.util.Map;
45+
import java.util.Properties;
4546

4647
import static org.junit.Assert.assertEquals;
4748
import static org.junit.Assert.fail;
@@ -98,6 +99,17 @@ public ExistXmldbEmbeddedServer(final boolean asGuest, final boolean disableAuto
9899
this.asGuest = asGuest;
99100
}
100101

102+
/**
103+
* @param asGuest Use the guest account, default is the admin account
104+
* @param disableAutoDeploy Whether auto-deployment of XARs should be disabled
105+
* @param useTemporaryStorage Whether the data and journal folder should use temporary storage
106+
* @param settings set properties
107+
*/
108+
public ExistXmldbEmbeddedServer(final boolean asGuest, final boolean disableAutoDeploy, final boolean useTemporaryStorage, final Properties settings) {
109+
this.existEmbeddedServer = new ExistEmbeddedServer(null, null, settings, disableAutoDeploy, useTemporaryStorage);
110+
this.asGuest = asGuest;
111+
}
112+
101113
@Override
102114
protected void before() throws Throwable {
103115
startDb();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist.xquery.update;
23+
24+
import org.exist.test.ExistXmldbEmbeddedServer;
25+
import org.junit.After;
26+
import org.junit.Before;
27+
import org.junit.ClassRule;
28+
import org.junit.Test;
29+
import org.xmldb.api.base.Collection;
30+
import org.xmldb.api.base.ResourceSet;
31+
import org.xmldb.api.modules.CollectionManagementService;
32+
import org.xmldb.api.modules.XMLResource;
33+
import org.xmldb.api.modules.XQueryService;
34+
35+
import static org.exist.util.PropertiesBuilder.propertiesBuilder;
36+
import static org.exist.storage.DBBroker.PROPERTY_XUPDATE_FRAGMENTATION_FACTOR;
37+
import static org.exist.test.TestConstants.TEST_COLLECTION_URI;
38+
import static org.exist.test.TestConstants.TEST_XML_URI;
39+
import static org.junit.Assert.assertEquals;
40+
41+
public class UpdateInsertTriggersDefrag {
42+
@ClassRule
43+
public static final ExistXmldbEmbeddedServer exist = new ExistXmldbEmbeddedServer(false, true, true,
44+
propertiesBuilder().put(PROPERTY_XUPDATE_FRAGMENTATION_FACTOR, -1).build());
45+
private final String path = TEST_COLLECTION_URI + "/" + TEST_XML_URI.toString();
46+
private Collection testCollection;
47+
private CollectionManagementService collectionService;
48+
49+
@Before
50+
public void setUp() throws Exception {
51+
collectionService = (CollectionManagementService) exist.getRoot().getService("CollectionManagementService","1.0");
52+
53+
testCollection = collectionService.createCollection(TEST_COLLECTION_URI.lastSegment().toString());
54+
final XMLResource doc = (XMLResource) testCollection.createResource(TEST_XML_URI.toString(), XMLResource.RESOURCE_TYPE);
55+
56+
doc.setContent("<list><item>initial</item></list>");
57+
testCollection.storeResource(doc);
58+
}
59+
60+
@After
61+
public void tearDown() throws Exception {
62+
collectionService.removeCollection(testCollection.getName());
63+
testCollection.close();
64+
}
65+
66+
@Test
67+
public void triggerDefragAfterUpdate() throws Exception {
68+
final XQueryService queryService = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
69+
70+
final String update = "update insert <item>new node</item> into doc('" + path + "')//list";
71+
final ResourceSet updateResult = queryService.queryResource(path, update);
72+
assertEquals("Update expression returns an empty sequence", 0, updateResult.getSize());
73+
74+
final ResourceSet itemResult = queryService.queryResource(path, "//item");
75+
assertEquals("Both items are returned", 2, itemResult.getSize());
76+
}
77+
78+
}

0 commit comments

Comments
 (0)