Skip to content

Commit

Permalink
add utframeutils log
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Xiaohua Cai <caixiaohua@starrocks.com>
  • Loading branch information
kevincai committed Feb 18, 2025
1 parent 0ae111a commit f38adfc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
24 changes: 20 additions & 4 deletions fe/fe-core/src/test/java/com/starrocks/utframe/MockedFrontend.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
import mockit.Mock;
import mockit.MockUp;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.junit.Assert;

import java.io.File;
import java.io.IOException;
Expand All @@ -65,6 +67,7 @@
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

Expand Down Expand Up @@ -99,6 +102,7 @@
*/
public class MockedFrontend {
public static final String FE_PROCESS = "fe";
private static final Logger LOG = LogManager.getLogger(MockedFrontend.class);

// the running dir of this mocked frontend.
// log/ starrocks-meta/ and conf/ dirs will be created under this dir.
Expand Down Expand Up @@ -213,11 +217,13 @@ private static class FERunnable implements Runnable {
private final String[] args;
private final boolean startBDB;
private final RunMode runMode;
private final CountDownLatch initDoneLatch;

public FERunnable(MockedFrontend frontend, boolean startBDB, RunMode runMode, String[] args) {
public FERunnable(MockedFrontend frontend, boolean startBDB, RunMode runMode, CountDownLatch initDoneLatch, String[] args) {

Check failure on line 222 in fe/fe-core/src/test/java/com/starrocks/utframe/MockedFrontend.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Line is longer than 130 characters (found 132). Raw Output: /github/workspace/./fe/fe-core/src/test/java/com/starrocks/utframe/MockedFrontend.java:222:0: error: Line is longer than 130 characters (found 132). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
this.frontend = frontend;
this.startBDB = startBDB;
this.runMode = runMode;
this.initDoneLatch = initDoneLatch;
this.args = args;
}

Expand Down Expand Up @@ -259,7 +265,7 @@ public boolean isPortUsing(String host, int port) {

GlobalStateMgr.getCurrentState().initialize(args);

if (RunMode.isSharedDataMode()) {
if (runMode == RunMode.SHARED_DATA) {
// setup and start StarManager service
Journal journal = GlobalStateMgr.getCurrentState().getJournal();
// TODO: support MockJournal in StarMgrServer
Expand All @@ -276,6 +282,9 @@ public boolean isPortUsing(String host, int port) {
StateChangeExecutor.getInstance().start();
StateChangeExecutor.getInstance().notifyNewFETypeTransfer(FrontendNodeType.LEADER);

// notify the main thread that the GlobalStateMgr instance is initialized.
initDoneLatch.countDown();

GlobalStateMgr.getCurrentState().waitForReady();

while (true) {
Expand All @@ -295,10 +304,17 @@ public void start(boolean startBDB, RunMode runMode, String[] args)
throw new NotInitException("fe process is not initialized");
}
initLock.unlock();
Thread feThread = new Thread(new FERunnable(this, startBDB, runMode, args), FE_PROCESS);
CountDownLatch initLatch = new CountDownLatch(1);
Thread feThread = new Thread(new FERunnable(this, startBDB, runMode, initLatch, args), FE_PROCESS);
feThread.start();
// initLatch.wait();
waitForCatalogReady();
System.out.println("Fe process is started");
String msg = String.format("Fe process is started with runMode: %s, expected runMode: %s, running dir: %s",
RunMode.getCurrentRunMode(), runMode, getRunningDir());
LOG.warn(msg);
System.out.printf(msg);
// make sure the runMode is up as expected
Assert.assertEquals(runMode, RunMode.getCurrentRunMode());
}

private void waitForCatalogReady() throws FeStartException {
Expand Down
11 changes: 9 additions & 2 deletions fe/fe-core/src/test/java/com/starrocks/utframe/UtFrameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,16 @@ public static synchronized void createMinStarRocksCluster(boolean startBDB, RunM
try {
ThriftConnectionPool.beHeartbeatPool = new MockGenericPool.HeatBeatPool("heartbeat");
ThriftConnectionPool.backendPool = new MockGenericPool.BackendThriftPool("backend");

List<String> stacks = LogUtil.getCurrentStackTraceToList();
StringBuilder printString = new StringBuilder();
for (String stack : stacks) {
if (stack.contains("com.starrocks.") && !stack.contains("LogUtil.java")) {
printString.append(",").append(stack);
}
}
runningDir = "fe/mocked/test/" + UUID.randomUUID().toString() + "/";
LOG.warn("Start cluster with running dir: {}, runMode: {}", runningDir, runMode);
LOG.warn("Start cluster with running dir: {}, runMode: {}, create_stack: {}", runningDir, runMode,
printString.toString());
startFEServer(runningDir, startBDB, runMode);

addMockBackend(10001);
Expand Down

0 comments on commit f38adfc

Please sign in to comment.