-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#noissue] Apply testcontainers-elasticsearch to testweb
- Loading branch information
Showing
8 changed files
with
142 additions
and
111 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
56 changes: 56 additions & 0 deletions
56
...icsearch-8-plugin-testweb/src/main/java/com/pinpoint/test/plugin/ElasticSearchServer.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,56 @@ | ||
package com.pinpoint.test.plugin; | ||
|
||
import com.navercorp.pinpoint.pluginit.utils.LogUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
import org.testcontainers.elasticsearch.ElasticsearchContainer; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import java.io.IOException; | ||
import java.util.function.Consumer; | ||
|
||
@Component | ||
public class ElasticSearchServer { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
public ElasticsearchContainer elasticSearchContainer; | ||
|
||
private final String address = "127.0.0.1"; | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public int getPort() { | ||
return elasticSearchContainer.getMappedPort(9200); | ||
} | ||
|
||
@PostConstruct | ||
public void init() throws IOException, InterruptedException { | ||
logger.info("ElasticSearchServer init"); | ||
if (!DockerClientFactory.instance().isDockerAvailable()) { | ||
throw new IllegalStateException("Docker not enabled"); | ||
} | ||
|
||
elasticSearchContainer = new ElasticsearchContainer(); | ||
elasticSearchContainer.withLogConsumer(new Consumer<OutputFrame>() { | ||
@Override | ||
public void accept(OutputFrame outputFrame) { | ||
logger.info(LogUtils.removeLineBreak(outputFrame.getUtf8String())); | ||
} | ||
}); | ||
elasticSearchContainer.start(); | ||
logger.info("host:{} port:{}", elasticSearchContainer.getHttpHostAddress(), getPort()); | ||
} | ||
|
||
@PreDestroy | ||
private void shutdown() { | ||
logger.info("ElasticSearchServer destroy"); | ||
if (elasticSearchContainer != null) { | ||
elasticSearchContainer.stop(); | ||
} | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
...search-8-plugin-testweb/src/main/java/com/pinpoint/test/plugin/EmbeddedElasticServer.java
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
...sticsearch-plugin-testweb/src/main/java/com/pinpoint/test/plugin/ElasticSearchServer.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,56 @@ | ||
package com.pinpoint.test.plugin; | ||
|
||
import com.navercorp.pinpoint.pluginit.utils.LogUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
import org.testcontainers.elasticsearch.ElasticsearchContainer; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import java.util.function.Consumer; | ||
|
||
|
||
@Component | ||
public class ElasticSearchServer { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
public ElasticsearchContainer elasticSearchContainer; | ||
|
||
private final String address = "127.0.0.1"; | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public int getPort() { | ||
return elasticSearchContainer.getMappedPort(9200); | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
logger.info("ElasticSearchServer init"); | ||
if (!DockerClientFactory.instance().isDockerAvailable()) { | ||
throw new IllegalStateException("Docker not enabled"); | ||
} | ||
|
||
elasticSearchContainer = new ElasticsearchContainer(); | ||
elasticSearchContainer.withLogConsumer(new Consumer<OutputFrame>() { | ||
@Override | ||
public void accept(OutputFrame outputFrame) { | ||
logger.info(LogUtils.removeLineBreak(outputFrame.getUtf8String())); | ||
} | ||
}); | ||
elasticSearchContainer.start(); | ||
logger.info("host:{} port:{}", elasticSearchContainer.getHttpHostAddress(), getPort()); | ||
} | ||
|
||
@PreDestroy | ||
private void shutdown() { | ||
logger.info("ElasticSearchServer destroy"); | ||
if (elasticSearchContainer != null) { | ||
elasticSearchContainer.stop(); | ||
} | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
...icsearch-plugin-testweb/src/main/java/com/pinpoint/test/plugin/EmbeddedElasticServer.java
This file was deleted.
Oops, something went wrong.