|
| 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