Skip to content

Commit 188dcdf

Browse files
committed
Fix tests without docker
1 parent 6c78e53 commit 188dcdf

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,25 @@
44
[![Codecov](https://img.shields.io/codecov/c/github/ydb-platform/ydb-jdbc-driver)](https://app.codecov.io/gh/ydb-platform/ydb-jdbc-driver)
55

66
## JDBC Driver for YDB
7-
---
8-
This is an experimental version of JDBC driver for YDB. It is in active development and is not intended for use in production environments.
9-
10-
### Building
11-
All tests are run without Docker by default.
12-
To enable all tests make sure you have Docker or Docker Machine installed then run `mvn install -DSKIP_DOCKER_TESTS=false`
137

148
### Quickstart
159

1610
1) Drop in [JDBC driver](https://github.com/ydb-platform/ydb-jdbc-driver/releases) to classpath or pick this file in IDEA
1711
2) Connect to YDB
18-
* Local or remote Docker (anonymous authentication): `jdbc:ydb:grpc://localhost:2135/local`
19-
* Self-hosted cluster: `jdbc:ydb:grpcs://<host>:2136/Root/testdb?secureConnectionCertificate=file:~/myca.cer` + username and password configured
20-
* Connect with token to the cloud instance: `jdbc:ydb:grpcs://<host>:2135/path/to/database?token=file:~/my_token`
12+
* Local or remote Docker (anonymous authentication):<br>`jdbc:ydb:grpc://localhost:2135/local`
13+
* Self-hosted cluster:<br>`jdbc:ydb:grpcs://<host>:2136/Root/testdb?secureConnectionCertificate=file:~/myca.cer`
14+
* Connect with token to the cloud instance:<br>`jdbc:ydb:grpcs://<host>:2135/path/to/database?token=file:~/my_token`
2115
* Connect with service account to the cloud instance: `jdbc:ydb:grpcs://<host>:2136/path/to/database?saFile=file:~/sa_key.json`
2216
3) Execute queries, see example in [YdbDriverExampleTest.java](jdbc/src/test/java/tech/ydb/jdbc/YdbDriverExampleTest.java)
2317

2418
### Authentication modes
2519

2620
YDB JDBC Driver supports the following [authentication modes](https://ydb.tech/en/docs/reference/ydb-sdk/auth):
27-
* Anonymous: no authentication, used when username and password are not specified and no other authentication properties configured;
28-
* Static Credentials: used when username and password are specified;
29-
* Access Token: used when `token` property is configured, needs YDB authentication token as printed by the `ydb auth get-token` CLI command;
30-
* Metadata: used when `useMetadata` property is set to `true`, extracts the authentication data from the metadata of a virtual machine, serverless container or a serverless function running in a cloud environment;
31-
* Service Account Key: used when `saFile` property is configured, extracts the service account key and uses it for authentication.
21+
* `Anonymous`: no authentication, used when username and password are not specified and no other authentication properties configured;
22+
* `Static Credentials`: used when username and password are specified;
23+
* `Access Token`: used when `token` property is configured, needs YDB authentication token as printed by the `ydb auth get-token` CLI command;
24+
* `Metadata`: used when `useMetadata` property is set to `true`, extracts the authentication data from the metadata of a virtual machine, serverless container or a serverless function running in a cloud environment;
25+
* `Service Account Key`: used when `saFile` property is configured, extracts the service account key and uses it for authentication.
3226

3327
### Driver properties reference
3428

@@ -44,3 +38,8 @@ File references for `saFile`, `token` or `secureConnectionCertificate` must be p
4438
* `saFile=file:~/mysaley1.json`
4539
* `token=file:/opt/secret/token-file`
4640
* `secureConnectionCertificate=file:/etc/ssl/cacert.cer`
41+
42+
### Building
43+
By default all tests are run using a local YDB instance in Docker (if host has Docker or Docker Machine installed)
44+
To disable these tests run `mvn test -DYDB_DISABLE_INTEGRATION_TESTS=true`
45+

jdbc/src/test/java/tech/ydb/jdbc/YdbDriverStaticCredsTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.junit.jupiter.api.extension.RegisterExtension;
1313

1414
import tech.ydb.jdbc.impl.helper.ExceptionAssert;
15+
import tech.ydb.jdbc.impl.helper.JdbcConnectionExtention;
1516
import tech.ydb.jdbc.impl.helper.JdbcUrlHelper;
1617
import tech.ydb.test.junit5.YdbHelperExtension;
1718

@@ -23,6 +24,9 @@ public class YdbDriverStaticCredsTest {
2324
@RegisterExtension
2425
private static final YdbHelperExtension ydb = new YdbHelperExtension();
2526

27+
@RegisterExtension
28+
private static final JdbcConnectionExtention jdbc = new JdbcConnectionExtention(ydb);
29+
2630
private static final JdbcUrlHelper jdbcURL = new JdbcUrlHelper(ydb);
2731

2832
@BeforeAll

jdbc/src/test/java/tech/ydb/jdbc/impl/helper/JdbcConnectionExtention.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
import org.junit.jupiter.api.extension.AfterEachCallback;
1313
import org.junit.jupiter.api.extension.BeforeAllCallback;
1414
import org.junit.jupiter.api.extension.BeforeEachCallback;
15+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
16+
import org.junit.jupiter.api.extension.ExecutionCondition;
1517
import org.junit.jupiter.api.extension.ExtensionContext;
1618

19+
import tech.ydb.test.integration.YdbHelperFactory;
1720
import tech.ydb.test.junit5.YdbHelperExtension;
1821

1922
/**
2023
*
2124
* @author Aleksandr Gorshenin
2225
*/
23-
public class JdbcConnectionExtention implements
26+
public class JdbcConnectionExtention implements ExecutionCondition,
2427
BeforeEachCallback, BeforeAllCallback, AfterEachCallback, AfterAllCallback {
2528

2629
private final JdbcUrlHelper jdbcURL;
@@ -63,6 +66,15 @@ public Connection connection() {
6366
return stack.peek();
6467
}
6568

69+
@Override
70+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
71+
if (!YdbHelperFactory.getInstance().isEnabled()) {
72+
return ConditionEvaluationResult.disabled("Ydb helper is disabled " + context.getDisplayName());
73+
}
74+
75+
return ConditionEvaluationResult.enabled("OK");
76+
}
77+
6678
@Override
6779
public void beforeEach(ExtensionContext ctx) throws Exception {
6880
register(ctx);

jdbc/src/test/java/tech/ydb/jdbc/impl/helper/JdbcUrlHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.net.URLEncoder;
66
import java.nio.charset.StandardCharsets;
77

8+
import tech.ydb.test.integration.YdbHelperFactory;
89
import tech.ydb.test.junit5.YdbHelperExtension;
910

1011
/**
@@ -51,6 +52,10 @@ public JdbcUrlHelper withAutority(String username, String password) {
5152
}
5253

5354
public String build() {
55+
if (!YdbHelperFactory.getInstance().isEnabled()) {
56+
return "jdbc:ydb:grpc://localhost/local";
57+
}
58+
5459
StringBuilder jdbc = new StringBuilder("jdbc:ydb:")
5560
.append(ydb.useTls() ? "grpcs://" : "grpc://")
5661
.append(authority)

0 commit comments

Comments
 (0)