-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : use test containers in dev mode
- Loading branch information
1 parent
0f55e77
commit fffbc95
Showing
5 changed files
with
27 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
boot-opensearch-sample/src/test/java/com/example/opensearch/TestOpenSearchApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.opensearch; | ||
|
||
import com.example.opensearch.common.ContainersConfig; | ||
import org.springframework.boot.SpringApplication; | ||
|
||
class TestOpenSearchApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(OpenSearchApplication::main).with(ContainersConfig.class).run(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 11 additions & 16 deletions
27
boot-opensearch-sample/src/test/java/com/example/opensearch/common/ContainersConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
package com.example.opensearch.common; | ||
|
||
import java.time.Duration; | ||
import org.opensearch.testcontainers.OpensearchContainer; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.utility.DockerImageName; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class ContainersConfig { | ||
|
||
@Container | ||
public static final OpensearchContainer<?> openSearchContainer = | ||
new OpensearchContainer<>(DockerImageName.parse("opensearchproject/opensearch:2.16.0")) | ||
.withEnv("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin"); | ||
|
||
static { | ||
openSearchContainer.start(); | ||
} | ||
|
||
@DynamicPropertySource | ||
static void setApplicationProperties(DynamicPropertyRegistry dynamicPropertyRegistry) { | ||
dynamicPropertyRegistry.add("opensearch.uris", openSearchContainer::getHttpHostAddress); | ||
@Bean | ||
@ServiceConnection | ||
OpensearchContainer<?> opensearchContainer() { | ||
return new OpensearchContainer<>("opensearchproject/opensearch:2.16.0") | ||
.withStartupAttempts(5) | ||
.withStartupTimeout(Duration.ofMinutes(10)); | ||
} | ||
} |