Skip to content

Commit

Permalink
Merge pull request #267 from ydb-platform/fix_concurrent_tests
Browse files Browse the repository at this point in the history
Added experimental option to use native docker port binding
  • Loading branch information
alex268 authored Apr 27, 2024
2 parents 4951bec + 146a73c commit f8dcaee
Show file tree
Hide file tree
Showing 19 changed files with 583 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
java: [ '8', '11', '17']

env:
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always -DYDB_DOCKER_ISOLATION=true

steps:
- uses: actions/checkout@v4
Expand All @@ -41,7 +41,7 @@ jobs:
needs: build

env:
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always -DYDB_DOCKER_ISOLATION=true

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
java: [ '8', '11', '17']

env:
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always -DYDB_DOCKER_ISOLATION=true

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- uses: actions/checkout@v4
with:
repository: ydb-platform/ydb-java-examples
ref: develop
ref: master
path: examples

- name: Download dependencies
Expand Down
6 changes: 6 additions & 0 deletions coordination/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:trunk</YDB_DOCKER_IMAGE>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public List<EndpointRecord> setNewState(String selfLocation, List<EndpointRecord
String hostAndPort = endpoint.getHostAndPort();

if (!newRecordsByEndpoint.containsKey(hostAndPort)) {
logger.debug("added endpoint {}", entry);
logger.debug("added endpoint {}", endpoint);
newRecordsByEndpoint.put(hostAndPort, entry);
if (endpoint.getNodeId() != 0) {
newRecordsByNodeId.put(endpoint.getNodeId(), entry);
Expand Down
4 changes: 2 additions & 2 deletions tests/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
<!-- Test env variables for unit tests -->
<environmentVariables>
<TEST_VAR1>var1</TEST_VAR1>
<!-- TEST_VAR2 isnot set -->
<!-- TEST_VAR2 is not set -->
<TEST_VAR3></TEST_VAR3>
<TEST_VAR4>true</TEST_VAR4>
<TEST_VAR5>true1</TEST_VAR5>

<YDB_DISABLE_INTEGRATION_TESTS>true</YDB_DISABLE_INTEGRATION_TESTS>
<YDB_DOCKER_ISOLATION>true</YDB_DOCKER_ISOLATION>
</environmentVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class YdbEnvironment {

private final Supplier<Boolean> cleanUpTests = createParam("YDB_CLEAN_UP", true);
private final Supplier<Boolean> disableIntegrationTests = createParam("YDB_DISABLE_INTEGRATION_TESTS", false);
private final Supplier<Boolean> useDockerIsolation = createParam("YDB_DOCKER_ISOLATION", false);

public String ydbEndpoint() {
return ydbEndpoint.get();
Expand Down Expand Up @@ -69,6 +70,10 @@ public boolean disableIntegrationTests() {
return disableIntegrationTests.get();
}

public boolean useDockerIsolation() {
return useDockerIsolation.get();
}

private Supplier<String> createParam(String key, String defaultValue) {
return Suppliers.memoize(() -> readParam(key, defaultValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.testcontainers.DockerClientFactory;

import tech.ydb.test.integration.docker.DockerHelperFactory;
import tech.ydb.test.integration.docker.ProxedDockerHelperFactory;
import tech.ydb.test.integration.external.ExternalHelperFactory;

/**
Expand Down Expand Up @@ -37,7 +38,11 @@ static YdbHelperFactory createYdbHelper(YdbEnvironment env) {
// check if docker is availabled
if (DockerClientFactory.instance().isDockerAvailable()) {
logger.info("setup docker-based ydb helper");
return new DockerHelperFactory(env);
if (env.useDockerIsolation()) {
return new ProxedDockerHelperFactory(env);
} else {
return new DockerHelperFactory(env);
}
}

logger.info("ydb helper is disabled");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package tech.ydb.test.integration.docker;

import com.google.protobuf.Any;
import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerMethodDefinition;
import io.grpc.Status;

import tech.ydb.core.impl.pool.EndpointRecord;
import tech.ydb.proto.OperationProtos;
import tech.ydb.proto.StatusCodesProtos;
import tech.ydb.proto.discovery.DiscoveryProtos;
import tech.ydb.proto.discovery.v1.DiscoveryServiceGrpc;


/**
*
* @author Aleksandr Gorshenin
*/
public class DiscoveryServiceProxy
implements ServerCallHandler<DiscoveryProtos.ListEndpointsRequest, DiscoveryProtos.ListEndpointsResponse> {

private final EndpointRecord endpoint;

public DiscoveryServiceProxy(EndpointRecord endpoint) {
this.endpoint = endpoint;
}

public ServerMethodDefinition<?, ?> toMethodDefinition() {
return ServerMethodDefinition.create(DiscoveryServiceGrpc.getListEndpointsMethod(), this);
}

@Override
public ServerCall.Listener<DiscoveryProtos.ListEndpointsRequest> startCall(
ServerCall<DiscoveryProtos.ListEndpointsRequest, DiscoveryProtos.ListEndpointsResponse> serverCall,
Metadata metadata
) {
serverCall.request(1);
serverCall.sendHeaders(new Metadata());
return new ServerCall.Listener<DiscoveryProtos.ListEndpointsRequest>() {
@Override
public void onMessage(DiscoveryProtos.ListEndpointsRequest message) {
serverCall.sendMessage(createDiscoveryResponse());
}

@Override
public void onHalfClose() {
serverCall.close(Status.OK, new Metadata());
}
};
}

private DiscoveryProtos.ListEndpointsResponse createDiscoveryResponse() {
DiscoveryProtos.ListEndpointsResult result = DiscoveryProtos.ListEndpointsResult.newBuilder()
.setSelfLocation("PROXY")
.addEndpoints(DiscoveryProtos.EndpointInfo.newBuilder()
.setAddress(endpoint.getHost())
.setPort(endpoint.getPort())
.build()
)
.build();

OperationProtos.Operation operation = OperationProtos.Operation.newBuilder()
.setReady(true)
.setStatus(StatusCodesProtos.StatusIds.StatusCode.SUCCESS)
.setId("grpc-proxy-discovery")
.setResult(Any.pack(result))
.build();

return DiscoveryProtos.ListEndpointsResponse.newBuilder()
.setOperation(operation)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.core.grpc.GrpcTransportBuilder;
import tech.ydb.core.impl.pool.EndpointRecord;
import tech.ydb.test.integration.YdbEnvironment;
import tech.ydb.test.integration.YdbHelper;
import tech.ydb.test.integration.YdbHelperFactory;
Expand Down Expand Up @@ -43,7 +44,8 @@ public GrpcTransport createTransport() {

@Override
public String endpoint() {
return env.ydbUseTls() ? container.secureEndpoint() : container.nonSecureEndpoint();
EndpointRecord endpoint = env.ydbUseTls() ? container.secureEndpoint() : container.nonSecureEndpoint();
return endpoint.getHostAndPort();
}

@Override
Expand All @@ -58,7 +60,7 @@ public boolean useTls() {

@Override
public String authToken() {
// connection to docker container always is anonymous
// connection to docker container is always anonymous
return null;
}

Expand Down
Loading

0 comments on commit f8dcaee

Please sign in to comment.