This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 91e4f3f4cad Add full coverage for session and dist variable handlers
(#37563)
91e4f3f4cad is described below
commit 91e4f3f4cad1f7f00b98259f504887fc297bf3e9
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 28 22:21:10 2025 +0800
Add full coverage for session and dist variable handlers (#37563)
* Add full coverage for session and dist variable handlers
* Add full coverage for session and dist variable handlers
---
AGENTS.md | 1 +
.../transaction/LocalTransactionManagerTest.java | 53 ++++++++++++++++++
.../SetComputeNodeStateExecutorTest.java | 40 +++++++++++++-
.../variable/SetDistVariableExecutorTest.java | 33 +++++++++--
.../xa/type/XABeginProxyBackendHandlerTest.java | 3 +-
.../backend/session/ConnectionSessionTest.java | 64 ++++++++++++++++++++--
6 files changed, 181 insertions(+), 13 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index acef641a119..4d570f81438 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -220,6 +220,7 @@ Always state which topology, registry, and engine versions
(e.g., MySQL 5.7 vs 8
- When static methods or constructors need mocking, prefer
`@ExtendWith(AutoMockExtension.class)` with `@StaticMockSettings` (or the
extension’s constructor-mocking support); when a class is listed in
`@StaticMockSettings`, do not call `mockStatic`/`mockConstruction`
directly—stub via `when(...)` instead. Only if AutoMockExtension cannot be used
and the reason is documented in the plan may you fall back to
`mockStatic`/`mockConstruction`, wrapped in try-with-resources.
- Before coding tests, follow the Coverage & Branch Checklist to map
inputs/branches to planned assertions.
- When a component is available via SPI (e.g., `TypedSPILoader`,
`DatabaseTypedSPILoader`, `PushDownMetaDataRefresher`), obtain the instance
through SPI by default; note any exceptions in the plan.
+- If the class under test implements `TypedSPI` or `DatabaseTypedSPI`,
instantiate it via `TypedSPILoader` or `DatabaseTypedSPILoader` instead of
calling `new` directly.
- Do not mix Mockito matchers with raw arguments; choose a single style per
invocation, and ensure the Mockito extension aligns with the mocking approach.
- Compliance is mandatory: before any coding, re-read AGENTS.md and convert
all hard requirements (SPI usage, no FQCN, mocking rules, coverage targets,
planning steps) into a checklist in the plan; do not proceed or report
completion until every item is satisfied or explicitly waived by the user.
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
index 0cfea7ecc41..c015a32fa2b 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
@@ -35,9 +35,16 @@ import org.mockito.quality.Strictness;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@@ -59,6 +66,9 @@ class LocalTransactionManagerTest {
@Mock
private Connection connection;
+ @Mock
+ private Connection anotherConnection;
+
private LocalTransactionManager localTransactionManager;
@BeforeEach
@@ -92,10 +102,53 @@ class LocalTransactionManagerTest {
verify(connection).commit();
}
+ @Test
+ void assertCommitWithExceptionOccur() throws SQLException {
+
when(connectionContext.getTransactionContext().isExceptionOccur()).thenReturn(true);
+ localTransactionManager.commit();
+ verify(connection).rollback();
+ }
+
+ @Test
+ void assertCommitWithSQLExceptionChain() throws SQLException {
+
when(connectionContext.getTransactionContext().isExceptionOccur()).thenReturn(false);
+ Multimap<String, Connection> cachedConnections = HashMultimap.create();
+ cachedConnections.put("ds1", connection);
+ cachedConnections.put("ds2", anotherConnection);
+
when(databaseConnectionManager.getCachedConnections()).thenReturn(cachedConnections);
+ SQLException first = new SQLException("first");
+ SQLException second = new SQLException("second");
+ doThrow(first).when(connection).commit();
+ doThrow(second).when(anotherConnection).commit();
+ SQLException actual = assertThrows(SQLException.class, () ->
localTransactionManager.commit());
+ assertThat(new HashSet<>(Arrays.asList(actual.getMessage(),
actual.getNextException().getMessage())), is(new
HashSet<>(Arrays.asList("first", "second"))));
+ }
+
@Test
void assertRollback() throws SQLException {
localTransactionManager.rollback();
verify(transactionStatus).isInTransaction();
verify(connection).rollback();
}
+
+ @Test
+ void assertRollbackWithoutInTransaction() throws SQLException {
+ when(transactionStatus.isInTransaction()).thenReturn(false);
+ localTransactionManager.rollback();
+ verify(connection, never()).rollback();
+ }
+
+ @Test
+ void assertRollbackWithSQLExceptionChain() throws SQLException {
+ Multimap<String, Connection> cachedConnections = HashMultimap.create();
+ cachedConnections.put("ds1", connection);
+ cachedConnections.put("ds2", anotherConnection);
+
when(databaseConnectionManager.getCachedConnections()).thenReturn(cachedConnections);
+ SQLException first = new SQLException("first");
+ SQLException second = new SQLException("second");
+ doThrow(first).when(connection).rollback();
+ doThrow(second).when(anotherConnection).rollback();
+ SQLException actual = assertThrows(SQLException.class, () ->
localTransactionManager.rollback());
+ assertThat(new HashSet<>(Arrays.asList(actual.getMessage(),
actual.getNextException().getMessage())), is(new
HashSet<>(Arrays.asList("first", "second"))));
+ }
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/computenode/SetComputeNodeStateExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/computenode/SetComputeNodeStateExecutorTest.java
index dc15b11a660..28feb0f9f26 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/computenode/SetComputeNodeStateExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/computenode/SetComputeNodeStateExecutorTest.java
@@ -17,20 +17,27 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.computenode;
+import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor;
import
org.apache.shardingsphere.distsql.statement.type.ral.updatable.SetComputeNodeStateStatement;
import
org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
+import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.state.instance.InstanceState;
import org.apache.shardingsphere.mode.manager.ContextManager;
+import
org.apache.shardingsphere.mode.manager.cluster.persist.facade.ClusterPersistServiceFacade;
import org.junit.jupiter.api.Test;
+import java.util.Optional;
+
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class SetComputeNodeStateExecutorTest {
- private final SetComputeNodeStateExecutor executor = new
SetComputeNodeStateExecutor();
+ private final SetComputeNodeStateExecutor executor =
(SetComputeNodeStateExecutor)
TypedSPILoader.getService(DistSQLUpdateExecutor.class,
SetComputeNodeStateStatement.class);
@Test
void assertExecuteUpdateWithNotExistsInstanceID() {
@@ -53,4 +60,35 @@ class SetComputeNodeStateExecutorTest {
.thenReturn(InstanceState.CIRCUIT_BREAK);
assertThrows(UnsupportedSQLOperationException.class, () ->
executor.executeUpdate(new SetComputeNodeStateStatement("DISABLE",
"instanceID"), contextManager));
}
+
+ @Test
+ void assertExecuteUpdateWithDisableInstance() {
+ ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
+
when(contextManager.getComputeNodeInstanceContext().getInstance().getMetaData().getId()).thenReturn("currentInstance");
+ ComputeNodeInstance computeNodeInstance =
mock(ComputeNodeInstance.class, RETURNS_DEEP_STUBS);
+
when(computeNodeInstance.getState().getCurrentState()).thenReturn(InstanceState.OK);
+
when(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find("instanceID")).thenReturn(Optional.of(computeNodeInstance));
+ ClusterPersistServiceFacade clusterPersistServiceFacade =
mock(ClusterPersistServiceFacade.class, RETURNS_DEEP_STUBS);
+
when(contextManager.getPersistServiceFacade().getModeFacade()).thenReturn(clusterPersistServiceFacade);
+ executor.executeUpdate(new SetComputeNodeStateStatement("DISABLE",
"instanceID"), contextManager);
+
verify(clusterPersistServiceFacade.getComputeNodeService()).updateState("instanceID",
InstanceState.CIRCUIT_BREAK);
+ }
+
+ @Test
+ void assertExecuteUpdateWithEnableInstance() {
+ ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
+
when(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find("instanceID")).thenReturn(Optional.of(mock(ComputeNodeInstance.class)));
+ ClusterPersistServiceFacade clusterPersistServiceFacade =
mock(ClusterPersistServiceFacade.class, RETURNS_DEEP_STUBS);
+
when(contextManager.getPersistServiceFacade().getModeFacade()).thenReturn(clusterPersistServiceFacade);
+ executor.executeUpdate(new SetComputeNodeStateStatement("ENABLE",
"instanceID"), contextManager);
+
verify(clusterPersistServiceFacade.getComputeNodeService()).updateState("instanceID",
InstanceState.OK);
+ }
+
+ @Test
+ void assertExecuteUpdateWithDisableNotExistsInstance() {
+ ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
+
when(contextManager.getComputeNodeInstanceContext().getInstance().getMetaData().getId()).thenReturn("currentInstance");
+
when(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find("instanceID")).thenReturn(Optional.empty());
+ assertThrows(UnsupportedSQLOperationException.class, () ->
executor.executeUpdate(new SetComputeNodeStateStatement("DISABLE",
"instanceID"), contextManager));
+ }
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
index 52cc934acfa..e511ab669f0 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
@@ -18,35 +18,37 @@
package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.variable;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor;
import
org.apache.shardingsphere.distsql.statement.type.ral.updatable.SetDistVariableStatement;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
+import
org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException;
+import
org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade;
import
org.apache.shardingsphere.mode.metadata.persist.config.global.PropertiesPersistService;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.jupiter.MockitoExtension;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@ExtendWith(MockitoExtension.class)
class SetDistVariableExecutorTest {
- private final SetDistVariableExecutor executor = new
SetDistVariableExecutor();
+ private final SetDistVariableExecutor executor = (SetDistVariableExecutor)
TypedSPILoader.getService(DistSQLUpdateExecutor.class,
SetDistVariableStatement.class);
@Test
void assertExecuteWithConfigurationKey() {
@@ -73,6 +75,29 @@ class SetDistVariableExecutorTest {
assertThat(((DatabaseType)
contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE)).getType(),
is("FIXTURE"));
}
+ @Test
+ void assertExecuteWithUnsupportedVariable() {
+ assertThrows(UnsupportedVariableException.class, () ->
executor.executeUpdate(new SetDistVariableStatement("unknown", "1"),
mockContextManager()));
+ }
+
+ @Test
+ void assertExecuteWithInvalidValue() {
+ assertThrows(InvalidVariableValueException.class, () ->
executor.executeUpdate(new
SetDistVariableStatement("proxy_frontend_flush_threshold", "invalid"),
mockContextManager()));
+ }
+
+ @Test
+ void assertExecuteWithCronVariable() {
+ ContextManager contextManager = mockContextManager();
+ SetDistVariableStatement statement = new
SetDistVariableStatement("proxy_meta_data_collector_cron", "0 0/5 * * * ?");
+ executor.executeUpdate(statement, contextManager);
+
assertThat(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps().getProps().getProperty("proxy-meta-data-collector-cron"),
is("0 0/5 * * * ?"));
+ }
+
+ @Test
+ void assertExecuteWithInvalidCronVariable() {
+ assertThrows(InvalidVariableValueException.class, () ->
executor.executeUpdate(new
SetDistVariableStatement("proxy_meta_data_collector_cron", "invalid"),
mockContextManager()));
+ }
+
private ContextManager mockContextManager() {
MetaDataPersistFacade metaDataPersistFacade =
mock(MetaDataPersistFacade.class, RETURNS_DEEP_STUBS);
when(metaDataPersistFacade.getPropsService()).thenReturn(mock(PropertiesPersistService.class));
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/xa/type/XABeginProxyBackendHandlerTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/xa/type/XABeginProxyBackendHandlerTest.java
index d202a173434..9598bfa97af 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/xa/type/XABeginProxyBackendHandlerTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/xa/type/XABeginProxyBackendHandlerTest.java
@@ -51,8 +51,7 @@ class XABeginProxyBackendHandlerTest {
when(transactionRule.getDefaultType()).thenReturn(TransactionType.XA);
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
when(metaData.getGlobalRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(transactionRule)));
- XABeginProxyBackendHandler handler = new
XABeginProxyBackendHandler(metaData, connectionSession, databaseProxyConnector);
- assertThat(handler.execute(), is(expected));
+ assertThat(new XABeginProxyBackendHandler(metaData, connectionSession,
databaseProxyConnector).execute(), is(expected));
assertTrue(transactionContext.isTransactionStarted());
assertThat(transactionContext.getTransactionType().orElse(""),
is(TransactionType.XA.name()));
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
index 1eae0450c08..cf97fd94c62 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
@@ -19,11 +19,13 @@ package org.apache.shardingsphere.proxy.backend.session;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import
org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.ProxyBackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import
org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
import org.apache.shardingsphere.transaction.api.TransactionType;
@@ -32,10 +34,10 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoSettings;
-import org.mockito.quality.Strictness;
+import org.mockito.internal.configuration.plugins.Plugins;
import java.util.Collections;
+import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -44,12 +46,14 @@ import static
org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(ProxyContext.class)
-@MockitoSettings(strictness = Strictness.LENIENT)
class ConnectionSessionTest {
@Mock
@@ -61,7 +65,7 @@ class ConnectionSessionTest {
void setup() {
connectionSession = new ConnectionSession(mock(), null);
connectionSession.setGrantee(mock(Grantee.class));
-
when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+
lenient().when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
}
@Test
@@ -70,6 +74,42 @@ class ConnectionSessionTest {
assertThat(connectionSession.getUsedDatabaseName(),
is("currentDatabase"));
}
+ @Test
+ void assertSetCurrentSchemaWithSameName() throws
ReflectiveOperationException {
+ ConnectionContext contextMock = mock(ConnectionContext.class);
+ getConnectionContextReference().set(contextMock);
+ connectionSession.setCurrentDatabaseName("db");
+ verify(contextMock, times(1)).setCurrentDatabaseName("db");
+ }
+
+ @Test
+ void assertSetCurrentSchemaWithNull() throws ReflectiveOperationException {
+ connectionSession.setCurrentDatabaseName("db");
+ ConnectionContext contextMock = mock(ConnectionContext.class);
+ getConnectionContextReference().set(contextMock);
+ connectionSession.setCurrentDatabaseName(null);
+ assertNull(connectionSession.getCurrentDatabaseName());
+ verify(contextMock).setCurrentDatabaseName(null);
+ }
+
+ @Test
+ void assertGetUsedDatabaseNameFromQueryContext() {
+ connectionSession.setCurrentDatabaseName("currentDatabase");
+ QueryContext queryContext = mock(QueryContext.class);
+
when(queryContext.getUsedDatabaseNames()).thenReturn(Collections.singleton("used_db"));
+ connectionSession.setQueryContext(queryContext);
+ assertThat(connectionSession.getUsedDatabaseName(), is("used_db"));
+ }
+
+ @Test
+ void assertGetUsedDatabaseNameWhenQueryContextEmpty() {
+ connectionSession.setCurrentDatabaseName("currentDatabase");
+ QueryContext queryContext = mock(QueryContext.class);
+
when(queryContext.getUsedDatabaseNames()).thenReturn(Collections.emptySet());
+ connectionSession.setQueryContext(queryContext);
+ assertThat(connectionSession.getUsedDatabaseName(),
is("currentDatabase"));
+ }
+
@Test
void assertSwitchSchemaWhileBegin() {
connectionSession.setCurrentDatabaseName("db");
@@ -89,16 +129,23 @@ class ConnectionSessionTest {
}
@Test
- void assertDefaultAutocommit() {
+ void assertDefaultAutoCommit() {
assertTrue(connectionSession.isAutoCommit());
}
@Test
- void assertSetAutocommit() {
+ void assertSetAutoCommit() {
connectionSession.setAutoCommit(false);
assertFalse(connectionSession.isAutoCommit());
}
+ @Test
+ void assertGetIsolationLevel() {
+
connectionSession.setIsolationLevel(TransactionIsolationLevel.READ_COMMITTED);
+ assertTrue(connectionSession.getIsolationLevel().isPresent());
+ assertThat(connectionSession.getIsolationLevel().get(),
is(TransactionIsolationLevel.READ_COMMITTED));
+ }
+
@Test
void assertClearQueryContext() {
connectionSession.setQueryContext(mock(QueryContext.class));
@@ -106,4 +153,9 @@ class ConnectionSessionTest {
connectionSession.clearQueryContext();
assertNull(connectionSession.getQueryContext());
}
+
+ @SuppressWarnings("unchecked")
+ private AtomicReference<ConnectionContext> getConnectionContextReference()
throws ReflectiveOperationException {
+ return (AtomicReference<ConnectionContext>)
Plugins.getMemberAccessor().get(ConnectionSession.class.getDeclaredField("connectionContext"),
connectionSession);
+ }
}