GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Enhancement] Update testing framework to use Mockito and add Java 21… · APIJSON/starrocks@9ab8974

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • fe
    • fe-core
      • build.gradle.kts
      • src/test/java/com/starrocks
        • qe
          • ConnectProcessorExecuteTest.java
          • ConnectProcessorTest.java
        • sql/analyzer
          • AlterSystemStmtAnalyzerTest.java
    • fe-parser
      • build.gradle.kts
    • fe-utils
      • build.gradle.kts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎fe/fe-core/build.gradle.kts‎

Copy file name to clipboardExpand all lines: fe/fe-core/build.gradle.kts
+38-1Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ dependencies {
275275
testImplementation("org.junit.jupiter:junit-jupiter")
276276
implementation("org.mariadb.jdbc:mariadb-java-client")
277277
testImplementation("org.mockito:mockito-inline:4.11.0")
278+
// Force ByteBuddy 1.14.9+ for Java 21 class file format support
279+
testImplementation("net.bytebuddy:byte-buddy:1.14.9")
280+
testImplementation("net.bytebuddy:byte-buddy-agent:1.14.9")
278281
testImplementation("org.openjdk.jmh:jmh-core:1.37")
279282
testImplementation("org.openjdk.jmh:jmh-generator-annprocess:1.37")
280283
implementation("org.owasp.encoder:encoder")
@@ -462,10 +465,37 @@ tasks.test {
462465
systemProperty("starrocks.home", project.ext["starrocks.home"] as String)
463466

464467
// Add JMockit Java agent to JVM arguments
468+
val jmockitPath = configurations.testCompileClasspath.get().find { it.name.contains("jmockit") }?.absolutePath
465469
jvmArgs(
466470
"-Djdk.attach.allowAttachSelf",
467471
"-Duser.timezone=Asia/Shanghai",
468-
"-javaagent:${configurations.testCompileClasspath.get().find { it.name.contains("jmockit") }?.absolutePath}"
472+
"-javaagent:${jmockitPath}",
473+
// JIT tuning to match Maven surefire config
474+
"-XX:TieredStopAtLevel=1",
475+
"-XX:CICompilerCount=1",
476+
"-XX:-BackgroundCompilation",
477+
"-XX:+UseSerialGC",
478+
// Java 21 module access for JMockit/Mockito ByteBuddy
479+
// (Maven surefire 3.2.5 auto-injects these on Java 17+)
480+
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
481+
"--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED",
482+
"--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED",
483+
"--add-opens", "java.base/java.io=ALL-UNNAMED",
484+
"--add-opens", "java.base/java.math=ALL-UNNAMED",
485+
"--add-opens", "java.base/java.net=ALL-UNNAMED",
486+
"--add-opens", "java.base/java.nio=ALL-UNNAMED",
487+
"--add-opens", "java.base/java.text=ALL-UNNAMED",
488+
"--add-opens", "java.base/java.time=ALL-UNNAMED",
489+
"--add-opens", "java.base/java.util=ALL-UNNAMED",
490+
"--add-opens", "java.base/java.util.stream=ALL-UNNAMED",
491+
"--add-opens", "java.base/java.util.regex=ALL-UNNAMED",
492+
"--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED",
493+
"--add-opens", "java.base/java.util.concurrent.atomic=ALL-UNNAMED",
494+
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED",
495+
"--add-opens", "java.base/sun.security.ssl=ALL-UNNAMED",
496+
"--add-opens", "java.base/sun.security.x509=ALL-UNNAMED",
497+
"--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED",
498+
"--add-opens", "java.management/sun.management=ALL-UNNAMED",
469499
)
470500

471501
// Use independent class loading (equivalent to useSystemClassLoader=false)
@@ -498,6 +528,13 @@ tasks.withType<Checkstyle>().configureEach {
498528
maxHeapSize = "4096m"
499529
}
500530

531+
// Aggregate task that checks both main and test sources (matches Maven behavior)
532+
tasks.register("checkstyle") {
533+
dependsOn("checkstyleMain", "checkstyleTest")
534+
description = "Run Checkstyle analysis for both main and test classes"
535+
group = "verification"
536+
}
537+
501538
// Bind checkstyle to run before compilation
502539
tasks.compileJava {
503540
dependsOn("checkstyleMain")
Collapse file

‎fe/fe-core/src/test/java/com/starrocks/qe/ConnectProcessorExecuteTest.java‎

Copy file name to clipboardExpand all lines: fe/fe-core/src/test/java/com/starrocks/qe/ConnectProcessorExecuteTest.java
+47-108Lines changed: 47 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,23 @@
5151
import com.starrocks.sql.ast.PrepareStmt;
5252
import com.starrocks.thrift.TUniqueId;
5353
import com.starrocks.utframe.UtFrameUtils;
54-
import mockit.Expectations;
55-
import mockit.Mock;
56-
import mockit.MockUp;
57-
import mockit.Mocked;
5854
import org.junit.jupiter.api.Assertions;
5955
import org.junit.jupiter.api.BeforeAll;
6056
import org.junit.jupiter.api.BeforeEach;
6157
import org.junit.jupiter.api.Test;
58+
import org.mockito.MockedConstruction;
59+
import org.mockito.Mockito;
6260
import org.xnio.StreamConnection;
6361

64-
import java.io.IOException;
6562
import java.nio.ByteBuffer;
6663

64+
import static org.mockito.Mockito.anyLong;
65+
import static org.mockito.Mockito.doNothing;
66+
import static org.mockito.Mockito.doReturn;
67+
import static org.mockito.Mockito.mock;
68+
import static org.mockito.Mockito.spy;
69+
import static org.mockito.Mockito.when;
70+
6771
public class ConnectProcessorExecuteTest extends DDLTestBase {
6872
private static ByteBuffer initDbPacket;
6973
private static ByteBuffer initWarehousePacket;
@@ -76,9 +80,14 @@ public class ConnectProcessorExecuteTest extends DDLTestBase {
7680
private static AuditEventBuilder auditBuilder = new AuditEventBuilder();
7781
private static ConnectContext myContext;
7882

79-
@Mocked
8083
private static StreamConnection connection;
8184

85+
static {
86+
connection = mock(StreamConnection.class);
87+
java.net.InetSocketAddress mockAddr = new java.net.InetSocketAddress("127.0.0.1", 12345);
88+
when(connection.getPeerAddress()).thenReturn(mockAddr);
89+
}
90+
8291
private static PQueryStatistics statistics = new PQueryStatistics();
8392

8493

@@ -177,50 +186,26 @@ public void setUp() throws Exception {
177186
changeUserPacket.clear();
178187
resetConnectionPacket.clear();
179188
// Mock
180-
MysqlChannel channel = new MysqlChannel(connection);
181-
new Expectations(channel) {
182-
{
183-
channel.getRemoteHostPortString();
184-
minTimes = 0;
185-
result = "127.0.0.1:12345";
186-
}
187-
};
189+
MysqlChannel channel = mock(MysqlChannel.class);
190+
when(channel.getRemoteHostPortString()).thenReturn("127.0.0.1:12345");
188191
myContext = new ConnectContext(connection);
189192
Deencapsulation.setField(myContext, "mysqlChannel", channel);
190193
super.setUp();
191194
}
192195

193196
private static MysqlChannel mockChannel(ByteBuffer packet) {
194197
try {
195-
MysqlChannel channel = new MysqlChannel(connection);
196-
new Expectations(channel) {
197-
{
198-
// Mock receive
199-
channel.fetchOnePacket();
200-
minTimes = 0;
201-
result = packet;
202-
203-
// Mock reset
204-
channel.setSequenceId(0);
205-
times = 1;
206-
207-
// Mock send
208-
channel.sendAndFlush((ByteBuffer) any);
209-
minTimes = 0;
210-
211-
channel.getRemoteHostPortString();
212-
minTimes = 0;
213-
result = "127.0.0.1:12345";
214-
}
215-
};
198+
MysqlChannel channel = mock(MysqlChannel.class);
199+
when(channel.fetchOnePacket()).thenReturn(packet);
200+
when(channel.getRemoteHostPortString()).thenReturn("127.0.0.1:12345");
216201
return channel;
217-
} catch (IOException e) {
202+
} catch (Exception e) {
218203
return null;
219204
}
220205
}
221206

222207
private static ConnectContext initMockContext(MysqlChannel channel, GlobalStateMgr globalStateMgr) {
223-
ConnectContext context = new ConnectContext(connection) {
208+
ConnectContext context = spy(new ConnectContext(connection) {
224209
private boolean firstTimeToSetCommand = true;
225210

226211
@Override
@@ -257,67 +242,23 @@ public void setCommand(MysqlCommand command) {
257242
super.setCommand(command);
258243
}
259244
}
260-
};
261-
262-
new Expectations(context) {
263-
{
264-
context.getMysqlChannel();
265-
minTimes = 0;
266-
result = channel;
267-
268-
context.isKilled();
269-
minTimes = 0;
270-
maxTimes = 3;
271-
returns(false, true, false);
272-
273-
context.getGlobalStateMgr();
274-
minTimes = 0;
275-
result = globalStateMgr;
276-
277-
context.getAuditEventBuilder();
278-
minTimes = 0;
279-
result = auditBuilder;
280-
281-
context.getQualifiedUser();
282-
minTimes = 0;
283-
result = "testCluster:user";
284-
285-
context.getCurrentUserIdentity();
286-
minTimes = 0;
287-
result = UserIdentity.ROOT;
288-
289-
context.getStartTime();
290-
minTimes = 0;
291-
result = 0L;
292-
293-
context.getReturnRows();
294-
minTimes = 0;
295-
result = 1L;
296-
297-
context.setStmtId(anyLong);
298-
minTimes = 0;
299-
300-
context.getStmtId();
301-
minTimes = 0;
302-
result = 1L;
303-
304-
context.getExecutionId();
305-
minTimes = 0;
306-
result = new TUniqueId();
307-
308-
context.getCapability();
309-
minTimes = 0;
310-
result = MysqlCapability.DEFAULT_CAPABILITY;
311-
312-
context.getAccessControlContext();
313-
minTimes = 0;
314-
result = new AccessControlContext();
315-
316-
context.getAuthenticationProvider();
317-
minTimes = 0;
318-
result = new PlainPasswordAuthenticationProvider(MysqlPassword.EMPTY_PASSWORD);
319-
}
320-
};
245+
});
246+
247+
doReturn(channel).when(context).getMysqlChannel();
248+
doReturn(false).doReturn(true).doReturn(false).when(context).isKilled();
249+
doReturn(globalStateMgr).when(context).getGlobalStateMgr();
250+
doReturn(auditBuilder).when(context).getAuditEventBuilder();
251+
doReturn("testCluster:user").when(context).getQualifiedUser();
252+
doReturn(UserIdentity.ROOT).when(context).getCurrentUserIdentity();
253+
doReturn(0L).when(context).getStartTime();
254+
doReturn(1L).when(context).getReturnRows();
255+
doNothing().when(context).setStmtId(anyLong());
256+
doReturn(1L).when(context).getStmtId();
257+
doReturn(new TUniqueId()).when(context).getExecutionId();
258+
doReturn(MysqlCapability.DEFAULT_CAPABILITY).when(context).getCapability();
259+
doReturn(new AccessControlContext()).when(context).getAccessControlContext();
260+
doReturn(new PlainPasswordAuthenticationProvider(MysqlPassword.EMPTY_PASSWORD))
261+
.when(context).getAuthenticationProvider();
321262

322263
return context;
323264
}
@@ -340,17 +281,15 @@ public void testStmtExecute() throws Exception {
340281

341282
ConnectProcessor processor = new ConnectProcessor(ctx);
342283
// Mock statement executor
343-
// Create mock for StmtExecutor using MockUp instead of @Mocked parameter
344-
new MockUp<StmtExecutor>() {
345-
@Mock
346-
public PQueryStatistics getQueryStatisticsForAuditLog() {
347-
return statistics;
348-
}
349-
};
284+
try (MockedConstruction<StmtExecutor> mocked = Mockito.mockConstruction(StmtExecutor.class,
285+
(mock, context) -> {
286+
when(mock.getQueryStatisticsForAuditLog()).thenReturn(statistics);
287+
})) {
350288

351-
processor.processOnce();
289+
processor.processOnce();
352290

353-
Assertions.assertEquals(MysqlCommand.COM_STMT_EXECUTE, myContext.getCommand());
354-
Assertions.assertTrue(ctx.getState().isQuery());
291+
Assertions.assertEquals(MysqlCommand.COM_STMT_EXECUTE, myContext.getCommand());
292+
Assertions.assertTrue(ctx.getState().isQuery());
293+
}
355294
}
356295
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.