|
1 | 1 | package org.testcontainers.qdrant;
|
2 | 2 |
|
3 |
| -import io.grpc.Grpc; |
4 |
| -import io.grpc.InsecureChannelCredentials; |
| 3 | +import io.qdrant.client.QdrantClient; |
5 | 4 | import io.qdrant.client.QdrantGrpcClient;
|
6 | 5 | import io.qdrant.client.grpc.QdrantOuterClass;
|
7 | 6 | import org.junit.Test;
|
| 7 | +import org.testcontainers.images.builder.Transferable; |
8 | 8 |
|
| 9 | +import java.util.UUID; |
9 | 10 | import java.util.concurrent.ExecutionException;
|
10 | 11 |
|
11 | 12 | import static org.assertj.core.api.Assertions.assertThat;
|
| 13 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
12 | 14 |
|
13 | 15 | public class QdrantContainerTest {
|
14 | 16 |
|
15 | 17 | @Test
|
16 |
| - public void test() throws ExecutionException, InterruptedException { |
| 18 | + public void shouldReturnVersion() throws ExecutionException, InterruptedException { |
17 | 19 | try (
|
18 | 20 | // qdrantContainer {
|
19 | 21 | QdrantContainer qdrant = new QdrantContainer("qdrant/qdrant:v1.7.4")
|
20 | 22 | // }
|
21 | 23 | ) {
|
22 | 24 | qdrant.start();
|
23 | 25 |
|
24 |
| - QdrantGrpcClient client = QdrantGrpcClient |
25 |
| - .newBuilder( |
26 |
| - Grpc.newChannelBuilder(qdrant.getGrpcHostAddress(), InsecureChannelCredentials.create()).build() |
27 |
| - ) |
28 |
| - .build(); |
29 |
| - QdrantOuterClass.HealthCheckReply healthCheckReply = client |
30 |
| - .qdrant() |
31 |
| - .healthCheck(QdrantOuterClass.HealthCheckRequest.getDefaultInstance()) |
32 |
| - .get(); |
| 26 | + QdrantClient client = new QdrantClient( |
| 27 | + QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).build() |
| 28 | + ); |
| 29 | + QdrantOuterClass.HealthCheckReply healthCheckReply = client.healthCheckAsync().get(); |
33 | 30 | assertThat(healthCheckReply.getVersion()).isEqualTo("1.7.4");
|
| 31 | + |
| 32 | + client.close(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void shouldSetApiKey() throws ExecutionException, InterruptedException { |
| 38 | + String apiKey = UUID.randomUUID().toString(); |
| 39 | + try (QdrantContainer qdrant = new QdrantContainer("qdrant/qdrant:v1.7.4").withApiKey(apiKey)) { |
| 40 | + qdrant.start(); |
| 41 | + |
| 42 | + final QdrantClient unauthClient = new QdrantClient( |
| 43 | + QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).build() |
| 44 | + ); |
| 45 | + |
| 46 | + assertThatThrownBy(() -> unauthClient.healthCheckAsync().get()).isInstanceOf(ExecutionException.class); |
| 47 | + |
| 48 | + unauthClient.close(); |
| 49 | + |
| 50 | + final QdrantClient client = new QdrantClient( |
| 51 | + QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).withApiKey(apiKey).build() |
| 52 | + ); |
| 53 | + |
| 54 | + QdrantOuterClass.HealthCheckReply healthCheckReply = client.healthCheckAsync().get(); |
| 55 | + assertThat(healthCheckReply.getVersion()).isEqualTo("1.7.4"); |
| 56 | + |
| 57 | + client.close(); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void shouldSetApiKeyUsingConfigFile() throws ExecutionException, InterruptedException { |
| 63 | + String apiKey = UUID.randomUUID().toString(); |
| 64 | + String configFile = "service:\n api_key: " + apiKey; |
| 65 | + try ( |
| 66 | + QdrantContainer qdrant = new QdrantContainer("qdrant/qdrant:v1.7.4") |
| 67 | + .withConfigFile(Transferable.of(configFile)) |
| 68 | + ) { |
| 69 | + qdrant.start(); |
| 70 | + |
| 71 | + final QdrantClient unauthClient = new QdrantClient( |
| 72 | + QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).build() |
| 73 | + ); |
| 74 | + |
| 75 | + assertThatThrownBy(() -> unauthClient.healthCheckAsync().get()).isInstanceOf(ExecutionException.class); |
| 76 | + |
| 77 | + unauthClient.close(); |
| 78 | + |
| 79 | + final QdrantClient client = new QdrantClient( |
| 80 | + QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).withApiKey(apiKey).build() |
| 81 | + ); |
| 82 | + |
| 83 | + QdrantOuterClass.HealthCheckReply healthCheckReply = client.healthCheckAsync().get(); |
| 84 | + assertThat(healthCheckReply.getVersion()).isEqualTo("1.7.4"); |
| 85 | + |
| 86 | + client.close(); |
34 | 87 | }
|
35 | 88 | }
|
36 | 89 | }
|
0 commit comments