|
19 | 19 | import org.junit.After; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.testcontainers.DockerClientFactory; |
| 22 | +import org.testcontainers.containers.BindMode; |
22 | 23 | import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; |
23 | 24 | import org.testcontainers.containers.wait.strategy.Wait; |
24 | 25 | import org.testcontainers.images.RemoteDockerImage; |
@@ -375,6 +376,46 @@ public void testElasticsearch8SecureByDefaultFailsSilentlyOnLatestImages() throw |
375 | 376 | } |
376 | 377 | } |
377 | 378 |
|
| 379 | + @Test |
| 380 | + public void testElasticsearchDefaultMaxHeapSize() throws Exception { |
| 381 | + long defaultHeapSize = 2147483648L; |
| 382 | + |
| 383 | + try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)) { |
| 384 | + container.start(); |
| 385 | + assertElasticsearchContainerHasHeapSize(container, defaultHeapSize); |
| 386 | + } |
| 387 | + } |
| 388 | + |
| 389 | + @Test |
| 390 | + public void testElasticsearchCustomMaxHeapSizeInEnvironmentVariable() throws Exception { |
| 391 | + long customHeapSize = 1574961152; |
| 392 | + |
| 393 | + try ( |
| 394 | + ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE) |
| 395 | + .withEnv("ES_JAVA_OPTS", String.format("-Xms%d -Xmx%d", customHeapSize, customHeapSize)) |
| 396 | + ) { |
| 397 | + container.start(); |
| 398 | + assertElasticsearchContainerHasHeapSize(container, customHeapSize); |
| 399 | + } |
| 400 | + } |
| 401 | + |
| 402 | + @Test |
| 403 | + public void testElasticsearchCustomMaxHeapSizeInJvmOptionsFile() throws Exception { |
| 404 | + long customHeapSize = 1574961152; |
| 405 | + |
| 406 | + try ( |
| 407 | + ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE) |
| 408 | + .withClasspathResourceMapping( |
| 409 | + "test-custom-memory-jvm.options", |
| 410 | + "/usr/share/elasticsearch/config/jvm.options.d/a-user-defined-jvm.options", |
| 411 | + BindMode.READ_ONLY |
| 412 | + ); |
| 413 | + ) { |
| 414 | + container.start(); |
| 415 | + assertElasticsearchContainerHasHeapSize(container, customHeapSize); |
| 416 | + } |
| 417 | + } |
| 418 | + |
378 | 419 | private void tagImage(String sourceImage, String targetImage, String targetTag) throws InterruptedException { |
379 | 420 | DockerClient dockerClient = DockerClientFactory.instance().client(); |
380 | 421 | dockerClient |
@@ -438,4 +479,13 @@ private RestClient getAnonymousClient(ElasticsearchContainer container) { |
438 | 479 |
|
439 | 480 | return anonymousClient; |
440 | 481 | } |
| 482 | + |
| 483 | + private void assertElasticsearchContainerHasHeapSize(ElasticsearchContainer container, long heapSizeInBytes) |
| 484 | + throws Exception { |
| 485 | + Response response = getClient(container).performRequest(new Request("GET", "/_nodes/_all/jvm")); |
| 486 | + String responseBody = EntityUtils.toString(response.getEntity()); |
| 487 | + assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); |
| 488 | + assertThat(responseBody).contains("\"heap_init_in_bytes\":" + heapSizeInBytes); |
| 489 | + assertThat(responseBody).contains("\"heap_max_in_bytes\":" + heapSizeInBytes); |
| 490 | + } |
441 | 491 | } |
0 commit comments