Skip to content

Commit fd3d243

Browse files
authored
Merge pull request #5276 from line-o/test/enforce-defragmentation
[bugfix] fix errors on update operations
2 parents 75da7eb + 1ca9901 commit fd3d243

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

exist-core/src/main/java/org/exist/storage/NativeBroker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,7 @@ public Object start() {
31723172
}
31733173
}.run();
31743174
// create a copy of the old doc to copy the nodes into it
3175-
final DocumentImpl tempDoc = new DocumentImpl(null, null, doc.getCollection(), doc.getDocId(), doc.getFileURI());
3175+
final DocumentImpl tempDoc = new DocumentImpl(null, doc.getDocId(), doc);
31763176
tempDoc.copyOf(this, doc, doc);
31773177
final StreamListener listener = getIndexController().getStreamListener(doc, ReindexMode.STORE);
31783178
// copy the nodes

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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.storage.DBBroker;
25+
import org.exist.test.ExistXmldbEmbeddedServer;
26+
import org.exist.test.TestConstants;
27+
import org.junit.After;
28+
import org.junit.Before;
29+
import org.junit.ClassRule;
30+
import org.junit.Test;
31+
import org.xmldb.api.base.Collection;
32+
import org.xmldb.api.base.ResourceSet;
33+
import org.xmldb.api.base.XMLDBException;
34+
import org.xmldb.api.modules.CollectionManagementService;
35+
import org.xmldb.api.modules.XMLResource;
36+
import org.xmldb.api.modules.XPathQueryService;
37+
import org.xmldb.api.modules.XQueryService;
38+
39+
import static org.exist.util.PropertiesBuilder.propertiesBuilder;
40+
import static org.junit.Assert.assertEquals;
41+
42+
public class UpdateInsertTriggersDefrag {
43+
@ClassRule
44+
public static final ExistXmldbEmbeddedServer exist = new ExistXmldbEmbeddedServer(false, true, true, propertiesBuilder().put(DBBroker.PROPERTY_XUPDATE_FRAGMENTATION_FACTOR, -1).build());
45+
final String path = TestConstants.TEST_COLLECTION_URI + "/" + TestConstants.TEST_XML_URI.toString();
46+
final String xml = "<list><item>initial</item></list>";
47+
Collection testCollection;
48+
XQueryService queryService;
49+
CollectionManagementService collectionService;
50+
51+
/**
52+
* stores XML String and get Query Service
53+
*
54+
* @param documentName to be stored in the DB
55+
* @param content to be stored in the DB
56+
* @throws XMLDBException if an error occurs storing the document
57+
*/
58+
private void storeXML(final String documentName, final String content) throws XMLDBException {
59+
final XMLResource doc = testCollection.createResource(documentName, XMLResource.class);
60+
doc.setContent(content);
61+
testCollection.storeResource(doc);
62+
}
63+
64+
@Before
65+
public void setUp() throws Exception {
66+
collectionService = exist.getRoot().getService(CollectionManagementService.class);
67+
testCollection = collectionService.createCollection(TestConstants.TEST_COLLECTION_URI.toString());
68+
queryService = (XQueryService) testCollection.getService(XPathQueryService.class);
69+
storeXML(TestConstants.TEST_XML_URI.toString(), xml);
70+
}
71+
72+
@After
73+
public void tearDown() throws Exception {
74+
collectionService.removeCollection(testCollection.getName());
75+
}
76+
77+
@Test
78+
public void triggerDefragAfterUpdate() throws Exception {
79+
final String update = "update insert <item>new node</item> into doc('" + path + "')//list";
80+
final ResourceSet updateResult = queryService.queryResource(TestConstants.TEST_XML_URI.toString(), update);
81+
assertEquals("Update expression returns an empty sequence", 0, updateResult.getSize());
82+
83+
final ResourceSet itemResult = queryService.queryResource(TestConstants.TEST_XML_URI.toString(), "//item");
84+
assertEquals("Both items are returned", 2, itemResult.getSize());
85+
}
86+
87+
}

0 commit comments

Comments
 (0)