Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -338,6 +338,9 @@ public void deleteApp(@Nonnull App app) {
AppFolderName folder = app.appFolder();
blobStore.deleteBlob(folder.resolve(MANIFEST_WEBAPP_FILENAME));

// TODO(DHIS2-20648) Once the replacement BlobStoreService implementation does recursive
// deleteDirectory on every backend (see contract test), this branch can collapse to a
// single blobStore.deleteDirectory(folder.asPrefix()) call.
if (blobStore.isFilesystem()) {
// Delete all files related to app (works for local filestore)
blobStore.deleteDirectory(folder.asPrefix());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ void putBlob(
* Recursively deletes all blobs whose key starts with {@code prefix}. On filesystem backends this
* maps to a directory delete; on object-store backends it performs per-key deletion.
*/
// TODO(DHIS2-20648) The replacement implementation must honour this recursively for ALL
// backends. The current jclouds-transient and jclouds-S3 paths are non-recursive (callers
// work around it in JCloudsAppStorageService#deleteApp); see BlobStoreServiceContractTest's
// supportsRecursiveDirectoryDelete capability hook — drop the false overrides once fixed.
void deleteDirectory(BlobKeyPrefix prefix);

/**
Expand All @@ -121,8 +125,12 @@ void putBlob(

/**
* Lists all blob keys whose key starts with {@code prefix} (recursive). May return an empty
* iterable if no matching blobs exist.
* iterable if no matching blobs exist. Returned keys identify real blobs only — synthetic
* directory marker entries (values ending with {@code /}) must not be returned.
*/
// TODO(DHIS2-20648) The replacement implementation must filter directory markers. The current
// jclouds-filesystem provider emits them; see BlobStoreServiceContractTest's
// listKeysIncludesDirectoryMarkers capability hook — drop the true override once fixed.
Iterable<BlobKey> listKeys(BlobKeyPrefix prefix);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,27 @@
import java.util.Properties;
import org.hisp.dhis.external.conf.DhisConfigurationProvider;
import org.hisp.dhis.test.config.PostgresDhisConfigurationProvider;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.Extension;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.MinIOContainer;

/**
* Use this configuration for tests relying on MinIO storage running in a Docker container. The
* container is stopped after the tests in the class have completed. Just add to test class like
* container is started once per JVM and shared across all test classes that use this extension;
* Testcontainers' Ryuk reaper handles teardown on JVM exit. Just add to test class like
*
* <p>@ExtendWith(MinIOTestExtension.class)
*
* <p>@ContextConfiguration(classes = {MinIOConfig.class})
*
* <p>If there are many uses of this extension then it should be considered whether keeping the
* container up for the entirety of the tests is more preferable, rather than starting/stopping
* multiple containers.
*
* @author david mackessy
*/
public class MinIOTestExtension implements AfterAllCallback {
public class MinIOTestExtension implements Extension {

Check warning on line 50 in dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/junit/MinIOTestExtension.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a private constructor to hide the implicit public one.

See more on https://sonarcloud.io/project/issues?id=dhis2_dhis2-core&issues=AZ4bpXMCbhxKRS7kelJ8&open=AZ4bpXMCbhxKRS7kelJ8&pullRequest=23867

public static final String MINIO_USER = "testuser";
public static final String MINIO_PASSWORD = "testpassword";

private static final String S3_URL;
private static final String MINIO_USER = "testuser";
private static final String MINIO_PASSWORD = "testpassword";
private static final MinIOContainer MIN_IO_CONTAINER;

static {
Expand All @@ -67,6 +64,13 @@
S3_URL = MIN_IO_CONTAINER.getS3URL();
}

/**
* Endpoint URL the running MinIO container is reachable on (e.g. {@code http://localhost:32812}).
*/
public static String s3Url() {
return S3_URL;
}

public static class DhisConfig {
@Bean
public DhisConfigurationProvider dhisConfigurationProvider() {
Expand All @@ -83,9 +87,4 @@
return pgDhisConfig;
}
}

@Override
public void afterAll(ExtensionContext context) {
MIN_IO_CONTAINER.stop();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Testcontainers' Ryuk reaper handles teardown on JVM exit

}
}
6 changes: 6 additions & 0 deletions dhis-2/dhis-test-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@
<artifactId>dhis-support-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>minio</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hisp.dhis.parser</groupId>
<artifactId>dhis-antlr-expression-parser</artifactId>
Expand Down Expand Up @@ -393,6 +398,7 @@
<ignoredUnusedDeclaredDependency>org.hisp.dhis:dhis-service-setting</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.testcontainers:postgresql</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.testcontainers:jdbc</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.testcontainers:minio</ignoredUnusedDeclaredDependency>
<!-- log4j-slf4j-impl is needed to log using slf4j see https://www.slf4j.org/codes.html#noProviders -->
<ignoredUnusedDeclaredDependency>org.apache.logging.log4j:log4j-slf4j-impl</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.hisp.dhis:dhis-service-audit-consumer</ignoredUnusedDeclaredDependency>
Expand Down
Loading
Loading