You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/02/22 15:26:29 UTC
[shardingsphere] branch master updated: Remove ProxyContextRestorer on agent module (#24308)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 2a61ff5e92e Remove ProxyContextRestorer on agent module (#24308)
2a61ff5e92e is described below
commit 2a61ff5e92e6a917adbc6f76a61caa057614a3a0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Feb 22 23:26:22 2023 +0800
Remove ProxyContextRestorer on agent module (#24308)
* Remove ProxyContextRestorer on prometheus module
* Remove ProxyContextRestorer on metrics core module
* Remove ProxyContextRestorer on tracing test module
---
.../plugin/metrics/core/ProxyContextRestorer.java | 38 -----------------
.../impl/proxy/ProxyMetaDataInfoExporterTest.java | 47 ++++++++++------------
.../impl/proxy/ProxyStateExporterTest.java | 29 +++++++++----
.../PrometheusPluginLifecycleServiceTest.java | 20 +++++++--
.../metrics/prometheus/ProxyContextRestorer.java | 38 -----------------
.../agent/plugin/tracing/ProxyContextRestorer.java | 38 -----------------
.../AbstractCommandExecutorTaskAdviceTest.java | 15 ++++---
.../executor/ShowProcessListExecutorTest.java | 2 +-
8 files changed, 69 insertions(+), 158 deletions(-)
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/ProxyContextRestorer.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/ProxyContextRestorer.java
deleted file mode 100644
index 8e5a26baf55..00000000000
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/ProxyContextRestorer.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.plugin.metrics.core;
-
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.junit.After;
-import org.junit.Before;
-
-public abstract class ProxyContextRestorer {
-
- private ContextManager currentContextManager;
-
- @Before
- public void recordCurrentContextManager() {
- currentContextManager = ProxyContext.getInstance().getContextManager();
- }
-
- @After
- public void restorePreviousContextManager() {
- ProxyContext.init(currentContextManager);
- }
-}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
index 06fdc86b7b9..8905fe9ddef 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.proxy;
-import org.apache.shardingsphere.agent.plugin.metrics.core.ProxyContextRestorer;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -25,18 +24,16 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.junit.After;
import org.junit.Test;
+import org.mockito.MockedStatic;
import javax.sql.DataSource;
import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -45,9 +42,10 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
-public final class ProxyMetaDataInfoExporterTest extends ProxyContextRestorer {
+public final class ProxyMetaDataInfoExporterTest {
@After
public void reset() {
@@ -57,32 +55,31 @@ public final class ProxyMetaDataInfoExporterTest extends ProxyContextRestorer {
@Test
public void assertExportWithoutContextManager() {
- ProxyContext.init(null);
- assertFalse(new ProxyMetaDataInfoExporter().export("FIXTURE").isPresent());
+ try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
+ proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(null);
+ assertFalse(new ProxyMetaDataInfoExporter().export("FIXTURE").isPresent());
+ }
}
@Test
public void assertExportWithContextManager() {
- ShardingSphereResourceMetaData resourceMetaData = mock(ShardingSphereResourceMetaData.class);
- when(resourceMetaData.getDataSources()).thenReturn(mockDataSources());
- ShardingSphereDatabase shardingSphereDatabase = mock(ShardingSphereDatabase.class);
- when(shardingSphereDatabase.getResourceMetaData()).thenReturn(resourceMetaData);
- Map<String, ShardingSphereDatabase> databases = new LinkedHashMap<>();
- databases.put("sharding_db", shardingSphereDatabase);
- ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class);
- when(shardingSphereMetaData.getDatabases()).thenReturn(databases);
- MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), shardingSphereMetaData);
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- ProxyContext.init(contextManager);
- Optional<GaugeMetricFamilyMetricsCollector> collector = new ProxyMetaDataInfoExporter().export("FIXTURE");
- assertTrue(collector.isPresent());
- assertThat(collector.get().toString(), is("database_count=1, storage_unit_count=1"));
+ ContextManager contextManager = mockContextManager();
+ try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
+ proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
+ Optional<GaugeMetricFamilyMetricsCollector> collector = new ProxyMetaDataInfoExporter().export("FIXTURE");
+ assertTrue(collector.isPresent());
+ assertThat(collector.get().toString(), is("database_count=1, storage_unit_count=1"));
+ }
}
- private Map<String, DataSource> mockDataSources() {
- Map<String, DataSource> result = new LinkedHashMap<>();
- result.put("ds_0", mock(DataSource.class));
+ private ContextManager mockContextManager() {
+ ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+ when(database.getResourceMetaData().getDataSources()).thenReturn(Collections.singletonMap("ds_0", mock(DataSource.class)));
+ ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class);
+ when(shardingSphereMetaData.getDatabases()).thenReturn(Collections.singletonMap("sharding_db", database));
+ MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), shardingSphereMetaData);
+ ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+ when(result.getMetaDataContexts()).thenReturn(metaDataContexts);
return result;
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java
index 1a36f062e19..8f45ffbaae7 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyStateExporterTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.proxy;
-import org.apache.shardingsphere.agent.plugin.metrics.core.ProxyContextRestorer;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
@@ -30,6 +29,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.state.StateContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.standalone.workerid.generator.StandaloneWorkerIdGenerator;
@@ -38,6 +38,7 @@ import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.junit.After;
import org.junit.Test;
+import org.mockito.MockedStatic;
import java.util.Collections;
import java.util.Optional;
@@ -46,9 +47,11 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
-public final class ProxyStateExporterTest extends ProxyContextRestorer {
+public final class ProxyStateExporterTest {
@After
public void reset() {
@@ -58,19 +61,29 @@ public final class ProxyStateExporterTest extends ProxyContextRestorer {
@Test
public void assertExportWithoutContextManager() {
- ProxyContext.init(null);
- assertFalse(new ProxyStateExporter().export("FIXTURE").isPresent());
+ try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
+ proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(null);
+ assertFalse(new ProxyStateExporter().export("FIXTURE").isPresent());
+ }
}
@Test
public void assertExportWithContextManager() {
+ ContextManager contextManager = mockContextManager();
+ try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
+ proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
+ proxyContext.when(() -> ProxyContext.getInstance().getStateContext()).thenReturn(Optional.of(mock(StateContext.class, RETURNS_DEEP_STUBS)));
+ Optional<GaugeMetricFamilyMetricsCollector> collector = new ProxyStateExporter().export("FIXTURE");
+ assertTrue(collector.isPresent());
+ assertThat(collector.get().toString(), is("0"));
+ }
+ }
+
+ private ContextManager mockContextManager() {
MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData());
InstanceContext instanceContext = new InstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null),
mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext());
- ProxyContext.init(new ContextManager(metaDataContexts, instanceContext));
- Optional<GaugeMetricFamilyMetricsCollector> collector = new ProxyStateExporter().export("FIXTURE");
- assertTrue(collector.isPresent());
- assertThat(collector.get().toString(), is("0"));
+ return new ContextManager(metaDataContexts, instanceContext);
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
index e894b2adc27..fe229f0e872 100644
--- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
+++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleServiceTest.java
@@ -35,14 +35,17 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.After;
import org.junit.Test;
+import org.mockito.MockedStatic;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
-public final class PrometheusPluginLifecycleServiceTest extends ProxyContextRestorer {
+public final class PrometheusPluginLifecycleServiceTest {
private final PrometheusPluginLifecycleService pluginLifecycleService = new PrometheusPluginLifecycleService();
@@ -53,12 +56,21 @@ public final class PrometheusPluginLifecycleServiceTest extends ProxyContextRest
@Test
public void assertStart() throws IOException {
+ ContextManager contextManager = mockContextManager();
+ try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
+ proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
+ pluginLifecycleService.start(new PluginConfiguration("localhost", 8090, "", PropertiesBuilder.build(new Property("JVM_INFORMATION_COLLECTOR_ENABLED", Boolean.TRUE.toString()))), true);
+ try (Socket socket = new Socket();) {
+ socket.connect(new InetSocketAddress("localhost", 8090));
+ }
+ }
+ }
+
+ private static ContextManager mockContextManager() {
MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData());
InstanceContext instanceContext = new InstanceContext(
new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null),
mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext());
- ProxyContext.init(new ContextManager(metaDataContexts, instanceContext));
- pluginLifecycleService.start(new PluginConfiguration("localhost", 8090, "", PropertiesBuilder.build(new Property("JVM_INFORMATION_COLLECTOR_ENABLED", Boolean.TRUE.toString()))), true);
- new Socket().connect(new InetSocketAddress("localhost", 8090));
+ return new ContextManager(metaDataContexts, instanceContext);
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/ProxyContextRestorer.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/ProxyContextRestorer.java
deleted file mode 100644
index 8a322a81ce7..00000000000
--- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/ProxyContextRestorer.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus;
-
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.junit.After;
-import org.junit.Before;
-
-public abstract class ProxyContextRestorer {
-
- private ContextManager currentContextManager;
-
- @Before
- public void recordCurrentContextManager() {
- currentContextManager = ProxyContext.getInstance().getContextManager();
- }
-
- @After
- public void restorePreviousContextManager() {
- ProxyContext.init(currentContextManager);
- }
-}
diff --git a/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java b/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java
deleted file mode 100644
index fe5e04c8c31..00000000000
--- a/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.plugin.tracing;
-
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.junit.After;
-import org.junit.Before;
-
-public abstract class ProxyContextRestorer {
-
- private ContextManager currentContextManager;
-
- @Before
- public void recordCurrentContextManager() {
- currentContextManager = ProxyContext.getInstance().getContextManager();
- }
-
- @After
- public void restorePreviousContextManager() {
- ProxyContext.init(currentContextManager);
- }
-}
diff --git a/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java b/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
index ed1d625ec35..3f0731ede10 100644
--- a/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
+++ b/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
@@ -21,7 +21,6 @@ import io.netty.util.DefaultAttributeMap;
import lombok.Getter;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.tracing.AgentRunner;
-import org.apache.shardingsphere.agent.plugin.tracing.ProxyContextRestorer;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -29,12 +28,14 @@ import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
import org.apache.shardingsphere.transaction.api.TransactionType;
import org.junit.runner.RunWith;
+import org.mockito.MockedStatic;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
@RunWith(AgentRunner.class)
-public abstract class AbstractCommandExecutorTaskAdviceTest extends ProxyContextRestorer implements AdviceTestBase {
+public abstract class AbstractCommandExecutorTaskAdviceTest implements AdviceTestBase {
@Getter
private TargetAdviceObject targetObject;
@@ -42,9 +43,11 @@ public abstract class AbstractCommandExecutorTaskAdviceTest extends ProxyContext
@SuppressWarnings("ConstantConditions")
@Override
public final void prepare() {
- ProxyContext.init(mock(ContextManager.class, RETURNS_DEEP_STUBS));
- ConnectionSession connectionSession = new ConnectionSession(mock(MySQLDatabaseType.class), TransactionType.BASE, new DefaultAttributeMap());
- Object executorTask = new CommandExecutorTask(null, connectionSession, null, null);
- targetObject = (TargetAdviceObject) executorTask;
+ try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
+ proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(mock(ContextManager.class, RETURNS_DEEP_STUBS));
+ ConnectionSession connectionSession = new ConnectionSession(mock(MySQLDatabaseType.class), TransactionType.BASE, new DefaultAttributeMap());
+ Object executorTask = new CommandExecutorTask(null, connectionSession, null, null);
+ targetObject = (TargetAdviceObject) executorTask;
+ }
}
}
diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcessListExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcessListExecutorTest.java
index 79b92143a47..86c27f0cd3d 100644
--- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcessListExecutorTest.java
+++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowProcessListExecutorTest.java
@@ -41,8 +41,8 @@ public final class ShowProcessListExecutorTest {
@Test
public void assertExecute() throws SQLException, ReflectiveOperationException {
+ ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
try (MockedStatic<ProxyContext> proxyContext = mockStatic(ProxyContext.class, RETURNS_DEEP_STUBS)) {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
proxyContext.when(() -> ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShowProcessListExecutor showProcessListExecutor = new ShowProcessListExecutor();
setupBatchProcessContexts(showProcessListExecutor);