Skip to content

Commit e978710

Browse files
committed
[bugfix] Make sure test resources are cleaned up
1 parent abf0f58 commit e978710

5 files changed

Lines changed: 152 additions & 33 deletions

File tree

exist-core/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@
984984
<include>src/test/java/org/exist/storage/RecoverBinary2Test.java</include>
985985
<include>src/test/java/org/exist/storage/RecoveryTest.java</include>
986986
<include>src/test/java/org/exist/storage/Recovery2Test.java</include>
987+
<include>src/test/java/org/exist/storage/RemoveCollectionTest.java</include>
987988
<include>src/main/java/org/exist/storage/StorageAddress.java</include>
988989
<include>src/test/java/org/exist/storage/XIncludeSerializerTest.java</include>
989990
<include>src/test/java/org/exist/storage/btree/BTreeTest.java</include>
@@ -995,7 +996,9 @@
995996
<include>src/main/java/org/exist/storage/io/VariableByteInputToInputStream.java</include>
996997
<include>src/main/java/org/exist/storage/io/VariableByteOutputToOutputStream.java</include>
997998
<include>src/test/java/org/exist/storage/io/VariableByteStreamTest.java</include>
999+
<include>src/test/java/org/exist/storage/lock/DeadlockTest.java</include>
9981000
<include>src/main/java/org/exist/storage/lock/FileLock.java</include>
1001+
<include>src/test/java/org/exist/storage/lock/ProtectedModeTest.java</include>
9991002
<include>src/main/java/org/exist/storage/recovery/RecoveryManager.java</include>
10001003
<include>src/main/java/org/exist/storage/serializers/EXistOutputKeys.java</include>
10011004
<include>src/main/java/org/exist/storage/serializers/Serializer.java</include>
@@ -1093,6 +1096,7 @@
10931096
<include>src/test/java/org/exist/xmldb/concurrent/XMLGenerator.java</include>
10941097
<include>src/test/java/org/exist/xmldb/concurrent/action/MultiResourcesAction.java</include>
10951098
<include>src/main/java/org/exist/xmlrpc/ExistRpcTypeFactory.java</include>
1099+
<include>src/test/java/org/exist/xmlrpc/QuerySessionTest.java</include>
10961100
<include>src/main/java/org/exist/xmlrpc/RpcAPI.java</include>
10971101
<include>src/main/java/org/exist/xmlrpc/RpcConnection.java</include>
10981102
<include>src/main/java/org/exist/xqj/Marshaller.java</include>
@@ -1568,6 +1572,7 @@
15681572
<exclude>src/test/java/org/exist/storage/RecoverXmlTest.java</exclude>
15691573
<exclude>src/test/java/org/exist/storage/RecoveryTest.java</exclude>
15701574
<exclude>src/test/java/org/exist/storage/Recovery2Test.java</exclude>
1575+
<exclude>src/test/java/org/exist/storage/RemoveCollectionTest.java</exclude>
15711576
<exclude>src/main/java/org/exist/storage/StorageAddress.java</exclude>
15721577
<exclude>src/test/java/org/exist/storage/XIncludeSerializerTest.java</exclude>
15731578
<exclude>src/main/java/org/exist/storage/XQueryPool.java</exclude>
@@ -1596,6 +1601,7 @@
15961601
<exclude>src/test/java/org/exist/storage/journal/JournalXmlTest.java</exclude>
15971602
<exclude>src/test/java/org/exist/storage/journal/LsnTest.java</exclude>
15981603
<exclude>src/test/java/org/exist/storage/lock/CollectionLocksTest.java</exclude>
1604+
<exclude>src/test/java/org/exist/storage/lock/DeadlockTest.java</exclude>
15991605
<exclude>src/test/java/org/exist/storage/lock/DocumentLocksTest.java</exclude>
16001606
<exclude>src/main/java/org/exist/storage/lock/EnsureContainerLocked.java</exclude>
16011607
<exclude>src/main/java/org/exist/storage/lock/EnsureContainerUnlocked.java</exclude>
@@ -1618,6 +1624,7 @@
16181624
<exclude>src/main/java/org/exist/storage/lock/ManagedLock.java</exclude>
16191625
<exclude>src/main/java/org/exist/storage/lock/ManagedLockGroupDocumentLock.java</exclude>
16201626
<exclude>src/main/java/org/exist/storage/lock/ManagedSingleLockDocumentLock.java</exclude>
1627+
<exclude>src/test/java/org/exist/storage/lock/ProtectedModeTest.java</exclude>
16211628
<exclude>src/main/java/org/exist/storage/recovery/RecoveryManager.java</exclude>
16221629
<exclude>src/main/java/org/exist/storage/serializers/EXistOutputKeys.java</exclude>
16231630
<exclude>src/test/java/org/exist/storage/serializers/NativeSerializerTest.java</exclude>
@@ -1740,6 +1747,7 @@
17401747
<exclude>src/main/java/org/exist/xmlrpc/ArrayWrapperParser.java</exclude>
17411748
<exclude>src/main/java/org/exist/xmlrpc/ArrayWrapperSerializer.java</exclude>
17421749
<exclude>src/main/java/org/exist/xmlrpc/ExistRpcTypeFactory.java</exclude>
1750+
<exclude>src/test/java/org/exist/xmlrpc/QuerySessionTest.java</exclude>
17431751
<exclude>src/main/java/org/exist/xmlrpc/RpcAPI.java</exclude>
17441752
<exclude>src/main/java/org/exist/xmlrpc/RpcConnection.java</exclude>
17451753
<exclude>src/main/java/org/exist/xmlrpc/XmlRpcExtensionConstants.java</exclude>

exist-core/src/test/java/org/exist/storage/RemoveCollectionTest.java

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
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; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -19,7 +43,6 @@
1943
* License along with this library; if not, write to the Free Software
2044
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2145
*/
22-
2346
package org.exist.storage;
2447

2548
import org.exist.EXistException;
@@ -156,16 +179,19 @@ public void replaceResources(final BrokerPool pool) throws SAXException, Permiss
156179

157180
try(final Txn transaction = transact.beginTransaction()) {
158181

159-
TestDataGenerator generator = new TestDataGenerator("xdb", COUNT);
160-
final Path[] files = generator.generate(broker, test, generateXQ);
161-
162-
int j = 0;
163-
for (final Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext() && j < files.length; j++) {
164-
final DocumentImpl doc = i.next();
165-
final InputSource is = new InputSource(files[j].toUri().toASCIIString());
166-
broker.storeDocument(transaction, doc.getURI(), is, MimeType.XML_TYPE, test);
182+
final TestDataGenerator generator = new TestDataGenerator("xdb", COUNT);
183+
try {
184+
final Path[] files = generator.generate(broker, test, generateXQ);
185+
186+
int j = 0;
187+
for (final Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext() && j < files.length; j++) {
188+
final DocumentImpl doc = i.next();
189+
final InputSource is = new InputSource(files[j].toUri().toASCIIString());
190+
broker.storeDocument(transaction, doc.getURI(), is, MimeType.XML_TYPE, test);
191+
}
192+
} finally {
193+
generator.releaseAll();
167194
}
168-
generator.releaseAll();
169195
transact.commit(transaction);
170196
}
171197
}
@@ -185,13 +211,16 @@ private Collection storeDocs(final DBBroker broker, final TransactionManager tra
185211

186212
try(final Txn transaction = transact.beginTransaction()) {
187213
final TestDataGenerator generator = new TestDataGenerator("xdb", COUNT);
188-
final Path[] files = generator.generate(broker, test, generateXQ);
189-
for(final Path file : files) {
190-
final InputSource is = new InputSource(file.toUri().toASCIIString());
214+
try {
215+
final Path[] files = generator.generate(broker, test, generateXQ);
216+
for (final Path file : files) {
217+
final InputSource is = new InputSource(file.toUri().toASCIIString());
191218

192-
broker.storeDocument(transaction, XmldbURI.create(file.getFileName().toString()), is, MimeType.XML_TYPE, test);
219+
broker.storeDocument(transaction, XmldbURI.create(file.getFileName().toString()), is, MimeType.XML_TYPE, test);
220+
}
221+
} finally {
222+
generator.releaseAll();
193223
}
194-
generator.releaseAll();
195224
transact.commit(transaction);
196225
}
197226
return test;

exist-core/src/test/java/org/exist/storage/lock/DeadlockTest.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
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; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -243,17 +267,20 @@ public void run() {
243267
transact.commit(transaction);
244268
}
245269

246-
final Path[] files = generator.generate(broker, coll, generateXQ);
247-
for (int j = 0; j < files.length; j++, fileCount++) {
248-
try(final Txn transaction = transact.beginTransaction()) {
249-
final InputSource is = new InputSource(files[j].toUri()
270+
try {
271+
final Path[] files = generator.generate(broker, coll, generateXQ);
272+
for (int j = 0; j < files.length; j++, fileCount++) {
273+
try (final Txn transaction = transact.beginTransaction()) {
274+
final InputSource is = new InputSource(files[j].toUri()
250275
.toASCIIString());
251276

252-
broker.storeDocument(transaction, XmldbURI.create("test" + fileCount + ".xml"), is, MimeType.XML_TYPE, coll);
253-
transact.commit(transaction);
277+
broker.storeDocument(transaction, XmldbURI.create("test" + fileCount + ".xml"), is, MimeType.XML_TYPE, coll);
278+
transact.commit(transaction);
279+
}
254280
}
281+
} finally {
282+
generator.releaseAll();
255283
}
256-
generator.releaseAll();
257284
}
258285
} catch (Exception e) {
259286
LOG.error(e.getMessage(), e);

exist-core/src/test/java/org/exist/storage/lock/ProtectedModeTest.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
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; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -124,11 +148,15 @@ public static void setupDb() throws XMLDBException, SAXException {
124148
final TestDataGenerator generator = new TestDataGenerator("xdb", DOCUMENT_COUNT);
125149
for (int i = 0; i < COLLECTION_COUNT; i++) {
126150
Collection currentColl = mgmt.createCollection("test" + i);
127-
final Path[] files = generator.generate(currentColl, generateXQ);
128-
for (int j = 0; j < files.length; j++) {
129-
final XMLResource resource = currentColl.createResource("xdb" + j + ".xml", XMLResource.class);
130-
resource.setContent(files[j].toFile());
131-
currentColl.storeResource(resource);
151+
try {
152+
final Path[] files = generator.generate(currentColl, generateXQ);
153+
for (int j = 0; j < files.length; j++) {
154+
final XMLResource resource = currentColl.createResource("xdb" + j + ".xml", XMLResource.class);
155+
resource.setContent(files[j].toFile());
156+
currentColl.storeResource(resource);
157+
}
158+
} finally {
159+
generator.releaseAll();
132160
}
133161
}
134162
}

exist-core/src/test/java/org/exist/xmlrpc/QuerySessionTest.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
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; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -157,13 +181,16 @@ public static void startServer() throws ClassNotFoundException, IllegalAccessExc
157181
Collection test = mgmt.createCollection("rpctest");
158182

159183
final TestDataGenerator generator = new TestDataGenerator("xdb", DOC_COUNT);
160-
final Path[] files = generator.generate(test, generateXQ);
161-
for (int i = 0; i < files.length; i++) {
162-
Resource resource = test.createResource(files[i].getFileName().toString(), XMLResource.class);
163-
resource.setContent(files[i].toFile());
164-
test.storeResource(resource);
184+
try {
185+
final Path[] files = generator.generate(test, generateXQ);
186+
for (int i = 0; i < files.length; i++) {
187+
Resource resource = test.createResource(files[i].getFileName().toString(), XMLResource.class);
188+
resource.setContent(files[i].toFile());
189+
test.storeResource(resource);
190+
}
191+
} finally {
192+
generator.releaseAll();
165193
}
166-
generator.releaseAll();
167194
}
168195

169196
@AfterClass

0 commit comments

Comments
 (0)