Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1

- name: Set up JDK 21
uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEPASSWORD }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1

- name: Set up JDK 21
uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ To install the library, add the following lines to your build config file.
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.18.2</version>
<version>1.18.3</version>
</dependency>
```

#### SBT

```sbt
libraryDependencies += "io.qdrant" % "client" % "1.18.2"
libraryDependencies += "io.qdrant" % "client" % "1.18.3"
```

#### Gradle

```gradle
implementation 'io.qdrant:client:1.18.2'
implementation 'io.qdrant:client:1.18.3'
```

> [!NOTE]
Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {

dependencies {
// Qdrant Java client
implementation 'io.qdrant:client:1.18.2'
implementation 'io.qdrant:client:1.18.3'

// gRPC dependencies - use the same version as Qdrant client
implementation 'io.grpc:grpc-netty-shaded:1.65.1'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ qdrantProtosVersion=v1.18.0
qdrantVersion=v1.18.0

# The version of the client to generate
packageVersion=1.18.2
packageVersion=1.18.3
15 changes: 8 additions & 7 deletions src/main/java/io/qdrant/client/QdrantGrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,16 @@ public Builder withHeaders(Map<String, String> headers) {
* @return a new instance of {@link QdrantGrpcClient}
*/
public QdrantGrpcClient build() {
if (checkCompatibility) {
String clientVersion = Builder.class.getPackage().getImplementationVersion();
checkVersionsCompatibility(clientVersion);
}

CallCredentials credentials = this.callCredentials;
if (credentials == null && (apiKey != null || headers != null)) {
credentials = new MetadataCredentials(apiKey, headers);
}

if (checkCompatibility) {
String clientVersion = Builder.class.getPackage().getImplementationVersion();
checkVersionsCompatibility(clientVersion, credentials);
}

return new QdrantGrpcClient(channel, shutdownChannelOnClose, credentials, timeout);
}

Expand All @@ -301,11 +301,12 @@ private static ManagedChannel createChannel(
return channelBuilder.build();
}

private void checkVersionsCompatibility(String clientVersion) {
private void checkVersionsCompatibility(
String clientVersion, @Nullable CallCredentials credentials) {
try {
String serverVersion =
QdrantGrpc.newBlockingStub(this.channel)
.withCallCredentials(this.callCredentials)
.withCallCredentials(credentials)
.healthCheck(QdrantOuterClass.HealthCheckRequest.getDefaultInstance())
.getVersion();
if (!VersionsCompatibilityChecker.isCompatible(clientVersion, serverVersion)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.qdrant.client;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.grpc.CallCredentials;
import io.grpc.ManagedChannel;
import io.qdrant.client.grpc.QdrantGrpc;
import io.qdrant.client.grpc.QdrantOuterClass;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.MockedStatic;

/**
* Unit tests for the version compatibility check performed by {@link
* QdrantGrpcClient.Builder#build()}.
*/
Comment thread
Anush008 marked this conversation as resolved.
class QdrantGrpcClientCompatibilityTest {

@Test
void compatibility_check_uses_api_key_credentials_from_with_api_key() {
ManagedChannel channel = mock(ManagedChannel.class);
QdrantGrpc.QdrantBlockingStub stub = mock(QdrantGrpc.QdrantBlockingStub.class);
QdrantOuterClass.HealthCheckReply reply =
QdrantOuterClass.HealthCheckReply.newBuilder()
.setTitle("qdrant")
.setVersion("1.0.0")
.build();

try (MockedStatic<QdrantGrpc> grpc = mockStatic(QdrantGrpc.class)) {
grpc.when(() -> QdrantGrpc.newBlockingStub(any())).thenReturn(stub);
when(stub.withCallCredentials(any())).thenReturn(stub);
when(stub.healthCheck(any())).thenReturn(reply);

QdrantGrpcClient client =
QdrantGrpcClient.newBuilder(channel, false, true).withApiKey("my-api-key").build();
client.close();

ArgumentCaptor<CallCredentials> credentialsCaptor =
ArgumentCaptor.forClass(CallCredentials.class);
verify(stub).withCallCredentials(credentialsCaptor.capture());

CallCredentials usedCredentials = credentialsCaptor.getValue();
assertNotNull(
usedCredentials,
"Version compatibility check must run with the API key credentials, not null");
assertInstanceOf(MetadataCredentials.class, usedCredentials);
}
}
}
Loading