Skip to content

Commit 4e9836d

Browse files
committed
[refactor] Remove reflection
1 parent d94e219 commit 4e9836d

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

exist-core/src/main/java/org/exist/storage/journal/Journal.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ public final class Journal implements Closeable {
203203
*/
204204
@ConfigurationFieldAsAttribute("minSize")
205205
//TODO: conf.xml refactoring <recovery minSize=""> => <journal minSize="">
206-
private final long journalSizeMin;
206+
// package-private accessibility for testing
207+
long journalSizeMin;
207208

208209
/**
209210
* size limit for the journal file. A checkpoint will be triggered if the file

exist-core/src/main/java/org/exist/storage/journal/JournalManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public class JournalManager implements BrokerPoolService {
6161

6262
@GuardedBy("this") private Path journalDir;
6363
@GuardedBy("this") private boolean groupCommits;
64-
@GuardedBy("this") private Journal journal;
64+
// package-private accessibility for testing
65+
@GuardedBy("this") Journal journal;
6566
@GuardedBy("this") private boolean journallingDisabled = false;
6667
@GuardedBy("this") private boolean initialized = false;
6768

exist-core/src/test/java/org/exist/storage/journal/AbstractJournalTest.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@
6565
import org.xml.sax.SAXException;
6666

6767
import java.io.IOException;
68-
import java.lang.reflect.Field;
69-
import java.lang.reflect.InvocationTargetException;
70-
import java.lang.reflect.Method;
71-
import java.lang.reflect.Modifier;
7268
import java.nio.file.Files;
7369
import java.nio.file.Path;
7470
import java.util.*;
@@ -1414,19 +1410,12 @@ protected void assertPartialOrdered(final List<ExpectedLoggable> expectedPartial
14141410
/**
14151411
* Check point's the journal, and forces switching to a new journal file.
14161412
*/
1417-
protected void checkpointJournalAndSwitchFile() throws NoSuchFieldException, IllegalAccessException, TransactionException {
1413+
protected void checkpointJournalAndSwitchFile() throws TransactionException {
1414+
final Journal journal = existEmbeddedServer.getBrokerPool().getJournalManager().get().journal;
14181415

14191416
//set Journal#journalMinSize = 0, so that switch files will always happen
1420-
final Field fldMinReplace = Journal.class.getDeclaredField("journalSizeMin");
1421-
fldMinReplace.setAccessible(true);
1422-
final Field modifiersField = JDKCompatibility.getModifiersField();
1423-
modifiersField.setAccessible( true );
1424-
modifiersField.setInt( fldMinReplace, fldMinReplace.getModifiers() & ~Modifier.FINAL );
1425-
final Field fldJournal = JournalManager.class.getDeclaredField("journal");
1426-
fldJournal.setAccessible(true);
1427-
final Journal journal = (Journal)fldJournal.get(existEmbeddedServer.getBrokerPool().getJournalManager().get());
1428-
final long existingMinReplaceValue = fldMinReplace.getLong(journal);
1429-
fldMinReplace.setLong(journal, 0);
1417+
final long existingMinReplaceValue = journal.journalSizeMin;
1418+
journal.journalSizeMin = 0;
14301419

14311420
// checkpoint the journal and switch file
14321421
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
@@ -1435,7 +1424,7 @@ protected void checkpointJournalAndSwitchFile() throws NoSuchFieldException, Ill
14351424
}
14361425

14371426
//restore the Journal#journalMinSize to its previous value
1438-
fldMinReplace.set(journal, existingMinReplaceValue);
1427+
journal.journalSizeMin = existingMinReplaceValue;
14391428
}
14401429

14411430
protected List<Loggable> readLatestJournalEntries() throws IOException, LogException {

exist-core/src/test/java/org/exist/storage/journal/JournalXmlTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static void storeTempXmlDocs() throws IOException {
9797
}
9898

9999
@Test
100-
public void largeJournalEntry_nonCorrupt() throws IllegalAccessException, EXistException, NoSuchFieldException, LockException, SAXException, PermissionDeniedException, IOException, InterruptedException {
100+
public void largeJournalEntry_nonCorrupt() throws EXistException, LockException, SAXException, PermissionDeniedException, IOException, InterruptedException {
101101
checkpointJournalAndSwitchFile();
102102

103103
// generate a string filled with random a-z characters which is larger than the journal buffer
@@ -126,7 +126,7 @@ public void largeJournalEntry_nonCorrupt() throws IllegalAccessException, EXistE
126126
}
127127

128128
@Test
129-
public void largeJournalEntry_corrupt() throws IllegalAccessException, EXistException, NoSuchFieldException, LockException, SAXException, PermissionDeniedException, IOException, InterruptedException {
129+
public void largeJournalEntry_corrupt() throws EXistException, LockException, SAXException, PermissionDeniedException, IOException, InterruptedException {
130130
checkpointJournalAndSwitchFile();
131131

132132
// generate a string filled with random a-z characters which is larger than the journal buffer

0 commit comments

Comments
 (0)