You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/03/27 10:24:40 UTC
(camel) branch main updated: CAMEL-20622: added support for CollectionInfo for camel-qdrant
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6b87e8e8870 CAMEL-20622: added support for CollectionInfo for camel-qdrant
6b87e8e8870 is described below
commit 6b87e8e887009084baf838f59e1345cdd58e9a56
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Mar 27 11:01:56 2024 +0100
CAMEL-20622: added support for CollectionInfo for camel-qdrant
---
.../camel/component/qdrant/QdrantAction.java | 1 +
.../camel/component/qdrant/QdrantProducer.java | 22 ++++++++++++
.../camel/component/qdrant/QdrantCommonTest.java | 12 +++++--
.../component/qdrant/it/QdrantComponentIT.java | 42 ++++++++++++++++++++--
4 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantAction.java b/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantAction.java
index 78eb582440e..81bc53085f8 100644
--- a/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantAction.java
+++ b/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantAction.java
@@ -21,4 +21,5 @@ public enum QdrantAction {
UPSERT,
RETRIEVE,
DELETE,
+ COLLECTION_INFO,
}
diff --git a/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantProducer.java b/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantProducer.java
index 05f17e80c4f..67cfc69ef12 100644
--- a/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantProducer.java
+++ b/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantProducer.java
@@ -89,6 +89,8 @@ public class QdrantProducer extends DefaultAsyncProducer {
return retrieve(exchange, callback);
case DELETE:
return delete(exchange, callback);
+ case COLLECTION_INFO:
+ return collectionInfo(exchange, callback);
default:
throw new UnsupportedOperationException("Unsupported action: " + action.name());
}
@@ -171,6 +173,26 @@ public class QdrantProducer extends DefaultAsyncProducer {
return false;
}
+ private boolean collectionInfo(Exchange exchange, AsyncCallback callback) throws Exception {
+ final String collection = getEndpoint().getCollection();
+ final Message in = exchange.getMessage();
+
+ call(
+ this.client.getCollectionInfoAsync(collection),
+
+ (r, t) -> {
+ if (t != null) {
+ exchange.setException(new QdrantActionException(QdrantAction.COLLECTION_INFO, t));
+ } else {
+ in.setBody(r);
+ }
+
+ callback.done(false);
+ });
+
+ return false;
+ }
+
private boolean delete(Exchange exchange, AsyncCallback callback) throws Exception {
final String collection = getEndpoint().getCollection();
final Message in = exchange.getMessage();
diff --git a/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/QdrantCommonTest.java b/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/QdrantCommonTest.java
index 52d6f772319..b43cf6f1d4d 100644
--- a/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/QdrantCommonTest.java
+++ b/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/QdrantCommonTest.java
@@ -38,7 +38,15 @@ public final class QdrantCommonTest extends CamelTestSupport {
.request(Exchange.class);
assertThat(result).isNotNull();
- assertThat(result.getException()).isInstanceOf(InvalidPayloadException.class);
- assertThat(result.getException().getMessage()).contains("No body available of type");
+
+ if (action == QdrantAction.COLLECTION_INFO) {
+ // null body is OK for collection info, but it throws an specific exception
+ // if the collection doesn't exist
+ assertThat(result.getException()).isInstanceOf(QdrantActionException.class);
+ } else {
+ assertThat(result.getException()).isInstanceOf(InvalidPayloadException.class);
+ assertThat(result.getException().getMessage()).contains("No body available of type");
+ }
+
}
}
diff --git a/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/it/QdrantComponentIT.java b/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/it/QdrantComponentIT.java
index bc3223c3ea6..9af813ff2e3 100644
--- a/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/it/QdrantComponentIT.java
+++ b/components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/it/QdrantComponentIT.java
@@ -20,6 +20,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
+import io.grpc.Status;
+import io.grpc.StatusRuntimeException;
import io.qdrant.client.ConditionFactory;
import io.qdrant.client.PointIdFactory;
import io.qdrant.client.ValueFactory;
@@ -29,6 +31,7 @@ import io.qdrant.client.grpc.Points;
import org.apache.camel.Exchange;
import org.apache.camel.component.qdrant.Qdrant;
import org.apache.camel.component.qdrant.QdrantAction;
+import org.apache.camel.component.qdrant.QdrantActionException;
import org.apache.camel.component.qdrant.QdrantTestSupport;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -39,6 +42,27 @@ import static org.assertj.core.api.Assertions.assertThat;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class QdrantComponentIT extends QdrantTestSupport {
+
+ @Test
+ @Order(0)
+ public void collectionInfoNonExistent() {
+ Exchange result = fluentTemplate.to("qdrant:testComponent")
+ .withHeader(Qdrant.Headers.ACTION, QdrantAction.COLLECTION_INFO)
+ .request(Exchange.class);
+
+ assertThat(result).isNotNull();
+ assertThat(result.getException()).isInstanceOf(QdrantActionException.class);
+
+ final QdrantActionException exception = result.getException(QdrantActionException.class);
+ final Throwable cause = exception.getCause();
+
+ assertThat(cause).isNotNull();
+ assertThat(cause).isInstanceOf(StatusRuntimeException.class);
+
+ StatusRuntimeException statusRuntimeException = (StatusRuntimeException) cause;
+ assertThat(statusRuntimeException.getStatus().getCode()).isEqualTo(Status.NOT_FOUND.getCode());
+ }
+
@Test
@Order(1)
public void createCollection() {
@@ -56,6 +80,18 @@ public class QdrantComponentIT extends QdrantTestSupport {
@Test
@Order(2)
+ public void collectionInfoExistent() {
+ Exchange result = fluentTemplate.to("qdrant:testComponent")
+ .withHeader(Qdrant.Headers.ACTION, QdrantAction.COLLECTION_INFO)
+ .request(Exchange.class);
+
+ assertThat(result).isNotNull();
+ assertThat(result.getException()).isNull();
+ assertThat(result.getMessage().getBody()).isInstanceOf(Collections.CollectionInfo.class);
+ }
+
+ @Test
+ @Order(3)
public void upsert() {
Exchange result = fluentTemplate.to("qdrant:testComponent")
.withHeader(Qdrant.Headers.ACTION, QdrantAction.UPSERT)
@@ -84,7 +120,7 @@ public class QdrantComponentIT extends QdrantTestSupport {
}
@Test
- @Order(3)
+ @Order(4)
@SuppressWarnings({ "unchecked" })
public void retrieve() {
Exchange result = fluentTemplate.to("qdrant:testComponent")
@@ -102,7 +138,7 @@ public class QdrantComponentIT extends QdrantTestSupport {
}
@Test
- @Order(4)
+ @Order(5)
public void delete() {
Exchange result = fluentTemplate.to("qdrant:testComponent")
.withHeader(Qdrant.Headers.ACTION, QdrantAction.DELETE)
@@ -124,7 +160,7 @@ public class QdrantComponentIT extends QdrantTestSupport {
}
@Test
- @Order(5)
+ @Order(6)
public void retrieveAfterDelete() {
Exchange result = fluentTemplate.to("qdrant:testComponent")
.withHeader(Qdrant.Headers.ACTION, QdrantAction.RETRIEVE)