Skip to content

Commit

Permalink
[apache#3024] improvement(IT): close containers and upload container …
Browse files Browse the repository at this point in the history
…log after all tests are finished (apache#3197)

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

close containers and upload container log after all tests are finished

### Why are the changes needed?

Fix: apache#3024 

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

N/A

### How was this patch tested?

existing ITs

---------

Co-authored-by: zhanghan18 <[email protected]>
Co-authored-by: Qi Yu <[email protected]>
  • Loading branch information
3 people authored and diqiu50 committed Jun 13, 2024
1 parent 1550331 commit b861e90
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 20 deletions.
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,43 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* 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;

/**
* This is an extension for juint 5, which aims to perform certain operations (such as resource
* recycling, etc.) after all test executions are completed (regardless of success or failure). You
* can Refer to {@link AbstractIT} for more information.
*/
public class CloseContainerExtension implements BeforeAllCallback {
@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);
}
}
}
}

0 comments on commit b861e90

Please sign in to comment.