Skip to content

Commit c14c3a9

Browse files
Copilothmottestad
andcommitted
Fix SailRepositoryConnection to properly set isolation level in getIsolationLevel()
Co-authored-by: hmottestad <797185+hmottestad@users.noreply.github.com>
1 parent 1670ce0 commit c14c3a9

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

core/repository/sail/src/main/java/org/eclipse/rdf4j/repository/sail/SailRepositoryConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public void begin() throws RepositoryException {
168168
@Override
169169
public void begin(IsolationLevel level) throws RepositoryException {
170170
try {
171+
// Call setIsolationLevel to update the AbstractRepositoryConnection's isolation level field
172+
setIsolationLevel(level);
173+
171174
// always call receiveTransactionSettings(...) before calling begin();
172175
sailConnection.setTransactionSettings();
173176

@@ -195,6 +198,8 @@ public void begin(TransactionSetting... settings) {
195198

196199
for (TransactionSetting setting : settings) {
197200
if (setting instanceof IsolationLevel) {
201+
// Call setIsolationLevel to update the AbstractRepositoryConnection's isolation level field
202+
setIsolationLevel((IsolationLevel) setting);
198203
sailConnection.begin((IsolationLevel) setting);
199204
return;
200205
}

core/repository/sail/src/test/java/org/eclipse/rdf4j/repository/sail/SailRepositoryConnectionTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.Optional;
2323

2424
import org.eclipse.rdf4j.common.iteration.EmptyIteration;
25+
import org.eclipse.rdf4j.common.transaction.IsolationLevel;
26+
import org.eclipse.rdf4j.common.transaction.IsolationLevels;
2527
import org.eclipse.rdf4j.query.BooleanQuery;
2628
import org.eclipse.rdf4j.query.GraphQuery;
2729
import org.eclipse.rdf4j.query.Query;
@@ -169,4 +171,31 @@ public void testExplainQuery() {
169171
anyBoolean(), anyInt());
170172
}
171173

174+
@Test
175+
public void testGetIsolationLevel_shouldReturnSetLevel() {
176+
// Test that getIsolationLevel() returns the level set via begin(IsolationLevel)
177+
assertThat(subject.getIsolationLevel()).isNull();
178+
179+
subject.begin(IsolationLevels.SERIALIZABLE);
180+
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.SERIALIZABLE);
181+
182+
subject.rollback();
183+
184+
subject.begin(IsolationLevels.READ_COMMITTED);
185+
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.READ_COMMITTED);
186+
187+
subject.rollback();
188+
}
189+
190+
@Test
191+
public void testGetIsolationLevel_shouldReturnSetLevelFromTransactionSettings() {
192+
// Test that getIsolationLevel() returns the level set via begin(TransactionSetting...)
193+
assertThat(subject.getIsolationLevel()).isNull();
194+
195+
subject.begin(IsolationLevels.READ_UNCOMMITTED);
196+
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.READ_UNCOMMITTED);
197+
198+
subject.rollback();
199+
}
200+
172201
}

initial-evidence.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
-------------------------------------------------------------------------------
2+
Test set: org.eclipse.rdf4j.repository.sail.SailRepositoryConnectionTest
3+
-------------------------------------------------------------------------------
4+
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.776 s <<< FAILURE! -- in org.eclipse.rdf4j.repository.sail.SailRepositoryConnectionTest
5+
org.eclipse.rdf4j.repository.sail.SailRepositoryConnectionTest.testGetIsolationLevel_shouldReturnSetLevel -- Time elapsed: 0.755 s <<< FAILURE!
6+
org.opentest4j.AssertionFailedError:
7+
8+
expected: SERIALIZABLE
9+
but was: null
10+
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
11+
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
12+
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
13+
at org.eclipse.rdf4j.repository.sail.SailRepositoryConnectionTest.testGetIsolationLevel_shouldReturnSetLevel(SailRepositoryConnectionTest.java:180)
14+
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15+
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
16+
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17+
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
18+
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
19+
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
20+
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
21+
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
22+
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
23+
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
24+
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
25+
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
26+
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
27+
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
28+
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
29+
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
30+
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
31+
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
32+
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
33+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
34+
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
35+
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
36+
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
37+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
38+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
39+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
40+
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
41+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
42+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
43+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
44+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
45+
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
46+
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
47+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
48+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
49+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
50+
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
51+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
52+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
53+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
54+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
55+
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
56+
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
57+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
58+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
59+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
60+
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
61+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
62+
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
63+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
64+
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
65+
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
66+
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
67+
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
68+
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
69+
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
70+
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
71+
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
72+
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
73+
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
74+
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
75+
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
76+
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
77+
at org.apache.maven.surefire.junitplatform.LauncherAdapter.executeWithoutCancellationToken(LauncherAdapter.java:60)
78+
at org.apache.maven.surefire.junitplatform.LauncherAdapter.execute(LauncherAdapter.java:52)
79+
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:203)
80+
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:168)
81+
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:136)
82+
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
83+
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
84+
at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
85+
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
86+

0 commit comments

Comments
 (0)