forked from trinodb/trino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No plans to reuse containers in CI. This is only for development purposes. Notice that it not always bring much value and some test do not play well with reusing as they have side effects. Use it wisely on your own responsibility. Locally starting TestingMySqlServer and loading tpch data there takes over a minute, with reusing it is barely noticeable. Allow to reuse: - TestingSqlServer - TestingMySqlServer
- Loading branch information
Showing
6 changed files
with
82 additions
and
9 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
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
48 changes: 48 additions & 0 deletions
48
testing/trino-testing/src/main/java/io/trino/testing/containers/TestContainers.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,48 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.trino.testing.containers; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.TestcontainersConfiguration; | ||
|
||
import java.io.Closeable; | ||
|
||
import static com.google.common.base.Preconditions.checkState; | ||
import static java.lang.Boolean.parseBoolean; | ||
import static java.lang.System.getenv; | ||
|
||
public final class TestContainers | ||
{ | ||
// To reuse container set TESTCONTAINERS_REUSE_ENABLE=true environment variable. | ||
// TESTCONTAINERS_REUSE_ENABLE is an environment variable defined in testcontainers library. | ||
private static final boolean TESTCONTAINERS_REUSE_ENABLE = parseBoolean(getenv("TESTCONTAINERS_REUSE_ENABLE")); | ||
|
||
private TestContainers() {} | ||
|
||
// You should not close the container directly if you want to reuse it. | ||
// Instead you should close closeable returned by {@link this::startOrReuse} | ||
public static Closeable startOrReuse(GenericContainer<?> container) | ||
{ | ||
boolean reuse = TestcontainersConfiguration.getInstance().environmentSupportsReuse(); | ||
checkState(reuse == TESTCONTAINERS_REUSE_ENABLE, "Unable to enable or disable container reuse"); | ||
|
||
container.withReuse(TESTCONTAINERS_REUSE_ENABLE); | ||
container.start(); | ||
if (reuse) { | ||
return () -> {}; | ||
} | ||
return container::stop; | ||
} | ||
} |
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