-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[qdrant] Allow to set key and config file (#8556)
Co-authored-by: Anush008 <anushshetty90@gmail.com>
- Loading branch information
1 parent
8d0cf9b
commit ba25e5d
Showing
2 changed files
with
90 additions
and
16 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
77 changes: 65 additions & 12 deletions
77
modules/qdrant/src/test/java/org/testcontainers/qdrant/QdrantContainerTest.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 |
---|---|---|
@@ -1,36 +1,89 @@ | ||
package org.testcontainers.qdrant; | ||
|
||
import io.grpc.Grpc; | ||
import io.grpc.InsecureChannelCredentials; | ||
import io.qdrant.client.QdrantClient; | ||
import io.qdrant.client.QdrantGrpcClient; | ||
import io.qdrant.client.grpc.QdrantOuterClass; | ||
import org.junit.Test; | ||
import org.testcontainers.images.builder.Transferable; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
public class QdrantContainerTest { | ||
|
||
@Test | ||
public void test() throws ExecutionException, InterruptedException { | ||
public void shouldReturnVersion() throws ExecutionException, InterruptedException { | ||
try ( | ||
// qdrantContainer { | ||
QdrantContainer qdrant = new QdrantContainer("qdrant/qdrant:v1.7.4") | ||
// } | ||
) { | ||
qdrant.start(); | ||
|
||
QdrantGrpcClient client = QdrantGrpcClient | ||
.newBuilder( | ||
Grpc.newChannelBuilder(qdrant.getGrpcHostAddress(), InsecureChannelCredentials.create()).build() | ||
) | ||
.build(); | ||
QdrantOuterClass.HealthCheckReply healthCheckReply = client | ||
.qdrant() | ||
.healthCheck(QdrantOuterClass.HealthCheckRequest.getDefaultInstance()) | ||
.get(); | ||
QdrantClient client = new QdrantClient( | ||
QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).build() | ||
); | ||
QdrantOuterClass.HealthCheckReply healthCheckReply = client.healthCheckAsync().get(); | ||
assertThat(healthCheckReply.getVersion()).isEqualTo("1.7.4"); | ||
|
||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldSetApiKey() throws ExecutionException, InterruptedException { | ||
String apiKey = UUID.randomUUID().toString(); | ||
try (QdrantContainer qdrant = new QdrantContainer("qdrant/qdrant:v1.7.4").withApiKey(apiKey)) { | ||
qdrant.start(); | ||
|
||
final QdrantClient unauthClient = new QdrantClient( | ||
QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).build() | ||
); | ||
|
||
assertThatThrownBy(() -> unauthClient.healthCheckAsync().get()).isInstanceOf(ExecutionException.class); | ||
|
||
unauthClient.close(); | ||
|
||
final QdrantClient client = new QdrantClient( | ||
QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).withApiKey(apiKey).build() | ||
); | ||
|
||
QdrantOuterClass.HealthCheckReply healthCheckReply = client.healthCheckAsync().get(); | ||
assertThat(healthCheckReply.getVersion()).isEqualTo("1.7.4"); | ||
|
||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldSetApiKeyUsingConfigFile() throws ExecutionException, InterruptedException { | ||
String apiKey = UUID.randomUUID().toString(); | ||
String configFile = "service:\n api_key: " + apiKey; | ||
try ( | ||
QdrantContainer qdrant = new QdrantContainer("qdrant/qdrant:v1.7.4") | ||
.withConfigFile(Transferable.of(configFile)) | ||
) { | ||
qdrant.start(); | ||
|
||
final QdrantClient unauthClient = new QdrantClient( | ||
QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).build() | ||
); | ||
|
||
assertThatThrownBy(() -> unauthClient.healthCheckAsync().get()).isInstanceOf(ExecutionException.class); | ||
|
||
unauthClient.close(); | ||
|
||
final QdrantClient client = new QdrantClient( | ||
QdrantGrpcClient.newBuilder(qdrant.getHost(), qdrant.getGrpcPort(), false).withApiKey(apiKey).build() | ||
); | ||
|
||
QdrantOuterClass.HealthCheckReply healthCheckReply = client.healthCheckAsync().get(); | ||
assertThat(healthCheckReply.getVersion()).isEqualTo("1.7.4"); | ||
|
||
client.close(); | ||
} | ||
} | ||
} |