github-actions[bot] commented on code in PR #62221:
URL: https://github.com/apache/doris/pull/62221#discussion_r3061680199
##########
fe/fe-core/src/test/java/org/apache/doris/alter/CloudIndexTest.java:
##########
@@ -91,136 +93,147 @@ public class CloudIndexTest {
private static CancelBuildIndexCommand cancelBuildIndexCommand;
private static SchemaChangeHandler schemaChangeHandler;
- @Before
- public void setUp() throws InstantiationException, IllegalAccessException,
IllegalArgumentException,
- InvocationTargetException, NoSuchMethodException,
SecurityException, UserException {
- FeConstants.runningUnitTest = true;
- // Setup for MetaServiceProxy mock
- new MockUp<MetaServiceProxy>(MetaServiceProxy.class) {
-
- @Mock
- public Cloud.BeginTxnResponse beginTxn(Cloud.BeginTxnRequest
request) {
- Cloud.BeginTxnResponse.Builder beginTxnResponseBuilder =
Cloud.BeginTxnResponse.newBuilder();
- beginTxnResponseBuilder.setTxnId(1000)
- .setStatus(
-
Cloud.MetaServiceResponseStatus.newBuilder().setCode(MetaServiceCode.OK).setMsg("OK"));
- return beginTxnResponseBuilder.build();
- }
-
- @Mock
- public Cloud.CommitTxnResponse commitTxn(Cloud.CommitTxnRequest
request) {
- Cloud.TxnInfoPB.Builder txnInfoBuilder =
Cloud.TxnInfoPB.newBuilder();
- txnInfoBuilder.setDbId(CatalogTestUtil.testDbId1);
-
txnInfoBuilder.addAllTableIds(Lists.newArrayList(olapTable.getId()));
- txnInfoBuilder.setLabel("test_label");
- txnInfoBuilder.setListenerId(-1);
- Cloud.CommitTxnResponse.Builder commitTxnResponseBuilder =
Cloud.CommitTxnResponse.newBuilder();
-
commitTxnResponseBuilder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"))
- .setTxnInfo(txnInfoBuilder.build());
- return commitTxnResponseBuilder.build();
- }
-
- @Mock
- public Cloud.CheckTxnConflictResponse
checkTxnConflict(Cloud.CheckTxnConflictRequest request) {
- Cloud.CheckTxnConflictResponse.Builder
checkTxnConflictResponseBuilder =
- Cloud.CheckTxnConflictResponse.newBuilder();
-
checkTxnConflictResponseBuilder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"))
- .setFinished(true);
- return checkTxnConflictResponseBuilder.build();
- }
-
- @Mock
- public Cloud.GetClusterResponse getCluster(Cloud.GetClusterRequest
request) {
- Cloud.GetClusterResponse.Builder getClusterResponseBuilder =
Cloud.GetClusterResponse.newBuilder();
- Cloud.ClusterPB.Builder clusterBuilder =
Cloud.ClusterPB.newBuilder();
-
clusterBuilder.setClusterId("test_id").setClusterName("test_group");
-
- Cloud.NodeInfoPB.Builder node1 = Cloud.NodeInfoPB.newBuilder();
- node1.setCloudUniqueId("test_cloud")
- .setName("host1")
- .setIp("host1")
- .setHost("host1")
- .setHeartbeatPort(123)
- .setEditLogPort(125)
- .setStatus(Cloud.NodeStatusPB.NODE_STATUS_RUNNING);
- clusterBuilder.addNodes(node1.build());
-
getClusterResponseBuilder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"))
- .addCluster(clusterBuilder.build());
- return getClusterResponseBuilder.build();
- }
-
- @Mock
- public Cloud.CreateTabletsResponse
createTablets(Cloud.CreateTabletsRequest request) {
- Cloud.CreateTabletsResponse.Builder responseBuilder =
Cloud.CreateTabletsResponse.newBuilder();
- responseBuilder.setStatus(
-
Cloud.MetaServiceResponseStatus.newBuilder().setCode(MetaServiceCode.OK).setMsg("OK"));
- return responseBuilder.build();
- }
+ private MockedStatic<MetaServiceProxy> mockedMetaServiceProxy;
+ private MetaServiceProxy mockProxy;
- @Mock
- public Cloud.FinishTabletJobResponse
finishTabletJob(Cloud.FinishTabletJobRequest request) {
- Cloud.FinishTabletJobResponse.Builder responseBuilder =
Cloud.FinishTabletJobResponse.newBuilder();
- responseBuilder.setStatus(
-
Cloud.MetaServiceResponseStatus.newBuilder().setCode(MetaServiceCode.OK).setMsg("OK"));
- return responseBuilder.build();
- }
-
- @Mock
- public Cloud.IndexResponse prepareIndex(Cloud.IndexRequest
request) {
- Cloud.IndexResponse.Builder builder =
Cloud.IndexResponse.newBuilder();
- builder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"));
- return builder.build();
- }
-
- @Mock
- public Cloud.IndexResponse commitIndex(Cloud.IndexRequest request)
{
- Cloud.IndexResponse.Builder builder =
Cloud.IndexResponse.newBuilder();
- builder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"));
- return builder.build();
- }
-
- @Mock
- public Cloud.IndexResponse dropIndex(Cloud.IndexRequest request) {
- Cloud.IndexResponse.Builder builder =
Cloud.IndexResponse.newBuilder();
- builder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"));
- return builder.build();
- }
+ private static void setField(Object target, Class<?> clazz, String
fieldName, Object value)
+ throws Exception {
+ Field field = clazz.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ field.set(target, value);
+ }
- @Mock
- public Cloud.CheckKVResponse checkKv(Cloud.CheckKVRequest request)
{
- Cloud.CheckKVResponse.Builder builder =
Cloud.CheckKVResponse.newBuilder();
- builder.setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
- .setCode(MetaServiceCode.OK).setMsg("OK"));
- return builder.build();
- }
+ @After
+ public void tearDown() {
+ if (mockedMetaServiceProxy != null) {
+ mockedMetaServiceProxy.close();
+ }
+ if (fakeEditLog != null) {
+ fakeEditLog.close();
Review Comment:
`FakeEnv` and `FakeEditLog` now wrap `MockedStatic`/`MockedConstruction`, so
closing only the current field value in `tearDown()` is not sufficient here.
`setUp()` creates both helpers, and several tests later overwrite the same
fields before `tearDown()` runs. That drops the original handles without
closing them, which can leave the static/constructor mocks active for later
tests. Please either avoid creating these helpers in `setUp()` when each test
creates its own instance, or close the old value before every reassignment.
##########
fe/fe-core/src/test/java/org/apache/doris/alter/IndexChangeJobTest.java:
##########
@@ -99,16 +101,28 @@ public void setUp()
slaveTransMgr.setEditLog(slaveEnv.getEditLog());
// Initialize ConnectContext
ctx = new ConnectContext();
- new MockUp<ConnectContext>() {
- @Mock
- public ConnectContext get() {
- return ctx;
- }
- };
+ mockedConnectContext = Mockito.mockStatic(ConnectContext.class);
+ mockedConnectContext.when(ConnectContext::get).thenReturn(ctx);
FeConstants.runningUnitTest = true;
AgentTaskQueue.clearAllTasks();
}
+ @After
+ public void tearDown() {
+ if (mockedConnectContext != null) {
+ mockedConnectContext.close();
+ }
+ if (fakeEnv != null) {
+ fakeEnv.close();
Review Comment:
This `tearDown()` only closes the last assigned helper instances, but many
tests in this file reassign `fakeEnv`/`fakeEditLog` after `setUp()` has already
created them. Since these helpers now own Mockito static/construction mocks,
the overwritten setup instances are leaked and can contaminate later tests. The
old instance needs to be closed before reassignment, or the helpers should only
be created once per test path.
##########
fe/fe-core/src/test/java/org/apache/doris/alter/RollupJobV2Test.java:
##########
@@ -114,18 +112,22 @@ public void setUp() throws InstantiationException,
IllegalAccessException, Illeg
FeConstants.runningUnitTest = true;
AgentTaskQueue.clearAllTasks();
- new MockUp<Env>() {
- @Mock
- public Env getCurrentEnv() {
- return masterEnv;
- }
- };
+ FakeEnv.setEnv(masterEnv);
}
@After
public void tearDown() {
File file = new File(fileName);
file.delete();
+ if (fakeEnv != null) {
+ fakeEnv.close();
Review Comment:
Same lifecycle issue as the other alter tests: `setUp()` creates
`FakeEnv`/`FakeEditLog`/`FakeTransactionIDGenerator`, but several tests replace
those fields before `tearDown()` executes. After the Mockito migration that
leaks the original `MockedStatic`/`MockedConstruction` handles, so later tests
can observe stale mocks.
##########
fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeJobV2Test.java:
##########
@@ -124,6 +124,19 @@ public void setUp()
AgentTaskQueue.clearAllTasks();
}
+ @After
+ public void tearDown() {
+ if (fakeEnv != null) {
+ fakeEnv.close();
Review Comment:
These close calls only cover the current field values. In this file,
multiple tests overwrite `fakeEnv`/`fakeEditLog` after `setUp()` has already
instantiated them, so the earlier helper objects are never closed. Because the
migrated helpers now hold Mockito static/construction mocks, that can leak
state across tests and make the suite flaky.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]