This is an automated email from the ASF dual-hosted git repository. fmariani pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit c5b75cc2ca33964ab335d563576778752a9e804d Author: Guillaume Nodet <[email protected]> AuthorDate: Mon Mar 23 21:16:49 2026 +0100 Restore original raw SDK tests alongside helper-based tests - Restore the original MilvusCreateCollectionTest using raw SDK objects (CollectionSchemaParam with withShardsNum and withEnableDynamicField) - Restore the original MilvusComponentIT tests using raw SDK objects (CreateCollectionParam, CreateIndexParam with indexName, SearchSimpleParam with offset, DeleteParam) - Keep the helper-based tests as additional test methods to cover both code paths Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../milvus/MilvusCreateCollectionTest.java | 69 ++++++- .../component/milvus/it/MilvusComponentIT.java | 225 ++++++++++++++++----- 2 files changed, 232 insertions(+), 62 deletions(-) diff --git a/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/MilvusCreateCollectionTest.java b/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/MilvusCreateCollectionTest.java index 1918defe59c9..a5499a07f6e3 100644 --- a/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/MilvusCreateCollectionTest.java +++ b/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/MilvusCreateCollectionTest.java @@ -17,6 +17,10 @@ package org.apache.camel.component.milvus; +import io.milvus.grpc.DataType; +import io.milvus.param.collection.CollectionSchemaParam; +import io.milvus.param.collection.CreateCollectionParam; +import io.milvus.param.collection.FieldType; import org.apache.camel.Exchange; import org.apache.camel.NoSuchHeaderException; import org.apache.camel.component.milvus.helpers.MilvusHelperCreateCollection; @@ -30,18 +34,63 @@ public class MilvusCreateCollectionTest extends MilvusTestSupport { @DisplayName("Tests that trying to create a collection without passing the action name triggers a failure") @Test - public void createCollectionWithoutRequiredParameters() throws Exception { - MilvusHelperCreateCollection ragCreateCollection = new MilvusHelperCreateCollection(); - ragCreateCollection.setCollectionName("test"); - ragCreateCollection.setCollectionDescription("customer info"); - ragCreateCollection.setIdFieldName("userID"); - ragCreateCollection.setVectorFieldName("userFace"); - ragCreateCollection.setTextFieldName("userAge"); - ragCreateCollection.setTextFieldDataType("Int8"); - ragCreateCollection.setDimension("64"); + public void createCollectionWithoutRequiredParameters() { + FieldType fieldType1 = FieldType.newBuilder() + .withName("userID") + .withDescription("user identification") + .withDataType(DataType.Int64) + .withPrimaryKey(true) + .withAutoID(true) + .build(); + + FieldType fieldType2 = FieldType.newBuilder() + .withName("userFace") + .withDescription("face embedding") + .withDataType(DataType.FloatVector) + .withDimension(64) + .build(); + + FieldType fieldType3 = FieldType.newBuilder() + .withName("userAge") + .withDescription("user age") + .withDataType(DataType.Int8) + .build(); + + CreateCollectionParam createCollectionReq = CreateCollectionParam.newBuilder() + .withCollectionName("test") + .withDescription("customer info") + .withShardsNum(2) + .withSchema(CollectionSchemaParam.newBuilder() + .withEnableDynamicField(false) + .addFieldType(fieldType1) + .addFieldType(fieldType2) + .addFieldType(fieldType3) + .build()) + .build(); + + Exchange result = fluentTemplate.to("milvus:createCollection") + .withBody( + createCollectionReq) + .request(Exchange.class); + + assertThat(result).isNotNull(); + assertThat(result.getException()).isInstanceOf(NoSuchHeaderException.class); + } + + @DisplayName("Tests that trying to create a collection via helper without passing the action name triggers a failure") + @Test + public void createCollectionWithHelperWithoutRequiredParameters() throws Exception { + MilvusHelperCreateCollection helper = new MilvusHelperCreateCollection(); + helper.setCollectionName("test"); + helper.setCollectionDescription("customer info"); + helper.setIdFieldName("userID"); + helper.setVectorFieldName("userFace"); + helper.setTextFieldName("userAge"); + helper.setTextFieldDataType("Int8"); + helper.setDimension("64"); Exchange tempExchange = new DefaultExchange(context); - ragCreateCollection.process(tempExchange); + helper.process(tempExchange); // Send body without the action header to trigger failure Exchange result = fluentTemplate.to("milvus:createCollection") diff --git a/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/it/MilvusComponentIT.java b/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/it/MilvusComponentIT.java index 6d12b6f21b46..ba6c42e6b0eb 100644 --- a/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/it/MilvusComponentIT.java +++ b/components/camel-ai/camel-milvus/src/test/java/org/apache/camel/component/milvus/it/MilvusComponentIT.java @@ -21,11 +21,18 @@ import java.util.List; import java.util.Random; import io.milvus.common.clientenum.ConsistencyLevelEnum; +import io.milvus.grpc.DataType; import io.milvus.grpc.QueryResults; import io.milvus.param.IndexType; +import io.milvus.param.MetricType; +import io.milvus.param.collection.CollectionSchemaParam; +import io.milvus.param.collection.CreateCollectionParam; +import io.milvus.param.collection.FieldType; +import io.milvus.param.dml.DeleteParam; import io.milvus.param.dml.InsertParam; import io.milvus.param.dml.QueryParam; import io.milvus.param.dml.UpsertParam; +import io.milvus.param.highlevel.dml.SearchSimpleParam; import io.milvus.param.highlevel.dml.response.SearchResponse; import io.milvus.param.index.CreateIndexParam; import org.apache.camel.Exchange; @@ -46,22 +53,43 @@ import static org.assertj.core.api.Assertions.assertThat; public class MilvusComponentIT extends MilvusTestSupport { @Test @Order(1) - public void createCollection() throws Exception { - MilvusHelperCreateCollection ragCreateCollection = new MilvusHelperCreateCollection(); - ragCreateCollection.setCollectionName("test"); - ragCreateCollection.setCollectionDescription("customer info"); - ragCreateCollection.setIdFieldName("userID"); - ragCreateCollection.setVectorFieldName("userFace"); - ragCreateCollection.setTextFieldName("userAge"); - ragCreateCollection.setTextFieldDataType("Int8"); - ragCreateCollection.setDimension("64"); + public void createCollection() { + FieldType fieldType1 = FieldType.newBuilder() + .withName("userID") + .withDescription("user identification") + .withDataType(DataType.Int64) + .withPrimaryKey(true) + .withAutoID(true) + .build(); - Exchange tempExchange = new DefaultExchange(context); - ragCreateCollection.process(tempExchange); + FieldType fieldType2 = FieldType.newBuilder() + .withName("userFace") + .withDescription("face embedding") + .withDataType(DataType.FloatVector) + .withDimension(64) + .build(); + + FieldType fieldType3 = FieldType.newBuilder() + .withName("userAge") + .withDescription("user age") + .withDataType(DataType.Int8) + .build(); + + CreateCollectionParam createCollectionReq = CreateCollectionParam.newBuilder() + .withCollectionName("test") + .withDescription("customer info") + .withShardsNum(2) + .withSchema(CollectionSchemaParam.newBuilder() + .withEnableDynamicField(false) + .addFieldType(fieldType1) + .addFieldType(fieldType2) + .addFieldType(fieldType3).build()) + .build(); Exchange result = fluentTemplate.to("milvus:test") - .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) - .withBody(tempExchange.getIn().getBody()) + .withHeader(MilvusHeaders.ACTION, MilvusAction.CREATE_COLLECTION) + .withBody( + createCollectionReq) .request(Exchange.class); assertThat(result).isNotNull(); @@ -70,7 +98,7 @@ public class MilvusComponentIT extends MilvusTestSupport { @Test @Order(2) - public void createIndex() throws Exception { + public void createIndex() { CreateIndexParam createAgeIndexParam = CreateIndexParam.newBuilder() .withCollectionName("test") .withFieldName("userAge") @@ -87,19 +115,20 @@ public class MilvusComponentIT extends MilvusTestSupport { assertThat(result).isNotNull(); assertThat(result.getException()).isNull(); - MilvusHelperCreateIndex ragCreateIndex = new MilvusHelperCreateIndex(); - ragCreateIndex.setCollectionName("test"); - ragCreateIndex.setVectorFieldName("userFace"); - ragCreateIndex.setIndexType("IVF_FLAT"); - ragCreateIndex.setMetricType("L2"); - ragCreateIndex.setExtraParam("{\"nlist\":128}"); - - Exchange tempExchange = new DefaultExchange(context); - ragCreateIndex.process(tempExchange); + CreateIndexParam createVectorIndexParam = CreateIndexParam.newBuilder() + .withCollectionName("test") + .withFieldName("userFace") + .withIndexName("userFaceIndex") + .withIndexType(IndexType.IVF_FLAT) + .withMetricType(MetricType.L2) + .withExtraParam("{\"nlist\":128}") + .withSyncMode(Boolean.TRUE) + .build(); result = fluentTemplate.to("milvus:test") - .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) - .withBody(tempExchange.getIn().getBody()) + .withHeader(MilvusHeaders.ACTION, MilvusAction.CREATE_INDEX) + .withBody( + createVectorIndexParam) .request(Exchange.class); assertThat(result).isNotNull(); @@ -163,20 +192,21 @@ public class MilvusComponentIT extends MilvusTestSupport { @Test @Order(5) - public void search() throws Exception { - MilvusHelperSearch ragSearch = new MilvusHelperSearch(); - ragSearch.setCollectionName("test"); - ragSearch.setOutputFields("userAge"); - ragSearch.setFilter("userAge>0"); - ragSearch.setLimit("100"); - - Exchange tempExchange = new DefaultExchange(context); - tempExchange.getIn().setBody(generateFloatVector()); - ragSearch.process(tempExchange); + public void search() { + SearchSimpleParam searchSimpleParam = SearchSimpleParam.newBuilder() + .withCollectionName("test") + .withVectors(generateFloatVector()) + .withFilter("userAge>0") + .withLimit(100L) + .withOffset(0L) + .withOutputFields(Lists.newArrayList("userAge")) + .withConsistencyLevel(ConsistencyLevelEnum.STRONG) + .build(); Exchange result = fluentTemplate.to("milvus:test") - .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) - .withBody(tempExchange.getIn().getBody()) + .withHeader(MilvusHeaders.ACTION, MilvusAction.SEARCH) + .withBody( + searchSimpleParam) .request(Exchange.class); assertThat(result).isNotNull(); @@ -207,40 +237,131 @@ public class MilvusComponentIT extends MilvusTestSupport { @Test @Order(7) - public void delete() throws Exception { - MilvusHelperDelete ragDelete = new MilvusHelperDelete(); - ragDelete.setCollectionName("test"); - ragDelete.setFilter("userAge>0"); + public void delete() { + DeleteParam delete = DeleteParam.newBuilder() + .withCollectionName("test") + .withExpr("userAge>0") + .build(); + + Exchange result = fluentTemplate.to("milvus:test") + .withHeader(MilvusHeaders.ACTION, MilvusAction.DELETE) + .withBody( + delete) + .request(Exchange.class); + + assertThat(result).isNotNull(); + assertThat(result.getException()).isNull(); + + SearchSimpleParam searchSimpleParam = SearchSimpleParam.newBuilder() + .withCollectionName("test") + .withVectors(generateFloatVector()) + .withFilter("userAge>0") + .withLimit(100L) + .withOffset(0L) + .withOutputFields(Lists.newArrayList("userAge")) + .withConsistencyLevel(ConsistencyLevelEnum.STRONG) + .build(); + + result = fluentTemplate.to("milvus:test") + .withHeader(MilvusHeaders.ACTION, MilvusAction.SEARCH) + .withBody( + searchSimpleParam) + .request(Exchange.class); + + assertThat(result).isNotNull(); + assertThat(result.getException()).isNull(); + assertThat(result.getMessage().getBody(SearchResponse.class).getRowRecords().size() == 0); + } + + // --- Helper-based tests (same operations via MilvusHelper beans) --- + + @Test + @Order(10) + public void createCollectionWithHelper() throws Exception { + MilvusHelperCreateCollection helper = new MilvusHelperCreateCollection(); + helper.setCollectionName("test_helper"); + helper.setCollectionDescription("helper test collection"); + helper.setIdFieldName("userID"); + helper.setVectorFieldName("userFace"); + helper.setTextFieldName("userAge"); + helper.setTextFieldDataType("Int8"); + helper.setDimension("64"); Exchange tempExchange = new DefaultExchange(context); - ragDelete.process(tempExchange); + helper.process(tempExchange); - Exchange result = fluentTemplate.to("milvus:test") + Exchange result = fluentTemplate.to("milvus:test_helper") + .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) + .withBody(tempExchange.getIn().getBody()) + .request(Exchange.class); + + assertThat(result).isNotNull(); + assertThat(result.getException()).isNull(); + } + + @Test + @Order(11) + public void createIndexWithHelper() throws Exception { + MilvusHelperCreateIndex helper = new MilvusHelperCreateIndex(); + helper.setCollectionName("test_helper"); + helper.setVectorFieldName("userFace"); + helper.setIndexName("userFaceIndex"); + helper.setIndexType("IVF_FLAT"); + helper.setMetricType("L2"); + helper.setExtraParam("{\"nlist\":128}"); + + Exchange tempExchange = new DefaultExchange(context); + helper.process(tempExchange); + + Exchange result = fluentTemplate.to("milvus:test_helper") .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) .withBody(tempExchange.getIn().getBody()) .request(Exchange.class); assertThat(result).isNotNull(); assertThat(result.getException()).isNull(); + } - MilvusHelperSearch ragSearch = new MilvusHelperSearch(); - ragSearch.setCollectionName("test"); - ragSearch.setOutputFields("userAge"); - ragSearch.setFilter("userAge>0"); - ragSearch.setLimit("100"); + @Test + @Order(12) + public void searchWithHelper() throws Exception { + MilvusHelperSearch helper = new MilvusHelperSearch(); + helper.setCollectionName("test"); + helper.setOutputFields("userAge"); + helper.setFilter("userAge>0"); + helper.setLimit("100"); + helper.setOffset("0"); - tempExchange = new DefaultExchange(context); + Exchange tempExchange = new DefaultExchange(context); tempExchange.getIn().setBody(generateFloatVector()); - ragSearch.process(tempExchange); + helper.process(tempExchange); - result = fluentTemplate.to("milvus:test") + Exchange result = fluentTemplate.to("milvus:test") + .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) + .withBody(tempExchange.getIn().getBody()) + .request(Exchange.class); + + assertThat(result).isNotNull(); + assertThat(result.getException()).isNull(); + } + + @Test + @Order(13) + public void deleteWithHelper() throws Exception { + MilvusHelperDelete helper = new MilvusHelperDelete(); + helper.setCollectionName("test_helper"); + helper.setFilter("userAge>0"); + + Exchange tempExchange = new DefaultExchange(context); + helper.process(tempExchange); + + Exchange result = fluentTemplate.to("milvus:test_helper") .withHeader(MilvusHeaders.ACTION, tempExchange.getIn().getHeader(MilvusHeaders.ACTION)) .withBody(tempExchange.getIn().getBody()) .request(Exchange.class); assertThat(result).isNotNull(); assertThat(result.getException()).isNull(); - assertThat(result.getMessage().getBody(SearchResponse.class).getRowRecords().size() == 0); } private List<List<Float>> generateFloatVectors(int count) {
