Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public void begin() throws RepositoryException {
@Override
public void begin(IsolationLevel level) throws RepositoryException {
try {
// Call setIsolationLevel to update the AbstractRepositoryConnection's isolation level field
setIsolationLevel(level);

// always call receiveTransactionSettings(...) before calling begin();
sailConnection.setTransactionSettings();

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

for (TransactionSetting setting : settings) {
if (setting instanceof IsolationLevel) {
// Call setIsolationLevel to update the AbstractRepositoryConnection's isolation level field
setIsolationLevel((IsolationLevel) setting);
sailConnection.begin((IsolationLevel) setting);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import java.util.Optional;

import org.eclipse.rdf4j.common.iteration.EmptyIteration;
import org.eclipse.rdf4j.common.transaction.IsolationLevel;
import org.eclipse.rdf4j.common.transaction.IsolationLevels;
import org.eclipse.rdf4j.query.BooleanQuery;
import org.eclipse.rdf4j.query.GraphQuery;
import org.eclipse.rdf4j.query.Query;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.algebra.QueryRoot;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.query.explanation.Explanation;
import org.eclipse.rdf4j.sail.Sail;
import org.eclipse.rdf4j.sail.SailConnection;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -169,4 +172,47 @@ public void testExplainQuery() {
anyBoolean(), anyInt());
}

@Test
public void testGetIsolationLevel_shouldReturnSetLevel() {
// Test that getIsolationLevel() returns the level set via begin(IsolationLevel)
assertThat(subject.getIsolationLevel()).isNull();

subject.begin(IsolationLevels.SERIALIZABLE);
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.SERIALIZABLE);

subject.rollback();

subject.begin(IsolationLevels.READ_COMMITTED);
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.READ_COMMITTED);

subject.rollback();
}

@Test
public void testGetIsolationLevel_shouldReturnSetLevelFromTransactionSettings() {
// Test that getIsolationLevel() returns the level set via begin(TransactionSetting...)
assertThat(subject.getIsolationLevel()).isNull();

subject.begin(IsolationLevels.READ_UNCOMMITTED);
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.READ_UNCOMMITTED);

subject.rollback();
}

@Test
public void testGetIsolationLevel_shouldReturnDefaultLevelWhenNotExplicitlySet() {
// Test that getIsolationLevel() returns the default isolation level when begin() is called without parameters
assertThat(subject.getIsolationLevel()).isNull();

// Create a mock sail that returns the default isolation level
Sail mockSail = mock(Sail.class);
when(mockSail.getDefaultIsolationLevel()).thenReturn(IsolationLevels.READ_COMMITTED);
when(sailRepository.getSail()).thenReturn(mockSail);

subject.begin();
assertThat(subject.getIsolationLevel()).isEqualTo(IsolationLevels.READ_COMMITTED);

subject.rollback();
}

}
Loading