Skip to content

Commit 12cbb4b

Browse files
authored
Merge pull request #5503 from evolvedbinary/hotfix/enforce-defragmentation
Fix test resource leaks introduced in eXist-db/exist#5276
2 parents 3ffd9bd + d380983 commit 12cbb4b

File tree

6 files changed

+108
-110
lines changed

6 files changed

+108
-110
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on: [push, pull_request]
33
permissions:
44
contents: read
55
env:
6-
MAVEN_OPTS: -XX:StartFlightRecording=maxsize=5g,disk=true,dumponexit=true,settings=default,filename=./ -DtrimStackTrace=false -D'maven.resolver.transport=wagon'
6+
MAVEN_OPTS: -DtrimStackTrace=false -D'maven.resolver.transport=wagon'
77
DEV_JDK: '17'
88
jobs:
99
license:
@@ -81,6 +81,5 @@ jobs:
8181
name: ${{ runner.os }}-${{ matrix.jvm }}-build-logs
8282
retention-days: 5
8383
path: |
84-
**/*.jfr
8584
**/hs_err_pid*.log
8685
**/target/surefire-reports/*

exist-core/pom.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,18 +1228,17 @@ The BaseX Team. The original license statement is also included below.]]></pream
12281228
<profiles>
12291229
<profile>
12301230
<!--
1231-
Disable parallel tests on Windows.
1232-
When running multiple tests in parallel, Quartz seems to stop eXist-db from shutting down
1233-
on AppVeyor Windows CI, see: https://github.com/quartz-scheduler/quartz/issues/448
1231+
Disable parallel tests on Windows in CI, seems to cause an occasional issue with
1232+
Surefire that produces the Maven error: 'Corrupted channel by directly writing to native stream in forked JVM'.
12341233
-->
1235-
<id>windows-disable-parallel-testing</id>
1234+
<id>windows-disable-parallel-ci-testing</id>
12361235
<activation>
12371236
<os>
12381237
<family>windows</family>
12391238
</os>
12401239
<property>
1241-
<name>env.APPVEYOR</name>
1242-
<value>True</value>
1240+
<name>env.GITHUB_ACTIONS</name>
1241+
<value>true</value>
12431242
</property>
12441243
</activation>
12451244
<build>
@@ -1268,16 +1267,16 @@ The BaseX Team. The original license statement is also included below.]]></pream
12681267
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
12691268
<forkCount>1C</forkCount>
12701269
<reuseForks>false</reuseForks>
1271-
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
1270+
<argLine>-Dfile.encoding=${project.build.sourceEncoding} -Dexist.recovery.progressbar.hide=true</argLine>
12721271
<systemPropertyVariables>
12731272
<jetty.home>${project.basedir}/../exist-jetty-config/target/classes/org/exist/jetty</jetty.home>
12741273
<exist.configurationFile>${project.build.testOutputDirectory}/conf.xml</exist.configurationFile>
12751274
<exist.jetty.standalone.webapp.dir>${project.build.testOutputDirectory}/standalone-webapp</exist.jetty.standalone.webapp.dir>
12761275
<log4j.configurationFile>${project.build.testOutputDirectory}/log4j2.xml</log4j.configurationFile>
12771276
</systemPropertyVariables>
12781277
<excludes>
1279-
<!-- NOTE: this test fails on AppVeyor Windows CI with Oracle JDK 11,
1280-
but not on some other windows systems :-/ -->
1278+
<!-- NOTE: this test occasionally fails on Windows CI
1279+
but not on some other Windows systems :-/ -->
12811280
<exclude>org.exist.storage.lock.CollectionLocksTest</exclude>
12821281

12831282
<!-- NOTE: these can still exhibit deadlocks -->

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@ public ExistXmldbEmbeddedServer(final boolean asGuest, final boolean disableAuto
9999
this.asGuest = asGuest;
100100
}
101101

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-
113102
@Override
114103
protected void before() throws Throwable {
115104
startDb();

exist-core/src/test/java/org/exist/xquery/update/UpdateInsertTriggersDefrag.java

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 com.evolvedbinary.j8fu.function.Consumer2E;
25+
import org.exist.EXistException;
26+
import org.exist.collections.Collection;
27+
import org.exist.security.PermissionDeniedException;
28+
import org.exist.source.StringSource;
29+
import org.exist.storage.BrokerPool;
30+
import org.exist.storage.DBBroker;
31+
import org.exist.storage.txn.Txn;
32+
import org.exist.test.ExistEmbeddedServer;
33+
import org.exist.test.TestConstants;
34+
import org.exist.util.MimeType;
35+
import org.exist.util.StringInputSource;
36+
import org.exist.xquery.XPathException;
37+
import org.exist.xquery.value.Sequence;
38+
import org.junit.Before;
39+
import org.junit.ClassRule;
40+
import org.junit.Test;
41+
42+
import java.io.IOException;
43+
import java.util.Optional;
44+
45+
import static org.exist.test.Util.executeQuery;
46+
import static org.exist.test.Util.withCompiledQuery;
47+
import static org.exist.util.PropertiesBuilder.propertiesBuilder;
48+
import static org.junit.Assert.assertEquals;
49+
import static org.junit.Assert.assertTrue;
50+
51+
public class UpdateInsertTriggersDefragTest {
52+
53+
@ClassRule
54+
public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer(propertiesBuilder().put(DBBroker.PROPERTY_XUPDATE_FRAGMENTATION_FACTOR, -1).build(), true, true);
55+
56+
@Before
57+
public void setUp() throws Exception {
58+
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
59+
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
60+
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
61+
62+
// store the test document in the test collection
63+
try (final Collection testCollection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI)) {
64+
broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource("<list><item>initial</item></list>"), MimeType.XML_TYPE, testCollection);
65+
}
66+
67+
transaction.commit();
68+
}
69+
}
70+
71+
@Test
72+
public void triggerDefragAfterUpdate() throws Exception {
73+
final String updateQuery = "update insert <item>new node</item> into doc('" + TestConstants.TEST_COLLECTION_URI + "/" + TestConstants.TEST_XML_URI + "')//list";
74+
assertQuery(updateQuery, updateResults ->
75+
assertTrue("Update expression returns an empty sequence", updateResults.isEmpty())
76+
);
77+
78+
final String searchQuery = "doc('" + TestConstants.TEST_COLLECTION_URI + "/" + TestConstants.TEST_XML_URI + "')//item";
79+
assertQuery(searchQuery, searchResults ->
80+
assertEquals("Both items are returned", 2, searchResults.getItemCount())
81+
);
82+
}
83+
84+
private void assertQuery(final String query, final Consumer2E<Sequence, XPathException, PermissionDeniedException> assertions) throws EXistException, XPathException, PermissionDeniedException, IOException {
85+
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
86+
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
87+
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
88+
89+
withCompiledQuery(broker, new StringSource(query), compiledQuery -> {
90+
final Sequence results = executeQuery(broker, compiledQuery);
91+
assertions.accept(results);
92+
return null;
93+
});
94+
95+
transaction.commit();
96+
}
97+
}
98+
}

exist-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@
847847
However it can make it hard to diagnose problems if tests leak state; If you experience
848848
such a problem you may want to set it to `false` whilst debugging -->
849849
<reuseForks>true</reuseForks>
850-
<argLine>@{jacocoArgLine} --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED -XX:StartFlightRecording=maxsize=5g,disk=true,dumponexit=true,settings=default,filename=${project.build.directory}/ -Dfile.encoding=${project.build.sourceEncoding}</argLine>
850+
<argLine>@{jacocoArgLine} --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED -Dfile.encoding=${project.build.sourceEncoding}</argLine>
851851
<systemPropertyVariables>
852852
<user.country>UK</user.country>
853853
<user.language>en</user.language>

0 commit comments

Comments
 (0)