Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#3024] improvement(IT): close containers and upload container log after all tests are finished #3197

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ protected void setupContainer() {

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

@Override
public void close() {
copyDorisLog();
super.close();
}

private void copyDorisLog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ protected void setupContainer() {

@Override
public void start() {
try {
super.start();
Preconditions.check("Hive container startup failed!", checkContainerStatus(10));
} finally {
copyHiveLog();
}
super.start();
Preconditions.check("Hive container startup failed!", checkContainerStatus(10));
}

@Override
public void close() {
copyHiveLog();
super.close();
}

private void copyHiveLog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public static Builder builder() {

@Override
public void start() {
try {
super.start();
Preconditions.checkArgument(checkContainerStatus(5), "Kafka container startup failed!");
} finally {
copyKafkaLogs();
}
super.start();
Preconditions.checkArgument(checkContainerStatus(5), "Kafka container startup failed!");
}

@Override
public void close() {
copyKafkaLogs();
super.close();
}

private void copyKafkaLogs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ExtendWith(PrintFuncNameExtension.class)
@ExtendWith({PrintFuncNameExtension.class, CloseContainerExtension.class})
public class AbstractIT {
protected static final ContainerSuite containerSuite = ContainerSuite.getInstance();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2023 Datastrato Pvt Ltd.
xiaozcy marked this conversation as resolved.
Show resolved Hide resolved
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.integration.test.util;

import com.datastrato.gravitino.integration.test.container.ContainerSuite;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CloseContainerExtension implements BeforeAllCallback {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaozcy
Adding a comment about this class is preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Override
public void beforeAll(ExtensionContext extensionContext) {
synchronized (CloseContainerExtension.class) {
extensionContext
.getRoot()
.getStore(ExtensionContext.Namespace.GLOBAL)
.getOrComputeIfAbsent(CloseableContainer.class);
}
}

private static class CloseableContainer implements ExtensionContext.Store.CloseableResource {
private static final Logger LOGGER = LoggerFactory.getLogger(CloseableContainer.class);
private static final ContainerSuite CONTAINER_SUITE = ContainerSuite.getInstance();

@Override
public void close() {
try {
CONTAINER_SUITE.close();
LOGGER.info("Containers were closed successfully");
} catch (Exception e) {
LOGGER.warn("Containers were not closed as expected", e);
}
}
}
}
Loading