Skip to content

Commit

Permalink
[MINOR] improvement(test): Move the logic of log uploading to the cla…
Browse files Browse the repository at this point in the history
…ss of doris container (#2858)

### What changes were proposed in this pull request?

Move the logic of log uploading to the class of Doris container

### Why are the changes needed?

If we have multiple Doris integration tests in one instance, the log
will not be uploaded as expected.

### Does this PR introduce _any_ user-facing change?

N/A.

### How was this patch tested?

N/A
  • Loading branch information
yuqi1129 authored Apr 9, 2024
1 parent 6bc084e commit abcfa96
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,16 @@
import com.datastrato.gravitino.integration.test.container.ContainerSuite;
import com.datastrato.gravitino.integration.test.container.DorisContainer;
import com.google.common.collect.Maps;
import java.io.File;
import java.util.Collections;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;

public class TestDorisAbstractIT extends TestJdbcAbstractIT {
private static final Logger LOG = LoggerFactory.getLogger(TestDorisAbstractIT.class);

private static final ContainerSuite containerSuite = ContainerSuite.getInstance();
protected static final String DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";

private static final String DORIS_FE_PATH = "/opt/apache-doris/fe/";
private static final String DORIS_BE_PATH = "/opt/apache-doris/be/";

@BeforeAll
public static void startup() {
containerSuite.startDorisContainer();
Expand All @@ -55,25 +46,6 @@ public static void startup() {
// Overwrite the stop method to close the data source and stop the container
@AfterAll
public static void stop() {
try {
GenericContainer<?> dorisContainer = containerSuite.getDorisContainer().getContainer();
// stop Doris container
String destPath = System.getenv("IT_PROJECT_DIR");
LOG.info("Copy doris log file to {}", destPath);

String feTarPath = "/doris-be.tar";
String beTarPath = "/doris-fe.tar";

// Pack the jar files
dorisContainer.execInContainer("tar", "cf", feTarPath, DORIS_BE_PATH + "log");
dorisContainer.execInContainer("tar", "cf", beTarPath, DORIS_FE_PATH + "log");

dorisContainer.copyFileFromContainer(feTarPath, destPath + File.separator + "doris-be.tar");
dorisContainer.copyFileFromContainer(beTarPath, destPath + File.separator + "doris-fe.tar");
} catch (Exception e) {
LOG.error("Failed to copy container log to local", e);
}

DataSourceUtils.closeDataSource(DATA_SOURCE);
if (null != CONTAINER) {
CONTAINER.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static java.lang.String.format;

import com.google.common.collect.ImmutableSet;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
Expand All @@ -30,6 +31,9 @@ public class DorisContainer extends BaseContainer {
public static final int FE_HTTP_PORT = 8030;
public static final int FE_MYSQL_PORT = 9030;

private static final String DORIS_FE_PATH = "/opt/apache-doris/fe/log";
private static final String DORIS_BE_PATH = "/opt/apache-doris/be/log";

public static Builder builder() {
return new Builder();
}
Expand All @@ -54,9 +58,33 @@ protected void setupContainer() {

@Override
public void start() {
super.start();
Preconditions.check("Doris container startup failed!", checkContainerStatus(5));
Preconditions.check("Doris container password change failed!", changePassword());
try {
super.start();
Preconditions.check("Doris container startup failed!", checkContainerStatus(5));
Preconditions.check("Doris container password change failed!", changePassword());
} finally {
copyDorisLog();
}
}

private void copyDorisLog() {
try {
// stop Doris container
String destPath = System.getenv("IT_PROJECT_DIR");
LOG.info("Copy doris log file to {}", destPath);

String feTarPath = "/doris-be.tar";
String beTarPath = "/doris-fe.tar";

// Pack the jar files
container.execInContainer("tar", "cf", feTarPath, DORIS_BE_PATH);
container.execInContainer("tar", "cf", beTarPath, DORIS_FE_PATH);

container.copyFileFromContainer(feTarPath, destPath + File.separator + "doris-be.tar");
container.copyFileFromContainer(beTarPath, destPath + File.separator + "doris-fe.tar");
} catch (Exception e) {
LOG.error("Failed to copy container log to local", e);
}
}

@Override
Expand Down

0 comments on commit abcfa96

Please sign in to comment.