未验证 提交 4c23773e 编写于 作者: T ThreadDao 提交者: GitHub

[skip ci] refine java sdk test (#4001)

* update java sdk test because of new pr
Signed-off-by: NThreadDao <zongyufen@foxmail.com>

* delete and compact, and fix exception case
Signed-off-by: NThreadDao <zongyufen@foxmail.com>

* TestSearchEntities
Signed-off-by: Nsahuang <xiaohai.xu@zilliz.com>

* TestPartition
Signed-off-by: Nsahuang <xiaohai.xu@zilliz.com>

* java test delete, getEntity and index, insert
Signed-off-by: NThreadDao <zongyufen@foxmail.com>

* fix binary case
Signed-off-by: NThreadDao <zongyufen@foxmail.com>
Co-authored-by: Nsahuang <xiaohai.xu@zilliz.com>
上级 eb4a14ad
......@@ -10,59 +10,59 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.10" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
<orderEntry type="library" name="Maven: org.testng:testng:6.14.3" level="project" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.72" level="project" />
<orderEntry type="library" name="Maven: org.apache-extras.beanshell:bsh:2.0b6" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.68" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.13" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: io.milvus:milvus-sdk-java:0.8.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven.plugins:maven-gpg-plugin:1.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-project:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-settings:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-profile:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact-manager:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven.wagon:wagon-provider-api:1.0-beta-6" level="project" />
<orderEntry type="library" name="Maven: backport-util-concurrent:backport-util-concurrent:3.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-registry:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-interpolation:1.11" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9-stable-1" level="project" />
<orderEntry type="library" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-repository-metadata:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:2.2.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-utils:3.0.20" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-sec-dispatcher:1.4" level="project" />
<orderEntry type="library" name="Maven: org.sonatype.plexus:plexus-cipher:1.4" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.grpc:grpc-netty-shaded:1.27.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.grpc:grpc-core:1.27.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.android:annotations:4.1.1.4" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.perfmark:perfmark-api:0.19.0" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-protobuf:1.27.2" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-api:1.27.2" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-context:1.27.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.18" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.11.0" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:28.1-android" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-protobuf-lite:1.27.2" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-stub:1.27.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.11" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
<orderEntry type="library" name="Maven: org.testng:testng:6.14.3" level="project" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.72" level="project" />
<orderEntry type="library" name="Maven: org.apache-extras.beanshell:bsh:2.0b6" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.73" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.13" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: io.milvus:milvus-sdk-java:0.9.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-protobuf:1.30.2" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-api:1.30.2" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-context:1.30.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.12.0" level="project" />
<orderEntry type="library" name="Maven: com.google.api.grpc:proto-google-common-protos:1.17.0" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-protobuf-lite:1.30.2" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:28.2-android" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.5.5" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: com.google.api.grpc:proto-google-common-protos:1.17.0" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-protobuf-lite:1.27.2" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-stub:1.27.2" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java-util:3.11.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.18" level="project" />
<orderEntry type="library" name="Maven: io.grpc:grpc-stub:1.30.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.grpc:grpc-netty-shaded:1.30.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.grpc:grpc-core:1.30.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.android:annotations:4.1.1.4" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.perfmark:perfmark-api:0.19.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.12.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.12.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-core:2.12.1" level="project" />
<orderEntry type="library" name="Maven: org.testcontainers:testcontainers:1.14.3" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.20" level="project" />
<orderEntry type="library" name="Maven: org.rnorth.duct-tape:duct-tape:1.0.8" level="project" />
<orderEntry type="library" name="Maven: org.rnorth.visible-assertions:visible-assertions:2.1.2" level="project" />
<orderEntry type="library" name="Maven: org.rnorth:tcp-unix-socket-proxy:1.0.2" level="project" />
<orderEntry type="library" name="Maven: com.kohlschutter.junixsocket:junixsocket-native-common:2.0.4" level="project" />
<orderEntry type="library" name="Maven: org.scijava:native-lib-loader:2.0.2" level="project" />
<orderEntry type="library" name="Maven: com.kohlschutter.junixsocket:junixsocket-common:2.0.4" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:5.5.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:5.5.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-simple:1.7.30" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -118,6 +118,17 @@
<artifactId>milvus-sdk-java</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.14.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.grpc</groupId>-->
......
package com;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import io.milvus.client.*;
public final class Constants {
......@@ -19,39 +21,39 @@ public final class Constants {
public static final double epsilon = 0.001;
public static final int segmentRowLimit = 5000;
public static final String fieldNameKey = "name";
public static final String vectorType = "float";
public static final String binaryVectorType = "binary";
public static final String defaultMetricType = "L2";
public static final MetricType defaultMetricType = MetricType.L2;
public static final String indexType = "IVF_SQ8";
public static final IndexType indexType = IndexType.IVF_SQ8;
public static final String defaultIndexType = "FLAT";
public static final IndexType defaultIndexType = IndexType.FLAT;
public static final String defaultBinaryIndexType = "BIN_FLAT";
public static final IndexType defaultBinaryIndexType = IndexType.BIN_IVF_FLAT;
public static final String defaultBinaryMetricType = "JACCARD";
public static final MetricType defaultBinaryMetricType = MetricType.JACCARD;
public static final String floatFieldName = "float_vector";
public static final String intFieldName = "int64";
public static final String binaryFieldName = "binary_vector";
public static final String floatFieldName = "float";
public static final String indexParam = Utils.setIndexParam(indexType, "L2", n_list);
public static final String floatVectorFieldName = "float_vector";
public static final String binaryIndexParam = Utils.setIndexParam(defaultBinaryIndexType, defaultBinaryMetricType, n_list);
public static final String binaryVectorFieldName = "binary_vector";
public static final List<List<Float>> vectors = Utils.genVectors(nb, dimension, true);
public static final List<List<Byte>> vectorsBinary = Utils.genBinaryVectors(nb, dimension);
public static final List<Map<String,Object>> defaultFields = Utils.genDefaultFields(dimension,false);
public static final List<Map<String,Object>> defaultBinaryFields = Utils.genDefaultFields(dimension,true);
public static final List<ByteBuffer> vectorsBinary = Utils.genBinaryVectors(nb, dimension);
public static final List<Map<String,Object>> defaultEntities = Utils.genDefaultEntities(dimension, nb, vectors);
public static final Map<String, List> defaultEntities = Utils.genDefaultEntities(nb, vectors);
public static final List<Map<String,Object>> defaultBinaryEntities = Utils.genDefaultBinaryEntities(dimension, nb, vectorsBinary);
public static final Map<String, List> defaultBinaryEntities = Utils.genDefaultBinaryEntities(nb, vectorsBinary);
public static final String searchParam = Utils.setSearchParam(defaultMetricType, vectors.subList(0, nq), topk, n_probe);
......
......@@ -3,7 +3,6 @@ package com;
import io.milvus.client.*;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.testng.SkipException;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.xml.XmlClass;
......@@ -12,16 +11,17 @@ import org.testng.xml.XmlTest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class MainClass {
private static String HOST = "127.0.0.1";
// private static String HOST = "192.168.1.238";
private static int PORT = 19530;
private int segmentRowCount = 5000;
private static ConnectParam CONNECT_PARAM = new ConnectParam.Builder()
.withHost(HOST)
.withPort(PORT)
.build();
private static MilvusClient client;
public static void setHost(String host) {
MainClass.HOST = host;
......@@ -45,77 +45,67 @@ public class MainClass {
}
@DataProvider(name="ConnectInstance")
public Object[][] connectInstance() throws ConnectFailedException {
MilvusClient client = new MilvusGrpcClient();
public Object[][] connectInstance() throws Exception {
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(HOST)
.withPort(PORT)
.build();
client.connect(connectParam);
client = new MilvusGrpcClient(connectParam).withLogging();
String collectionName = RandomStringUtils.randomAlphabetic(10);
return new Object[][]{{client, collectionName}};
}
@DataProvider(name="DisConnectInstance")
public Object[][] disConnectInstance() throws ConnectFailedException {
public Object[][] disConnectInstance(){
// Generate connection instance
MilvusClient client = new MilvusGrpcClient();
client.connect(CONNECT_PARAM);
try {
client.disconnect();
} catch (InterruptedException e) {
e.printStackTrace();
}
client = new MilvusGrpcClient(CONNECT_PARAM).withLogging();
client.close();
String collectionName = RandomStringUtils.randomAlphabetic(10);
return new Object[][]{{client, collectionName}};
}
private Object[][] genCollection(boolean isBinary, boolean autoId) throws ConnectFailedException {
private Object[][] genCollection(boolean isBinary, boolean autoId) throws Exception {
Object[][] collection;
String collectionName = Utils.genUniqueStr("collection");
List<Map<String, Object>> defaultFields = Utils.genDefaultFields(Constants.dimension,isBinary);
String jsonParams = String.format("{\"segment_row_count\": %s, \"auto_id\": %s}",segmentRowCount, autoId);
// Generate connection instance
MilvusClient client = new MilvusGrpcClient();
client.connect(CONNECT_PARAM);
CollectionMapping cm = new CollectionMapping.Builder(collectionName)
.withFields(defaultFields)
.withParamsInJson(jsonParams)
.build();
Response res = client.createCollection(cm);
if (!res.ok()) {
System.out.println(res.getMessage());
throw new SkipException("Collection created failed");
client = new MilvusGrpcClient(CONNECT_PARAM).withLogging();
CollectionMapping cm = CollectionMapping
.create(collectionName)
.addField(Constants.intFieldName, DataType.INT64)
.addField(Constants.floatFieldName, DataType.FLOAT)
.setParamsInJson(new JsonBuilder()
.param("segment_row_limit", segmentRowCount)
.param("auto_id", autoId)
.build());
if (isBinary) {
cm.addVectorField("binary_vector", DataType.VECTOR_BINARY, Constants.dimension);
} else {
cm.addVectorField("float_vector", DataType.VECTOR_FLOAT, Constants.dimension);
}
client.createCollection(cm);
collection = new Object[][]{{client, collectionName}};
return collection;
}
@DataProvider(name="Collection")
public Object[][] provideCollection() throws ConnectFailedException, InterruptedException {
public Object[][] provideCollection() throws Exception, InterruptedException {
Object[][] collection = genCollection(false,true);
return collection;
// List<String> tableNames = client.listCollections().getCollectionNames();
// for (int j = 0; j < tableNames.size(); ++j
// ) {
// client.dropCollection(tableNames.get(j));
// }
// Thread.currentThread().sleep(2000);
}
@DataProvider(name="IdCollection")
public Object[][] provideIdCollection() throws ConnectFailedException, InterruptedException {
public Object[][] provideIdCollection() throws Exception, InterruptedException {
Object[][] idCollection = genCollection(false,false);
return idCollection;
}
@DataProvider(name="BinaryCollection")
public Object[][] provideBinaryCollection() throws ConnectFailedException, InterruptedException {
public Object[][] provideBinaryCollection() throws Exception, InterruptedException {
Object[][] binaryCollection = genCollection(true,true);
return binaryCollection;
}
@DataProvider(name="BinaryIdCollection")
public Object[][] provideBinaryIdCollection() throws ConnectFailedException, InterruptedException {
public Object[][] provideBinaryIdCollection() throws Exception, InterruptedException {
Object[][] binaryIdCollection = genCollection(true,false);
return binaryIdCollection;
}
......
......@@ -2,165 +2,150 @@ package com;
import com.alibaba.fastjson.JSONObject;
import io.milvus.client.*;
import io.milvus.client.exception.ClientSideMilvusException;
import io.milvus.client.exception.ServerSideMilvusException;
import org.testng.Assert;
import org.testng.annotations.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class TestCollection {
int segmentRowCount = 5000;
int dimension = 128;
String intFieldName = Constants.intFieldName;
String floatFieldName = Constants.floatFieldName;
String floatVectorFieldName = Constants.floatVectorFieldName;
Boolean autoId = true;
// case-01
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testCreateCollection(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema = new CollectionMapping.Builder(collectionName)
.withFields(Utils.genDefaultFields(dimension,false))
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
Response res = client.createCollection(collectionSchema);
assert(res.ok());
Assert.assertEquals(res.ok(), true);
// Generate connection instance
CollectionMapping cm = Utils.genCreateCollectionMapping(collectionName, true,false);
client.createCollection(cm);
Assert.assertEquals(client.hasCollection(collectionName), true);
}
// case-02
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testCreateCollectionDisconnect(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema = new CollectionMapping.Builder(collectionName)
.withFields(Utils.genDefaultFields(dimension,false))
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
Response res = client.createCollection(collectionSchema);
assert(!res.ok());
CollectionMapping cm = Utils.genCreateCollectionMapping(collectionName, true, false);
client.createCollection(cm);
}
// case-03
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCreateCollectionRepeatably(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema = new CollectionMapping.Builder(collectionName)
.withFields(Utils.genDefaultFields(dimension,false))
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
Response res = client.createCollection(collectionSchema);
Assert.assertEquals(res.ok(), true);
Response resNew = client.createCollection(collectionSchema);
Assert.assertEquals(resNew.ok(), false);
CollectionMapping cm = Utils.genCreateCollectionMapping(collectionName, true, false);
client.createCollection(cm);
Assert.assertEquals(client.hasCollection(collectionName), true);
client.createCollection(cm);
}
// case-04
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCreateCollectionWrongParams(MilvusClient client, String collectionName) {
Integer dim = 0;
CollectionMapping collectionSchema = new CollectionMapping.Builder(collectionName)
.withFields(Utils.genDefaultFields(dim,false))
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
Response res = client.createCollection(collectionSchema);
System.out.println(res.toString());
Assert.assertEquals(res.ok(), false);
CollectionMapping cm = CollectionMapping.create(collectionName)
.addField(intFieldName, DataType.INT64)
.addField(floatFieldName, DataType.FLOAT)
.addVectorField(floatVectorFieldName, DataType.VECTOR_FLOAT, dim)
.setParamsInJson(new JsonBuilder()
.param("segment_row_limit", Constants.segmentRowLimit)
.param("auto_id", autoId)
.build());
client.createCollection(cm);
}
// case-05
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testShowCollections(MilvusClient client, String collectionName) {
Integer collectionNum = 10;
ListCollectionsResponse res = null;
List<String> originCollections = new ArrayList<>();
for (int i = 0; i < collectionNum; ++i) {
String collectionNameNew = collectionName+"_"+Integer.toString(i);
CollectionMapping collectionSchema = new CollectionMapping.Builder(collectionNameNew)
.withFields(Utils.genDefaultFields(dimension,false))
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
client.createCollection(collectionSchema);
List<String> collectionNames = client.listCollections().getCollectionNames();
Assert.assertTrue(collectionNames.contains(collectionNameNew));
originCollections.add(collectionNameNew);
CollectionMapping cm = Utils.genCreateCollectionMapping(collectionNameNew, true, false);
client.createCollection(cm);
}
List<String> listCollections = client.listCollections();
originCollections.stream().forEach(listCollections::contains);
}
// case-06
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testShowCollectionsWithoutConnect(MilvusClient client, String collectionName) {
ListCollectionsResponse res = client.listCollections();
assert(!res.getResponse().ok());
client.listCollections();
}
// case-07
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDropCollection(MilvusClient client, String collectionName) throws InterruptedException {
Response res = client.dropCollection(collectionName);
assert(res.ok());
Thread.currentThread().sleep(1000);
List<String> collectionNames = client.listCollections().getCollectionNames();
public void testDropCollection(MilvusClient client, String collectionName) {
client.dropCollection(collectionName);
Assert.assertEquals(client.hasCollection(collectionName), false);
// Thread.currentThread().sleep(1000);
List<String> collectionNames = client.listCollections();
Assert.assertFalse(collectionNames.contains(collectionName));
}
// case-08
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDropCollectionNotExisted(MilvusClient client, String collectionName) {
Response res = client.dropCollection(collectionName+"_");
assert(!res.ok());
List<String> collectionNames = client.listCollections().getCollectionNames();
client.dropCollection(collectionName+"_");
List<String> collectionNames = client.listCollections();
Assert.assertTrue(collectionNames.contains(collectionName));
}
// case-09
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testDropCollectionWithoutConnect(MilvusClient client, String collectionName) {
Response res = client.dropCollection(collectionName);
assert(!res.ok());
client.dropCollection(collectionName);
}
// case-10
// TODO
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDescribeCollection(MilvusClient client, String collectionName) {
GetCollectionInfoResponse res = client.getCollectionInfo(collectionName);
assert(res.getResponse().ok());
CollectionMapping collectionSchema = res.getCollectionMapping().get();
List<Map<String,Object>> fields = (List<Map<String, Object>>) collectionSchema.getFields();
CollectionMapping info = client.getCollectionInfo(collectionName);
List<Map<String,Object>> fields = info.getFields();
System.out.println(fields);
int dim = 0;
for(Map<String,Object> field: fields){
if ("float_vector".equals(field.get("field"))) {
if (floatVectorFieldName.equals(field.get(Constants.fieldNameKey))) {
JSONObject jsonObject = JSONObject.parseObject(field.get("params").toString());
String dimParams = jsonObject.getString("params");
dim = Utils.getParam(dimParams,"dim");
dim = jsonObject.getIntValue("dim");
}
continue;
}
String segmentParams = collectionSchema.getParamsInJson();
Assert.assertEquals(dim, dimension);
Assert.assertEquals(collectionSchema.getCollectionName(), collectionName);
Assert.assertEquals(Utils.getParam(segmentParams,"segment_row_count"), segmentRowCount);
JSONObject params = JSONObject.parseObject(info.getParamsInJson().toString());
Assert.assertEquals(dim, Constants.dimension);
Assert.assertEquals(info.getCollectionName(), collectionName);
Assert.assertEquals(params.getIntValue("segment_row_limit"), Constants.segmentRowLimit);
}
// case-11
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testDescribeCollectionWithoutConnect(MilvusClient client, String collectionName) {
GetCollectionInfoResponse res = client.getCollectionInfo(collectionName);
assert(!res.getResponse().ok());
client.getCollectionInfo(collectionName);
}
// case-12
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testHasCollectionNotExisted(MilvusClient client, String collectionName) {
HasCollectionResponse res = client.hasCollection(collectionName+"_");
assert(res.getResponse().ok());
Assert.assertFalse(res.hasCollection());
String collectionNameNew = collectionName+"_";
Assert.assertFalse(client.hasCollection(collectionNameNew));
}
// case-13
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testHasCollectionWithoutConnect(MilvusClient client, String collectionName) {
HasCollectionResponse res = client.hasCollection(collectionName);
assert(!res.getResponse().ok());
client.hasCollection(collectionName);
}
// case-14
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testHasCollection(MilvusClient client, String collectionName) {
HasCollectionResponse res = client.hasCollection(collectionName);
assert(res.getResponse().ok());
Assert.assertTrue(res.hasCollection());
Assert.assertTrue(client.hasCollection(collectionName));
}
}
package com;
import io.milvus.client.*;
import io.milvus.client.exception.ClientSideMilvusException;
import io.milvus.client.exception.ServerSideMilvusException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
public class TestCollectionCount {
int segmentRowCount = 5000;
int dimension = Constants.dimension;
int nb = Constants.nb;
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCollectionCountNoVectors(MilvusClient client, String collectionName) {
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
Assert.assertEquals(client.countEntities(collectionName), 0);
}
// case-02
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCollectionCountCollectionNotExisted(MilvusClient client, String collectionName) {
CountEntitiesResponse res = client.countEntities(collectionName+"_");
assert(!res.getResponse().ok());
client.countEntities(collectionName+"_");
}
// case-03
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testCollectionCountWithoutConnect(MilvusClient client, String collectionName) {
CountEntitiesResponse res = client.countEntities(collectionName+"_");
assert(!res.getResponse().ok());
client.countEntities(collectionName);
}
// case-04
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCollectionCount(MilvusClient client, String collectionName) throws InterruptedException {
InsertParam insertParam =
new InsertParam.Builder(collectionName)
.withFields(Constants.defaultEntities)
.build();
InsertResponse insertResponse = client.insert(insertParam);
public void testCollectionCount(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genInsertParam(collectionName);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
// Insert returns a list of entity ids that you will be using (if you did not supply the yourself) to reference the entities you just inserted
List<Long> vectorIds = insertResponse.getEntityIds();
// Add vectors
Response flushResponse = client.flush(collectionName);
Assert.assertTrue(flushResponse.ok());
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
Assert.assertEquals(client.countEntities(collectionName), nb);
}
// case-05
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testCollectionCountBinary(MilvusClient client, String collectionName) throws InterruptedException {
public void testCollectionCountBinary(MilvusClient client, String collectionName) {
// Add vectors
InsertParam insertParam = new InsertParam.Builder(collectionName)
.withFields(Constants.defaultBinaryEntities)
.build();
client.insert(insertParam);
InsertParam insertParam = Utils.genBinaryInsertParam(collectionName);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
Assert.assertEquals(client.countEntities(collectionName), nb);
}
// case-06
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCollectionCountMultiCollections(MilvusClient client, String collectionName) throws InterruptedException {
public void testCollectionCountMultiCollections(MilvusClient client, String collectionName) {
Integer collectionNum = 10;
CountEntitiesResponse res;
for (int i = 0; i < collectionNum; ++i) {
String collectionNameNew = collectionName + "_" + i;
CollectionMapping collectionSchema = new CollectionMapping.Builder(collectionNameNew)
.withFields(Utils.genDefaultFields(dimension,false))
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
Response createRes = client.createCollection(collectionSchema);
Assert.assertEquals(createRes.ok(), true);
CollectionMapping cm = Utils.genCreateCollectionMapping(collectionNameNew, true, false);
client.createCollection(cm);
// Add vectors
InsertParam insertParam = new InsertParam.Builder(collectionNameNew)
.withFields(Constants.defaultEntities)
.build();
InsertResponse insertRes = client.insert(insertParam);
Assert.assertEquals(insertRes.ok(), true);
Response flushRes = client.flush(collectionNameNew);
Assert.assertEquals(flushRes.ok(), true);
InsertParam insertParam = Utils.genInsertParam(collectionNameNew);
List<Long> ids = client.insert(insertParam);
client.flush(collectionNameNew);
}
for (int i = 0; i < collectionNum; ++i) {
String collectionNameNew = collectionName + "_" + i;
res = client.countEntities(collectionNameNew);
Assert.assertEquals(res.getCollectionEntityCount(), nb);
Assert.assertEquals(client.countEntities(collectionNameNew), nb);
}
}
}
......
package com;
import io.milvus.client.*;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
public class TestCollectionCount_v2 {
int segmentRowCount = 5000;
int dimension = Constants.dimension;
int nb = Constants.nb;
List<List<Float>> vectors = Constants.vectors;
List<List<Byte>> vectorsBinary = Constants.vectorsBinary;
// case-04
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCollectionCount(MilvusClient client, String collectionName) throws InterruptedException {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse insertResponse = client.insert(insertParam);
// Insert returns a list of entity ids that you will be using (if you did not supply the yourself) to reference the entities you just inserted
List<Long> vectorIds = insertResponse.getEntityIds();
// Add vectors
Response flushResponse = client.flush(collectionName);
Assert.assertTrue(flushResponse.ok());
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
}
// case-05
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testCollectionCountBinary(MilvusClient client, String collectionName) throws InterruptedException {
// Add vectors
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
client.insert(insertParam);
client.flush(collectionName);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
}
// case-06
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCollectionCountMultiCollections(MilvusClient client, String collectionName) throws InterruptedException {
Integer collectionNum = 10;
CountEntitiesResponse res;
for (int i = 0; i < collectionNum; ++i) {
String collectionNameNew = collectionName + "_" + i;
CollectionMapping collectionSchema =
Utils.genDefaultCollectionMapping(collectionNameNew, dimension, segmentRowCount, false);
Response createRes = client.createCollection(collectionSchema);
Assert.assertEquals(createRes.ok(), true);
// Add vectors
InsertParam insertParam = Utils.genDefaultInsertParam(collectionNameNew, dimension, nb, vectors);
InsertResponse insertRes = client.insert(insertParam);
Assert.assertEquals(insertRes.ok(), true);
Response flushRes = client.flush(collectionNameNew);
Assert.assertEquals(flushRes.ok(), true);
}
for (int i = 0; i < collectionNum; ++i) {
String collectionNameNew = collectionName + "_" + i;
res = client.countEntities(collectionNameNew);
Assert.assertEquals(res.getCollectionEntityCount(), nb);
}
}
}
package com;
import com.alibaba.fastjson.JSONObject;
import io.milvus.client.*;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.List;
public class TestCollectionInfo_v2 {
int nb = Constants.nb;
int dimension = Constants.dimension;
int n_list = Constants.n_list;
List<List<Float>> vectors = Constants.vectors;
List<List<Byte>> vectorsBinary = Constants.vectorsBinary;
String indexType = Constants.indexType;
String metricType = Constants.defaultMetricType;
String floatFieldName = Constants.floatFieldName;
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetEntityIdsAfterDeleteEntities(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse resInsert = client.insert(insertParam);
client.flush(collectionName);
List<Long> idsBefore = resInsert.getEntityIds();
client.deleteEntityByID(collectionName, Collections.singletonList(idsBefore.get(0)));
client.flush(collectionName);
Response res = client.getCollectionStats(collectionName);
System.out.println(res.getMessage());
JSONObject collectionInfo = Utils.getCollectionInfo(res.getMessage());
int rowCount = collectionInfo.getIntValue("row_count");
assert(rowCount == nb - 1);
}
// case-02
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetEntityIdsAterDeleteEntitiesIndexed(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse resInsert = client.insert(insertParam);
client.flush(collectionName);
Index index = Utils.genDefaultIndex(collectionName, floatFieldName, indexType, metricType, n_list);
Response createIndexResponse = client.createIndex(index);
assert(createIndexResponse.ok());
List<Long> idsBefore = resInsert.getEntityIds();
client.deleteEntityByID(collectionName, Collections.singletonList(idsBefore.get(0)));
client.flush(collectionName);
Response res = client.getCollectionStats(collectionName);
System.out.println(res.getMessage());
JSONObject collectionInfo = Utils.getCollectionInfo(res.getMessage());
int rowCount = collectionInfo.getIntValue("row_count");
assert(rowCount == nb - 1);
}
// case-03
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testGetEntityIdsAfterDeleteEntitiesBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
InsertResponse resInsert = client.insert(insertParam);
client.flush(collectionName);
List<Long> idsBefore = resInsert.getEntityIds();
client.deleteEntityByID(collectionName, Collections.singletonList(idsBefore.get(0)));
client.flush(collectionName);
Response res = client.getCollectionStats(collectionName);
System.out.println(res.getMessage());
JSONObject collectionInfo = Utils.getCollectionInfo(res.getMessage());
int rowCount = collectionInfo.getIntValue("row_count");
assert(rowCount == nb - 1);
}
}
\ No newline at end of file
......@@ -7,64 +7,55 @@ import org.testng.annotations.Test;
import java.util.Collections;
import java.util.List;
public class TestCollectionInfo {
public class TestCollectionStats {
int nb = Constants.nb;
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetEntityIdsAfterDeleteEntities(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName)
.withFields(Constants.defaultEntities)
.build();
InsertResponse resInsert = client.insert(insertParam);
InsertParam insertParam = Utils.genInsertParam(collectionName);
List<Long> idsBefore = client.insert(insertParam);
client.flush(collectionName);
List<Long> idsBefore = resInsert.getEntityIds();
client.deleteEntityByID(collectionName, Collections.singletonList(idsBefore.get(0)));
client.flush(collectionName);
Response res = client.getCollectionStats(collectionName);
System.out.println(res.getMessage());
JSONObject collectionInfo = Utils.getCollectionInfo(res.getMessage());
int rowCount = collectionInfo.getIntValue("row_count");
String stats = client.getCollectionStats(collectionName);
JSONObject collectionStats = JSONObject.parseObject(stats);
int rowCount = collectionStats.getIntValue("row_count");
assert(rowCount == nb - 1);
}
// case-02
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetEntityIdsAterDeleteEntitiesIndexed(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName)
.withFields(Constants.defaultEntities)
.build();
InsertResponse resInsert = client.insert(insertParam);
public void testGetEntityIdsAfterDeleteEntitiesIndexed(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genInsertParam(collectionName);
List<Long> idsBefore = client.insert(insertParam);
client.flush(collectionName);
Index index = new Index.Builder(collectionName, "float_vector")
.withParamsInJson(Constants.indexParam).build();
Response createIndexResponse = client.createIndex(index);
assert(createIndexResponse.ok());
List<Long> idsBefore = resInsert.getEntityIds();
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
client.deleteEntityByID(collectionName, Collections.singletonList(idsBefore.get(0)));
client.flush(collectionName);
Response res = client.getCollectionStats(collectionName);
System.out.println(res.getMessage());
JSONObject collectionInfo = Utils.getCollectionInfo(res.getMessage());
int rowCount = collectionInfo.getIntValue("row_count");
String stats = client.getCollectionStats(collectionName);
JSONObject collectionStats = JSONObject.parseObject(stats);
int rowCount = collectionStats.getIntValue("row_count");
assert(rowCount == nb - 1);
}
// case-03
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testGetEntityIdsAfterDeleteEntitiesBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName)
.withFields(Constants.defaultBinaryEntities)
.build();
InsertResponse resInsert = client.insert(insertParam);
InsertParam insertParam = Utils.genBinaryInsertParam(collectionName);
List<Long> idsBefore = client.insert(insertParam);
client.flush(collectionName);
List<Long> idsBefore = resInsert.getEntityIds();
client.deleteEntityByID(collectionName, Collections.singletonList(idsBefore.get(0)));
client.flush(collectionName);
Response res = client.getCollectionStats(collectionName);
System.out.println(res.getMessage());
JSONObject collectionInfo = Utils.getCollectionInfo(res.getMessage());
int rowCount = collectionInfo.getIntValue("row_count");
String stats = client.getCollectionStats(collectionName);
System.out.println(stats);
JSONObject collectionStats = JSONObject.parseObject(stats);
int rowCount = collectionStats.getIntValue("row_count");
assert(rowCount == nb - 1);
}
......
package com;
import io.milvus.client.*;
import org.testng.Assert;
import org.testng.annotations.*;
import java.util.List;
public class TestCollection_v2 {
int segmentRowCount = 5000;
int dimension = 128;
@BeforeClass
public MilvusClient setUp() throws ConnectFailedException {
MilvusClient client = new MilvusGrpcClient();
ConnectParam connectParam = new ConnectParam.Builder()
.withHost("127.0.0.1")
.withPort(19530)
.build();
client.connect(connectParam);
return client;
}
@AfterClass
public void tearDown() throws ConnectFailedException {
MilvusClient client = setUp();
List<String> collectionNames = client.listCollections().getCollectionNames();
// collectionNames.forEach(collection -> {client.dropCollection(collection);});
for(String collection: collectionNames){
System.out.print(collection+" ");
client.dropCollection(collection);
}
System.out.println("After Test");
}
// case-01
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testCreateCollection(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema =
Utils.genDefaultCollectionMapping(collectionName, dimension, segmentRowCount, false);
Response res = client.createCollection(collectionSchema);
assert(res.ok());
Assert.assertEquals(res.ok(), true);
}
// case-02
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
public void testCreateCollectionDisconnect(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema =
Utils.genDefaultCollectionMapping(collectionName, dimension, segmentRowCount, false);
Response res = client.createCollection(collectionSchema);
assert(!res.ok());
}
// case-03
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testCreateCollectionRepeatably(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema =
Utils.genDefaultCollectionMapping(collectionName, dimension, segmentRowCount, false);
Response res = client.createCollection(collectionSchema);
Assert.assertEquals(res.ok(), true);
Response resNew = client.createCollection(collectionSchema);
Assert.assertEquals(resNew.ok(), false);
}
// case-04
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testCreateCollectionWrongParams(MilvusClient client, String collectionName) {
CollectionMapping collectionSchema =
Utils.genDefaultCollectionMapping(collectionName, 0, segmentRowCount, false);
Response res = client.createCollection(collectionSchema);
System.out.println(res.toString());
Assert.assertEquals(res.ok(), false);
}
// case-05
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testShowCollections(MilvusClient client, String collectionName) {
Integer collectionNum = 10;
ListCollectionsResponse res = null;
for (int i = 0; i < collectionNum; ++i) {
String collectionNameNew = collectionName+"_"+Integer.toString(i);
CollectionMapping collectionSchema =
Utils.genDefaultCollectionMapping(collectionNameNew, dimension, segmentRowCount, false);
client.createCollection(collectionSchema);
List<String> collectionNames = client.listCollections().getCollectionNames();
Assert.assertTrue(collectionNames.contains(collectionNameNew));
}
}
}
......@@ -2,13 +2,10 @@ package com;
import com.alibaba.fastjson.JSONObject;
import io.milvus.client.*;
import io.milvus.client.exception.ServerSideMilvusException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.MoreExecutors;
public class TestCompact {
int nb = Constants.nb;
......@@ -16,166 +13,153 @@ public class TestCompact {
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCompactAfterDelete(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
List<Long> ids = Utils.initData(client, collectionName);
client.deleteEntityByID(collectionName, ids);
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.flush(collectionName);
CompactParam compactParam = new CompactParam.Builder(collectionName).build();
Response res_compact = client.compact(compactParam);
assert(res_compact.ok());
Response statsResponse = client.getCollectionStats(collectionName);
assert(statsResponse.ok());
JSONObject jsonObject = JSONObject.parseObject(statsResponse.getMessage());
client.compact(CompactParam.create(collectionName));
String statsResponse = client.getCollectionStats(collectionName);
JSONObject jsonObject = JSONObject.parseObject(statsResponse);
Assert.assertEquals(jsonObject.getIntValue("data_size"), 0);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
Assert.assertEquals(client.countEntities(collectionName), 0);
}
// case-02
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testCompactAfterDeleteBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
List<Long> ids = Utils.initBinaryData(client, collectionName);
client.deleteEntityByID(collectionName, ids);
client.flush(collectionName);
CompactParam compactParam = new CompactParam.Builder(collectionName).build();
Response res_compact = client.compact(compactParam);
assert(res_compact.ok());
Response statsResponse = client.getCollectionStats(collectionName);
assert(statsResponse.ok());
JSONObject jsonObject = JSONObject.parseObject(statsResponse.getMessage());
client.compact(CompactParam.create(collectionName));
String stats = client.getCollectionStats(collectionName);
JSONObject jsonObject = JSONObject.parseObject(stats);
Assert.assertEquals(jsonObject.getIntValue("data_size"), 0);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
Assert.assertEquals(client.countEntities(collectionName), 0);
}
// case-03
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCompactNoCollection(MilvusClient client, String collectionName) {
String name = "";
CompactParam compactParam = new CompactParam.Builder(name).build();
Response res_compact = client.compact(compactParam);
assert(!res_compact.ok());
client.compact(CompactParam.create(name));
}
// case-04
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCompactEmptyCollection(MilvusClient client, String collectionName) {
CompactParam compactParam = new CompactParam.Builder(collectionName).build();
Response res_compact = client.compact(compactParam);
assert(res_compact.ok());
String stats = client.getCollectionStats(collectionName);
JSONObject jsonObject = JSONObject.parseObject(stats);
client.compact(CompactParam.create(collectionName));
int data_size = jsonObject.getIntValue("data_size");
Assert.assertEquals(0, data_size);
}
// case-05
// TODO delete not correct
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCompactThresholdLessThanDeleted(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
client.flush(collectionName);
Response deleteRes = client.deleteEntityByID(collectionName, res.getEntityIds().subList(0, nb/4));
assert(deleteRes.ok());
client.flush(collectionName);
Response resBefore = client.getCollectionStats(collectionName);
JSONObject segmentsBefore = (JSONObject)Utils.parseJsonArray(resBefore.getMessage(), "segments").get(0);
CompactParam compactParam = new CompactParam.Builder(collectionName).withThreshold(0.3).build();
Response resCompact = client.compact(compactParam);
assert(resCompact.ok());
Response resAfter = client.getCollectionStats(collectionName);
JSONObject segmentsAfter = (JSONObject)Utils.parseJsonArray(resAfter.getMessage(), "segments").get(0);
Assert.assertEquals(segmentsBefore.get("data_size"), segmentsAfter.get("data_size"));
int segmentRowLimit = nb+1000;
String collectionNameNew = collectionName+"_";
CollectionMapping cm = CollectionMapping.create(collectionNameNew)
.addField(Constants.intFieldName, DataType.INT64)
.addField(Constants.floatFieldName, DataType.FLOAT)
.addVectorField(Constants.floatVectorFieldName, DataType.VECTOR_FLOAT, Constants.dimension)
.setParamsInJson(new JsonBuilder()
.param("segment_row_limit", segmentRowLimit)
.param("auto_id", true)
.build());
client.createCollection(cm);
List<Long> ids = Utils.initData(client, collectionNameNew);
client.deleteEntityByID(collectionNameNew, ids.subList(0, nb / 4));
client.flush(collectionNameNew);
Assert.assertEquals(client.countEntities(collectionNameNew), nb - (nb / 4));
// before compact
String stats = client.getCollectionStats(collectionNameNew);
JSONObject segmentsBefore = (JSONObject)Utils.parseJsonArray(stats, "segments").get(0);
client.compact(CompactParam.create(collectionNameNew).setThreshold(0.9));
// after compact
String statsAfter = client.getCollectionStats(collectionNameNew);
JSONObject segmentsAfter = (JSONObject)Utils.parseJsonArray(statsAfter, "segments").get(0);
Assert.assertEquals(segmentsAfter.get("data_size"), segmentsBefore.get("data_size"));
}
// case-06
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCompactInvalidThreshold(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = Utils.initData(client, collectionName);
client.deleteEntityByID(collectionName, ids);
client.flush(collectionName);
Response deleteRes = client.deleteEntityByID(collectionName, res.getEntityIds());
assert(deleteRes.ok());
client.flush(collectionName);
CompactParam compactParam = new CompactParam.Builder(collectionName).withThreshold(-1.0).build();
Response resCompact = client.compact(compactParam);
Assert.assertFalse(resCompact.ok());
client.compact(CompactParam.create(collectionName).setThreshold(-1.0));
}
// case-07, test CompactAsync callback
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCompactAsyncAfterDelete(MilvusClient client, String collectionName) {
// define callback
FutureCallback<Response> futureCallback = new FutureCallback<Response>() {
@Override
public void onSuccess(Response compactResponse) {
assert(compactResponse != null);
assert(compactResponse.ok());
Response statsResponse = client.getCollectionStats(collectionName);
assert(statsResponse.ok());
JSONObject jsonObject = JSONObject.parseObject(statsResponse.getMessage());
Assert.assertEquals(jsonObject.getIntValue("data_size"), 0);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
}
@Override
public void onFailure(Throwable t) {
System.out.println(t.getMessage());
Assert.assertTrue(false);
}
};
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.flush(collectionName);
CompactParam compactParam = new CompactParam.Builder(collectionName).build();
// call compactAsync
ListenableFuture<Response> compactResponseFuture = client.compactAsync(compactParam);
Futures.addCallback(compactResponseFuture, futureCallback, MoreExecutors.directExecutor());
// execute before callback
Response statsResponse = client.getCollectionStats(collectionName);
assert(statsResponse.ok());
JSONObject jsonObject = JSONObject.parseObject(statsResponse.getMessage());
Assert.assertTrue(jsonObject.getIntValue("data_size") > 0);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
}
// case-08, test CompactAsync callback with invalid collection name
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCompactAsyncNoCollection(MilvusClient client, String collectionName) {
// define callback
FutureCallback<Response> futureCallback = new FutureCallback<Response>() {
@Override
public void onSuccess(Response compactResponse) {
assert(compactResponse != null);
assert(!compactResponse.ok());
}
@Override
public void onFailure(Throwable t) {
System.out.println(t.getMessage());
Assert.assertTrue(false);
}
};
String name = "";
CompactParam compactParam = new CompactParam.Builder(name).build();
// call compactAsync
ListenableFuture<Response> compactResponseFuture = client.compactAsync(compactParam);
Futures.addCallback(compactResponseFuture, futureCallback, MoreExecutors.directExecutor());
}
// // case-07, test CompactAsync callback
// @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
// public void testCompactAsyncAfterDelete(MilvusClient client, String collectionName) {
// // define callback
// FutureCallback<Response> futureCallback = new FutureCallback<Response>() {
// @Override
// public void onSuccess(Response compactResponse) {
// assert(compactResponse != null);
// assert(compactResponse.ok());
//
// Response statsResponse = client.getCollectionStats(collectionName);
// assert(statsResponse.ok());
// JSONObject jsonObject = JSONObject.parseObject(statsResponse.getMessage());
// Assert.assertEquals(jsonObject.getIntValue("data_size"), 0);
// Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
// }
//
// @Override
// public void onFailure(Throwable t) {
// System.out.println(t.getMessage());
// Assert.assertTrue(false);
// }
// };
//
// InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
// InsertResponse res = client.insert(insertParam);
// assert(res.getResponse().ok());
// List<Long> ids = res.getEntityIds();
// client.flush(collectionName);
// Response res_delete = client.deleteEntityByID(collectionName, ids);
// assert(res_delete.ok());
// client.flush(collectionName);
// CompactParam compactParam = new CompactParam.Builder(collectionName).build();
//
// // call compactAsync
// ListenableFuture<Response> compactResponseFuture = client.compactAsync(compactParam);
// Futures.addCallback(compactResponseFuture, futureCallback, MoreExecutors.directExecutor());
//
// // execute before callback
// Response statsResponse = client.getCollectionStats(collectionName);
// assert(statsResponse.ok());
// JSONObject jsonObject = JSONObject.parseObject(statsResponse.getMessage());
// Assert.assertTrue(jsonObject.getIntValue("data_size") > 0);
// Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
// }
//
// // case-08, test CompactAsync callback with invalid collection name
// @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
// public void testCompactAsyncNoCollection(MilvusClient client, String collectionName) {
// // define callback
// FutureCallback<Response> futureCallback = new FutureCallback<Response>() {
// @Override
// public void onSuccess(Response compactResponse) {
// assert(compactResponse != null);
// assert(!compactResponse.ok());
// }
//
// @Override
// public void onFailure(Throwable t) {
// System.out.println(t.getMessage());
// Assert.assertTrue(false);
// }
// };
//
// String name = "";
// CompactParam compactParam = new CompactParam.Builder(name).build();
//
// // call compactAsync
// ListenableFuture<Response> compactResponseFuture = client.compactAsync(compactParam);
// Futures.addCallback(compactResponseFuture, futureCallback, MoreExecutors.directExecutor());
// }
}
package com;
import io.milvus.client.exception.ClientSideMilvusException;
import io.milvus.client.*;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
public class TestConnect {
@Test(dataProvider = "DefaultConnectArgs", dataProviderClass = MainClass.class)
public void testConnect(String host, int port) throws ConnectFailedException {
public void testConnect(String host, int port) throws Exception {
System.out.println("Host: "+host+", Port: "+port);
MilvusClient client = new MilvusGrpcClient();
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(host)
.withPort(port)
.build();
Response res = client.connect(connectParam);
assert(res.ok());
// assert(client.isConnected());
MilvusClient client = new MilvusGrpcClient(connectParam).withLogging();
}
@Test(dataProvider = "DefaultConnectArgs", dataProviderClass = MainClass.class)
public void testConnectRepeat(String host, int port) {
MilvusGrpcClient client = new MilvusGrpcClient();
Response res = null;
try {
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(host)
.withPort(port)
.build();
res = client.connect(connectParam);
res = client.connect(connectParam);
} catch (ConnectFailedException e) {
e.printStackTrace();
}
assert (res.ok());
// assert(client.isConnected());
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(host)
.withPort(port)
.build();
MilvusClient client = new MilvusGrpcClient(connectParam).withLogging();
MilvusClient client1 = new MilvusGrpcClient(connectParam).withLogging();
}
@Test(dataProvider="InvalidConnectArgs")
// TODO timeout
@Test(dataProvider="InvalidConnectArgs", expectedExceptions = {ClientSideMilvusException.class, IllegalArgumentException.class})
public void testConnectInvalidConnectArgs(String ip, int port) {
MilvusClient client = new MilvusGrpcClient();
Response res = null;
try {
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(ip)
.withPort(port)
.build();
res = client.connect(connectParam);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertEquals(res, null);
// assert(!client.isConnected());
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(ip)
.withPort(port)
.withKeepAliveTimeout(1, TimeUnit.MILLISECONDS)
.build();
MilvusClient client = new MilvusGrpcClient(connectParam).withLogging();
}
@DataProvider(name="InvalidConnectArgs")
......@@ -62,27 +46,21 @@ public class TestConnect {
{"1.1.1.1", port},
{"255.255.0.0", port},
{"1.2.2", port},
// {"中文", port},
// {"www.baidu.com", 100000},
{"中文", port},
{"www.baidu.com", 100000},
{"127.0.0.1", 100000},
{"www.baidu.com", 80},
};
}
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testDisconnect(MilvusClient client, String collectionName){
// assert(!client.isConnected());
client.close();
}
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
public void testDisconnectRepeatably(MilvusClient client, String collectionName){
Response res = null;
try {
res = client.disconnect();
} catch (InterruptedException e) {
e.printStackTrace();
}
assert(!res.ok());
// assert(!client.isConnected());
}
// // TODO
// @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
// public void testDisconnectRepeatably(MilvusClient client, String collectionName){
// client.close();
// }
}
package com;
import io.milvus.client.*;
import io.milvus.client.exception.ServerSideMilvusException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
......@@ -15,93 +17,64 @@ public class TestDeleteEntities {
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteEntities(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
InsertParam insertParam = Utils.genInsertParam(collectionName);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.deleteEntityByID(collectionName, ids);
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
Assert.assertEquals(client.countEntities(collectionName), 0);
}
// case-02
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteSingleEntity(MilvusClient client, String collectionName) {
List<List<Float>> del_vector = new ArrayList<>();
del_vector.add(Constants.vectors.get(0));
List<Long> del_ids = new ArrayList<>();
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
del_ids.add(ids.get(0));
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
assert(res_delete.ok());
List<Long> ids = Utils.initData(client, collectionName);
client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), Constants.nb - 1);
Assert.assertEquals(client.countEntities(collectionName), Constants.nb - 1);
// Assert getEntityByID
GetEntityByIDResponse res_get = client.getEntityByID(collectionName, del_ids);
assert(res_get.getResponse().ok());
Assert.assertEquals(res_get.getFieldsMap().size(), 1);
Map<Long, Map<String, Object>> resEntity = client.getEntityByID(collectionName, Collections.singletonList(ids.get(0)));
Assert.assertEquals(resEntity.size(), 0);
}
// case-03
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDeleteEntitiesCollectionNotExisted(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
client.flush(collectionName);
List<Long> ids = res.getEntityIds();
String collectionNameNew = Utils.genUniqueStr(collectionName);
Response res_delete = client.deleteEntityByID(collectionNameNew, ids);
assert(!res_delete.ok());
client.deleteEntityByID(collectionNameNew, new ArrayList<Long>());
}
// case-04
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDeleteEntitiesEmptyCollection(MilvusClient client, String collectionName) {
String collectionNameNew = Utils.genUniqueStr(collectionName);
List<Long> entityIds = LongStream.range(0, Constants.nb).boxed().collect(Collectors.toList());
Response res_delete = client.deleteEntityByID(collectionNameNew, entityIds);
assert(!res_delete.ok());
client.deleteEntityByID(collectionNameNew, entityIds);
}
// case-05
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteEntityIdNotExisted(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = new ArrayList<Long>();
ids.add((long)123456);
ids.add((long)1234561);
List<Long> ids = Utils.initData(client, collectionName);
List<Long> delIds = new ArrayList<Long>();
delIds.add(123456L);
delIds.add(1234561L);
client.deleteEntityByID(collectionName, delIds);
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), Constants.nb);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName), Constants.nb);
}
// case-06
// Below tests binary vectors
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testDeleteEntitiesBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
List<Long> ids = Utils.initBinaryData(client, collectionName);
client.deleteEntityByID(collectionName, ids);
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
Assert.assertEquals(client.countEntities(collectionName), 0);
}
}
package com;
import io.milvus.client.*;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TestDeleteEntities_v2 {
int dimension = Constants.dimension;
int nb = Constants.nb;
List<List<Float>> vectors = Constants.vectors;
List<List<Byte>> vectorsBinary = Constants.vectorsBinary;
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteEntities(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
}
// case-02
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteSingleEntity(MilvusClient client, String collectionName) {
List<List<Float>> del_vector = new ArrayList<>();
del_vector.add(Constants.vectors.get(0));
List<Long> del_ids = new ArrayList<>();
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
del_ids.add(ids.get(0));
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
assert(res_delete.ok());
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), Constants.nb - 1);
// Assert getEntityByID
GetEntityByIDResponse res_get = client.getEntityByID(collectionName, del_ids);
assert(res_get.getResponse().ok());
Assert.assertEquals(res_get.getFieldsMap().size(), 1);
}
// case-03
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteEntitiesCollectionNotExisted(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
client.flush(collectionName);
List<Long> ids = res.getEntityIds();
String collectionNameNew = Utils.genUniqueStr(collectionName);
Response res_delete = client.deleteEntityByID(collectionNameNew, ids);
assert(!res_delete.ok());
}
// case-05
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDeleteEntityIdNotExisted(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = new ArrayList<Long>();
ids.add((long)123456);
ids.add((long)1234561);
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), Constants.nb);
}
// case-06
// Below tests binary vectors
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testDeleteEntitiesBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
List<Long> ids = res.getEntityIds();
client.flush(collectionName);
Response res_delete = client.deleteEntityByID(collectionName, ids);
assert(res_delete.ok());
client.flush(collectionName);
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
}
}
package com;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
import io.milvus.client.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.testng.Assert;
......@@ -11,20 +9,21 @@ import java.util.ArrayList;
import java.util.List;
public class TestFlush {
int segmentRowCount = 50;
int nb = Constants.nb;
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testFlushCollectionNotExisted(MilvusClient client, String collectionName) {
String newCollection = "not_existed";
Response res = client.flush(newCollection);
assert(!res.ok());
try {
client.flush(newCollection);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testFlushEmptyCollection(MilvusClient client, String collectionName) {
Response res = client.flush(collectionName);
assert(res.ok());
client.flush(collectionName);
}
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
......@@ -33,64 +32,66 @@ public class TestFlush {
int collectionNum = 10;
for (int i = 0; i < collectionNum; i++) {
names.add(RandomStringUtils.randomAlphabetic(10));
CollectionMapping collectionSchema = new CollectionMapping.Builder(names.get(i))
.withFields(Constants.defaultFields)
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
client.createCollection(collectionSchema);
InsertParam insertParam = new InsertParam.Builder(names.get(i)).withFields(Constants.defaultEntities).build();
CollectionMapping cm = CollectionMapping
.create(names.get(i))
.addField("int64", DataType.INT64)
.addField("float", DataType.FLOAT)
.addVectorField("float_vector", DataType.VECTOR_FLOAT, Constants.dimension)
.setParamsInJson(new JsonBuilder()
.param("segment_row_limit", Constants.segmentRowLimit)
.param("auto_id", true)
.build());
client.createCollection(cm);
InsertParam insertParam = Utils.genInsertParam(names.get(i));
client.insert(insertParam);
System.out.println("Table " + names.get(i) + " created.");
}
Response res = client.flush(names);
assert(res.ok());
client.flush(names);
for (int i = 0; i < collectionNum; i++) {
// check row count
Assert.assertEquals(client.countEntities(names.get(i)).getCollectionEntityCount(), nb);
}
}
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
public void testAddCollectionsFlushAsync(MilvusClient client, String collectionName) throws ExecutionException, InterruptedException {
List<String> names = new ArrayList<>();
for (int i = 0; i < 100; i++) {
names.add(RandomStringUtils.randomAlphabetic(10));
CollectionMapping collectionSchema = new CollectionMapping.Builder(names.get(i))
.withFields(Constants.defaultFields)
.withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
.build();
client.createCollection(collectionSchema);
InsertParam insertParam = new InsertParam.Builder(names.get(i)).withFields(Constants.defaultEntities).build();
client.insert(insertParam);
System.out.println("Collection " + names.get(i) + " created.");
}
ListenableFuture<Response> flushResponseFuture = client.flushAsync(names);
flushResponseFuture.get();
for (int i = 0; i < 100; i++) {
// check row count
Assert.assertEquals(client.countEntities(names.get(i)).getCollectionEntityCount(), nb);
Assert.assertEquals(client.countEntities(names.get(i)), nb);
}
}
// @Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
// public void testAddCollectionsFlushAsync(MilvusClient client, String collectionName) throws ExecutionException, InterruptedException {
// List<String> names = new ArrayList<>();
// for (int i = 0; i < 100; i++) {
// names.add(RandomStringUtils.randomAlphabetic(10));
// CollectionMapping collectionSchema = new CollectionMapping.Builder(names.get(i))
// .withFields(Constants.defaultFields)
// .withParamsInJson(String.format("{\"segment_row_count\": %s}",segmentRowCount))
// .build();
// client.createCollection(collectionSchema);
// InsertParam insertParam = new InsertParam.Builder(names.get(i)).withFields(Constants.defaultEntities).build();
// client.insert(insertParam);
// System.out.println("Collection " + names.get(i) + " created.");
// }
// ListenableFuture<Response> flushResponseFuture = client.flushAsync(names);
// flushResponseFuture.get();
// for (int i = 0; i < 100; i++) {
// // check row count
// Assert.assertEquals(client.countEntities(names.get(i)).getCollectionEntityCount(), nb);
// }
// }
//
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testAddFlushMultipleTimes(MilvusClient client, String collectionName) {
for (int i = 0; i < 10; i++) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
client.insert(insertParam);
Response res = client.flush(collectionName);
assert(res.ok());
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb * (i+1));
InsertParam insertParam = Utils.genInsertParam(collectionName);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
Assert.assertEquals(client.countEntities(collectionName), nb * (i+1));
}
}
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testAddFlushMultipleTimesBinary(MilvusClient client, String collectionName) {
for (int i = 0; i < 10; i++) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
client.insert(insertParam);
Response res = client.flush(collectionName);
assert(res.ok());
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb * (i+1));
InsertParam insertParam = Utils.genBinaryInsertParam(collectionName);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
Assert.assertEquals(client.countEntities(collectionName), nb * (i+1));
}
}
}
\ No newline at end of file
package com;
import io.milvus.client.*;
import io.milvus.client.exception.ServerSideMilvusException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.nio.ByteBuffer;
import java.util.*;
public class TestGetEntityByID {
public List<Long> get_ids = Utils.toListIds(1111);
......@@ -15,88 +14,77 @@ public class TestGetEntityByID {
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetEntitiesByIdValid(MilvusClient client, String collectionName) {
int get_length = 100;
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse resInsert = client.insert(insertParam);
List<Long> ids = resInsert.getEntityIds();
InsertParam insertParam = Utils.genInsertParam(collectionName);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
GetEntityByIDResponse res = client.getEntityByID(collectionName, ids.subList(0, get_length));
assert (res.getResponse().ok());
// assert (res.getValidIds(), ids.subList(0, get_length));
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(collectionName, ids.subList(0, get_length));
for (int i = 0; i < get_length; i++) {
List<Map<String,Object>> fieldsMap = res.getFieldsMap();
assert (fieldsMap.get(i).get("float_vector").equals(Constants.vectors.get(i)));
Map<String,Object> fieldsMap = resEntities.get(ids.get(i));
assert (fieldsMap.get("float_vector").equals(Constants.vectors.get(i)));
}
}
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetEntityByIdAfterDelete(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
InsertResponse resInsert = client.insert(insertParam);
List<Long> ids = resInsert.getEntityIds();
Response res_delete = client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(1)));
assert(res_delete.ok());
List<Long> ids = Utils.initData(client, collectionName);
client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(1)));
client.flush(collectionName);
List<Long> getIds = ids.subList(0,2);
GetEntityByIDResponse res = client.getEntityByID(collectionName, getIds);
assert (res.getResponse().ok());
List<Map<String, Object>> fieldsMap = res.getFieldsMap();
Assert.assertEquals(fieldsMap.size(), getIds.size());
Assert.assertEquals(fieldsMap.get(0).get("float_vector"), Constants.vectors.get(0));
Assert.assertEquals(res.getFieldsMap().get(1).size(), 0);
Assert.assertEquals(res.getFieldsMap().get(1), new HashMap<>());
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(collectionName, getIds);
Assert.assertEquals(resEntities.size(), getIds.size()-1);
Assert.assertEquals(resEntities.get(getIds.get(0)).get(Constants.floatVectorFieldName), Constants.vectors.get(0));
}
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testGetEntityByIdCollectionNameNotExisted(MilvusClient client, String collectionName) {
String newCollection = "not_existed";
GetEntityByIDResponse res = client.getEntityByID(newCollection, get_ids);
assert(!res.getResponse().ok());
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(newCollection, get_ids);
}
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testGetVectorIdNotExisted(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
client.insert(insertParam);
client.flush(collectionName);
GetEntityByIDResponse res = client.getEntityByID(collectionName, get_ids);
Assert.assertEquals(res.getFieldsMap().size(), get_ids.size());
Assert.assertEquals(res.getFieldsMap().get(0), new HashMap<>());
List<Long> ids = Utils.initData(client, collectionName);
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(collectionName, get_ids);
Assert.assertEquals(resEntities.size(), 0);
}
// Binary tests
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testGetEntityByIdValidBinary(MilvusClient client, String collectionName) {
int get_length = 20;
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
InsertResponse resInsert = client.insert(insertParam);
List<Long> ids = resInsert.getEntityIds();
List<Long> intValues = new ArrayList<>(Constants.nb);
List<Float> floatValues = new ArrayList<>(Constants.nb);
List<ByteBuffer> vectors = Utils.genBinaryVectors(Constants.nb, Constants.dimension);
for (int i = 0; i < Constants.nb; ++i) {
intValues.add((long) i);
floatValues.add((float) i);
}
InsertParam insertParam = InsertParam
.create(collectionName)
.addField(Constants.intFieldName, DataType.INT64, intValues)
.addField(Constants.floatFieldName, DataType.FLOAT, floatValues)
.addVectorField(Constants.binaryVectorFieldName, DataType.VECTOR_BINARY, vectors);
List<Long> ids = client.insert(insertParam);
client.flush(collectionName);
GetEntityByIDResponse res = client.getEntityByID(collectionName, ids.subList(0, get_length));
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(collectionName, ids.subList(0, get_length));
for (int i = 0; i < get_length; i++) {
List<Map<String,Object>> fieldsMap = res.getFieldsMap();
assert (fieldsMap.get(i).get("binary_vector").equals(Constants.vectorsBinary.get(i)));
assert (resEntities.get(ids.get(i)).get(Constants.binaryVectorFieldName).equals(vectors.get(i)));
}
}
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testGetEntityByIdAfterDeleteBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
InsertResponse resInsert = client.insert(insertParam);
List<Long> ids = resInsert.getEntityIds();
Response res_delete = client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
assert(res_delete.ok());
List<Long> ids = Utils.initBinaryData(client, collectionName);
client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
client.flush(collectionName);
GetEntityByIDResponse res = client.getEntityByID(collectionName, ids.subList(0, 1));
Assert.assertEquals(res.getFieldsMap().size(), 1);
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(collectionName, ids.subList(0, 1));
Assert.assertEquals(resEntities.size(), 0);
}
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testGetEntityIdNotExistedBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
client.insert(insertParam);
client.flush(collectionName);
GetEntityByIDResponse res = client.getEntityByID(collectionName, get_ids);
Assert.assertEquals(res.getFieldsMap().size(), get_ids.size());
Assert.assertEquals(res.getFieldsMap().get(0), new HashMap<>());
List<Long> ids = Utils.initBinaryData(client, collectionName);
Map<Long, Map<String, Object>> resEntities = client.getEntityByID(collectionName, get_ids);
Assert.assertEquals(resEntities.size(), 0);
}
}
\ No newline at end of file
......@@ -2,186 +2,197 @@ package com;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import io.milvus.client.*;
import io.milvus.client.exception.ClientSideMilvusException;
import io.milvus.client.exception.ServerSideMilvusException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
public class TestIndex {
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndex(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
client.insert(insertParam);
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), Constants.indexType));
}
List<Long> ids = Utils.initData(client, collectionName);
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
String stats = client.getCollectionStats(collectionName);
JSONArray filesJsonArray = Utils.parseJsonArray(stats, "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), Constants.indexType.toString()));
}
// case-02
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testCreateIndexBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
client.insert(insertParam);
Index index = new Index.Builder(collectionName, Constants.binaryFieldName).withParamsInJson(Constants.binaryIndexParam).build();
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), Constants.defaultBinaryIndexType));
}
List<Long> ids = Utils.initBinaryData(client, collectionName);
Index index = Index
.create(collectionName, Constants.binaryVectorFieldName)
.setIndexType(Constants.defaultBinaryIndexType)
.setMetricType(MetricType.JACCARD)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
String stats = client.getCollectionStats(collectionName);
JSONArray filesJsonArray = Utils.parseJsonArray(stats, "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), Constants.defaultBinaryIndexType.toString()));
}
// case-03
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndexRepeatably(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
client.insert(insertParam);
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response res_create_2 = client.createIndex(index);
assert(res_create_2.ok());
List<Long> ids = Utils.initData(client, collectionName);
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
client.createIndex(index);
}
// case-04
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndexWithNoVector(MilvusClient client, String collectionName) {
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
Response res_create = client.createIndex(index);
assert(res_create.ok());
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
}
// case-05
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCreateIndexTableNotExisted(MilvusClient client, String collectionName) {
String collectionNameNew = Utils.genUniqueStr(collectionName);
Index index = new Index.Builder(collectionNameNew, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
Response res_create = client.createIndex(index);
assert(!res_create.ok());
Index index = Index
.create(collectionNameNew, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
}
// case-06
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testCreateIndexWithoutConnect(MilvusClient client, String collectionName) {
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
Response res_create = client.createIndex(index);
assert(!res_create.ok());
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
}
// case-07
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCreateIndexInvalidNList(MilvusClient client, String collectionName) {
int n_list = 0;
String indexParamNew = Utils.setIndexParam(Constants.indexType, "L2", n_list);
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(indexParamNew).build();
Response res_create = client.createIndex(index);
assert(!res_create.ok());
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(IndexType.IVF_SQ8)
.setMetricType(MetricType.L2)
.setParamsInJson(new JsonBuilder().param("nlist", n_list).build());
client.createIndex(index);
}
// #3407
// case-08
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCreateIndexInvalidMetricTypeBinary(MilvusClient client, String collectionName) {
String metric_type = "L2";
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
client.insert(insertParam);
String indexParamNew = Utils.setIndexParam("BIN_IVF_FLAT", metric_type, Constants.n_list);
Index createIndexParam = new Index.Builder(collectionName, Constants.binaryFieldName).withParamsInJson(indexParamNew).build();
Response res_create = client.createIndex(createIndexParam);
assert (!res_create.ok());
MetricType metric_type = MetricType.L2;
List<Long> ids = Utils.initBinaryData(client, collectionName);
Index index = Index
.create(collectionName, Constants.binaryVectorFieldName)
.setIndexType(IndexType.BIN_IVF_FLAT)
.setMetricType(metric_type)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
}
// #3408
// case-09
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDropIndex(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultEntities).build();
client.insert(insertParam);
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response res_drop = client.dropIndex(collectionName, Constants.floatFieldName);
assert(res_drop.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item -> (JSONObject) item).forEach(file->{
Assert.assertFalse(file.containsKey("index_type"));
});
List<Long> ids = Utils.initData(client, collectionName);
Index index = Index
.create(collectionName, Constants.floatVectorFieldName)
.setIndexType(Constants.indexType)
.setMetricType(Constants.defaultMetricType)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
client.dropIndex(collectionName, Constants.floatVectorFieldName);
String stats = client.getCollectionStats(collectionName);
JSONArray filesJsonArray = Utils.parseJsonArray(stats, "files");
for (Object item : filesJsonArray) {
JSONObject file = (JSONObject) item;
Assert.assertFalse(file.containsKey("index_type"));
}
}
// case-10
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testDropIndexBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(Constants.defaultBinaryEntities).build();
client.insert(insertParam);
Index index = new Index.Builder(collectionName, Constants.binaryFieldName).withParamsInJson(Constants.binaryIndexParam).build();
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response res_drop = client.dropIndex(collectionName, Constants.binaryFieldName);
assert(res_drop.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item -> (JSONObject) item).forEach(file->{
Assert.assertFalse(file.containsKey("index_type"));
});
List<Long> ids = Utils.initBinaryData(client, collectionName);
Index index = Index
.create(collectionName, Constants.binaryVectorFieldName)
.setIndexType(Constants.defaultBinaryIndexType)
.setMetricType(Constants.defaultBinaryMetricType)
.setParamsInJson(new JsonBuilder().param("nlist", Constants.n_list).build());
client.createIndex(index);
client.dropIndex(collectionName, Constants.binaryVectorFieldName);
String stats = client.getCollectionStats(collectionName);
JSONArray filesJsonArray = Utils.parseJsonArray(stats, "files");
for (Object item : filesJsonArray) {
JSONObject file = (JSONObject) item;
Assert.assertFalse(file.containsKey("index_type"));
}
}
// case-11
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDropIndexCollectionNotExisted(MilvusClient client, String collectionName) {
String collectionNameNew = Utils.genUniqueStr(collectionName);
Response res_drop = client.dropIndex(collectionNameNew, Constants.floatFieldName);
assert(!res_drop.ok());
client.dropIndex(collectionNameNew, Constants.floatVectorFieldName);
}
// case-12
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class, expectedExceptions = ClientSideMilvusException.class)
public void testDropIndexWithoutConnect(MilvusClient client, String collectionName) {
Response res_drop = client.dropIndex(collectionName, Constants.floatFieldName);
assert(!res_drop.ok());
}
// case-13
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testAsyncIndex(MilvusClient client, String collectionName) {
Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
ListenableFuture<Response> createIndexResFuture = client.createIndexAsync(index);
Futures.addCallback(
createIndexResFuture, new FutureCallback<Response>() {
@Override
public void onSuccess(Response createIndexResponse) {
Assert.assertNotNull(createIndexResponse);
Assert.assertTrue(createIndexResponse.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), Constants.indexType));
}
}
@Override
public void onFailure(Throwable t) {
System.out.println(t.getMessage());
}
}, MoreExecutors.directExecutor()
);
client.dropIndex(collectionName, Constants.floatVectorFieldName);
}
//
// // case-13
// @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
// public void testAsyncIndex(MilvusClient client, String collectionName) {
// Index index = new Index.Builder(collectionName, Constants.floatFieldName).withParamsInJson(Constants.indexParam).build();
// ListenableFuture<Response> createIndexResFuture = client.createIndexAsync(index);
// Futures.addCallback(
// createIndexResFuture, new FutureCallback<Response>() {
// @Override
// public void onSuccess(Response createIndexResponse) {
// Assert.assertNotNull(createIndexResponse);
// Assert.assertTrue(createIndexResponse.ok());
// Response statsResponse = client.getCollectionStats(collectionName);
// if(statsResponse.ok()) {
// JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
// filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
// Assert.assertEquals(file.get("index_type"), Constants.indexType));
// }
// }
// @Override
// public void onFailure(Throwable t) {
// System.out.println(t.getMessage());
// }
// }, MoreExecutors.directExecutor()
// );
// }
}
package com;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.milvus.client.*;
import org.testng.Assert;
import org.testng.annotations.*;
import java.util.List;
public class TestIndex_v2 {
int dimension = Constants.dimension;
int nb = Constants.nb;
int n_list = Constants.n_list;
String floatFieldName = Constants.floatFieldName;
String binaryFieldName = Constants.binaryFieldName;
String indexType = Constants.indexType;
String defaultBinaryIndexType = Constants.defaultBinaryIndexType;
String defaultMetricType = Constants.defaultMetricType;
List<List<Float>> vectors = Constants.vectors;
List<List<Byte>> vectorsBinary = Constants.vectorsBinary;
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndex(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
client.insert(insertParam);
Index index = Utils.genDefaultIndex(collectionName, floatFieldName, indexType, defaultMetricType, n_list);
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
System.out.println(statsResponse.getMessage());
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), indexType));
}
}
// case-02
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testCreateIndexBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
client.insert(insertParam);
Index index = Utils.genDefaultIndex(collectionName, binaryFieldName, defaultBinaryIndexType,
Constants.defaultBinaryMetricType, n_list);
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item-> (JSONObject)item).filter(item->item.containsKey("index_type")).forEach(file->
Assert.assertEquals(file.get("index_type"), defaultBinaryIndexType));
}
}
// case-04
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndexWithNoVector(MilvusClient client, String collectionName) {
Index index = Utils.genDefaultIndex(collectionName, floatFieldName, indexType,
defaultMetricType, n_list);
Response res_create = client.createIndex(index);
assert(res_create.ok());
}
// case-05
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndexTableNotExisted(MilvusClient client, String collectionName) {
String collectionNameNew = Utils.genUniqueStr(collectionName);
Index index = Utils.genDefaultIndex(collectionNameNew, floatFieldName, indexType,
defaultMetricType, n_list);
Response res_create = client.createIndex(index);
assert(!res_create.ok());
}
// case-06
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
public void testCreateIndexWithoutConnect(MilvusClient client, String collectionName) {
Index index = Utils.genDefaultIndex(collectionName, floatFieldName, indexType,
defaultMetricType, n_list);
Response res_create = client.createIndex(index);
assert(!res_create.ok());
}
// case-07
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreateIndexInvalidNList(MilvusClient client, String collectionName) {
int n_list = 0;
Index index = Utils.genDefaultIndex(collectionName, floatFieldName, indexType, defaultMetricType, n_list);
Response res_create = client.createIndex(index);
assert(!res_create.ok());
}
// #3407
// case-08
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testCreateIndexInvalidMetricTypeBinary(MilvusClient client, String collectionName) {
String metric_type = "L2";
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
client.insert(insertParam);
Index createIndexParam = Utils.genDefaultIndex(collectionName, binaryFieldName, "BIN_IVF_FLAT", metric_type, n_list);
Response res_create = client.createIndex(createIndexParam);
Response statsResponse = client.getCollectionStats(collectionName);
System.out.println(statsResponse.getMessage());
Assert.assertFalse(res_create.ok());
}
// #3408
// case-09
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDropIndex(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
client.insert(insertParam);
Index index = Utils.genDefaultIndex(collectionName, floatFieldName, indexType, defaultMetricType, n_list);
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response res_drop = client.dropIndex(collectionName, floatFieldName);
assert(res_drop.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item -> (JSONObject) item).forEach(file->{
Assert.assertFalse(file.containsKey("index_type"));
});
}
}
// case-10
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testDropIndexBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
client.insert(insertParam);
Index index = Utils.genDefaultIndex(collectionName, binaryFieldName, defaultBinaryIndexType, Constants.defaultBinaryMetricType, n_list);
Response res_create = client.createIndex(index);
assert(res_create.ok());
Response res_drop = client.dropIndex(collectionName, binaryFieldName);
assert(res_drop.ok());
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray filesJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "files");
filesJsonArray.stream().map(item -> (JSONObject) item).forEach(file->{
Assert.assertFalse(file.containsKey("index_type"));
});
}
}
}
package com;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.milvus.client.InsertParam;
import io.milvus.client.InsertResponse;
import io.milvus.client.MilvusClient;
import io.milvus.client.Response;
import org.apache.commons.lang3.RandomStringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
public class TestInsertEntities_v2 {
int dimension = Constants.dimension;
String tag = "tag";
int nb = Constants.nb;
List<List<Float>> vectors = Constants.vectors;
List<List<Byte>> vectorsBinary = Constants.vectorsBinary;
// case-01
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testInsertEntitiesCollectionNotExisted(MilvusClient client, String collectionName) {
String collectionNameNew = collectionName + "_";
InsertParam insertParam = Utils.genDefaultInsertParam(collectionNameNew, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(!res.getResponse().ok());
}
// case-02
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
public void testInsertEntitiesWithoutConnect(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(!res.getResponse().ok());
}
// case-03
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testInsertEntities(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
Response res_flush = client.flush(collectionName);
assert(res_flush.ok());
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
}
// case-04
@Test(dataProvider = "IdCollection", dataProviderClass = MainClass.class)
public void testInsertEntityWithIds(MilvusClient client, String collectionName) {
// Add vectors with ids
List<Long> entityIds = LongStream.range(0, nb).boxed().collect(Collectors.toList());
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors, entityIds);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
Response res_flush = client.flush(collectionName);
assert(res_flush.ok());
// Assert ids and collection row count
Assert.assertEquals(res.getEntityIds(), entityIds);
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
}
// case-05
@Test(dataProvider = "IdCollection", dataProviderClass = MainClass.class)
public void testInsertEntityWithInvalidIds(MilvusClient client, String collectionName) {
// Add vectors with ids
List<Long> entityIds = LongStream.range(0, nb+1).boxed().collect(Collectors.toList());
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors, entityIds);
InsertResponse res = client.insert(insertParam);
assert(!res.getResponse().ok());
}
// ----------------------------- partition cases in Insert ---------------------------------
// case-08: Add vectors into collection with given tag
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testInsertEntityPartition(MilvusClient client, String collectionName) {
Response createpResponse = client.createPartition(collectionName, tag);
assert(createpResponse.ok());
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors, tag);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
Response res_flush = client.flush(collectionName);
assert(res_flush.ok());
// Assert collection row count
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray partitionsJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "partitions");
partitionsJsonArray.stream().map(item -> (JSONObject) item).filter(item->item.containsValue(tag)).forEach(obj -> {
Assert.assertEquals(obj.get("row_count"), nb);
Assert.assertEquals(obj.get("tag"), tag);
});
}
}
// case-09: Add vectors into collection, which tag not existed
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testInsertEntityPartitionTagNotExisted(MilvusClient client, String collectionName) {
Response createpResponse = client.createPartition(collectionName, tag);
assert(createpResponse.ok());
String tag = RandomStringUtils.randomAlphabetic(10);
InsertParam insertParam = Utils.genDefaultInsertParam(collectionName, dimension, nb, vectors, tag);
InsertResponse res = client.insert(insertParam);
assert(!res.getResponse().ok());
}
// case-10: Binary tests
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testInsertEntityPartitionABinary(MilvusClient client, String collectionName) {
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary, tag);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
Response res_flush = client.flush(collectionName);
assert(res_flush.ok());
// Assert collection row count
Response statsResponse = client.getCollectionStats(collectionName);
if(statsResponse.ok()) {
JSONArray partitionsJsonArray = Utils.parseJsonArray(statsResponse.getMessage(), "partitions");
partitionsJsonArray.stream().map(item -> (JSONObject) item).filter(item->item.containsValue(tag)).forEach(obj -> {
Assert.assertEquals(obj.get("tag"), tag);
Assert.assertEquals(obj.get("row_count"), nb);
});
}
}
// case-11
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testInsertEntityBinary(MilvusClient client, String collectionName) {
InsertParam insertParam = Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
Response res_flush = client.flush(collectionName);
assert(res_flush.ok());
// Assert collection row count
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
}
// case-12
@Test(dataProvider = "BinaryIdCollection", dataProviderClass = MainClass.class)
public void testInsertBinaryEntityWithIds(MilvusClient client, String collectionName) {
// Add vectors with ids
List<Long> entityIds = LongStream.range(0, nb).boxed().collect(Collectors.toList());
InsertParam insertParam =
Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary, entityIds);
InsertResponse res = client.insert(insertParam);
assert(res.getResponse().ok());
Response res_flush = client.flush(collectionName);
assert(res_flush.ok());
// Assert collection row count
Assert.assertEquals(entityIds, res.getEntityIds());
Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
}
// case-13
@Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
public void testInsertBinaryEntityWithInvalidIds(MilvusClient client, String collectionName) {
// Add vectors with ids
List<Long> invalidEntityIds = LongStream.range(0, nb+1).boxed().collect(Collectors.toList());
InsertParam insertParam =
Utils.genDefaultBinaryInsertParam(collectionName, dimension, nb, vectorsBinary, invalidEntityIds);
InsertResponse res = client.insert(insertParam);
assert(!res.getResponse().ok());
}
}
//package com;
package com;//package com;
//
//import io.milvus.client.*;
//import org.apache.commons.lang3.RandomStringUtils;
......
//package com;
package com;//package com;
//
//import io.milvus.client.*;
//import org.apache.commons.cli.*;
......
package com;
import io.milvus.client.*;
import io.milvus.client.exception.ServerSideMilvusException;
import org.apache.commons.lang3.RandomStringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
public class TestPartition {
int dimension = 128;
// ----------------------------- create partition cases in ---------------------------------
......@@ -15,22 +15,19 @@ public class TestPartition {
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testCreatePartition(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
client.createPartition(collectionName, tag);
Assert.assertEquals(client.hasPartition(collectionName, tag), true);
// show partitions
List<String> partitions = client.listPartitions(collectionName).getPartitionList();
System.out.println(partitions);
List<String> partitions = client.listPartitions(collectionName);
Assert.assertTrue(partitions.contains(tag));
}
// create partition, tag name existed
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testCreatePartitionTagNameExisted(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
Response createpResponseNew = client.createPartition(collectionName, tag);
assert (!createpResponseNew.ok());
client.createPartition(collectionName, tag);
client.createPartition(collectionName, tag);
}
// ----------------------------- has partition cases in ---------------------------------
......@@ -38,23 +35,17 @@ public class TestPartition {
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testHasPartitionTagNameNotExisted(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
client.createPartition(collectionName, tag);
String tagNew = RandomStringUtils.randomAlphabetic(10);
HasPartitionResponse haspResponse = client.hasPartition(collectionName, tagNew);
assert (haspResponse.ok());
Assert.assertFalse(haspResponse.hasPartition());
Assert.assertFalse(client.hasPartition(collectionName, tagNew));
}
// has partition, tag name existed
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testHasPartitionTagNameExisted(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
HasPartitionResponse haspResponse = client.hasPartition(collectionName, tag);
assert (haspResponse.ok());
Assert.assertTrue(haspResponse.hasPartition());
client.createPartition(collectionName, tag);
Assert.assertTrue(client.hasPartition(collectionName, tag));
}
// ----------------------------- drop partition cases in ---------------------------------
......@@ -63,62 +54,47 @@ public class TestPartition {
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testDropPartition(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponseNew = client.createPartition(collectionName, tag);
assert (createpResponseNew.ok());
Response response = client.dropPartition(collectionName, tag);
assert (response.ok());
client.createPartition(collectionName, tag);
client.dropPartition(collectionName, tag);
// show partitions
System.out.println(client.listPartitions(collectionName).getPartitionList());
int length = client.listPartitions(collectionName).getPartitionList().size();
System.out.println(client.listPartitions(collectionName));
int length = client.listPartitions(collectionName).size();
// _default
Assert.assertEquals(length, 1);
}
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDropPartitionDefault(MilvusClient client, String collectionName) {
String tag = "_default";
Response createpResponseNew = client.createPartition(collectionName, tag);
assert (!createpResponseNew.ok());
// show partitions
// System.out.println(client.listPartitions(collectionName).getPartitionList());
// int length = client.listPartitions(collectionName).getPartitionList().size();
// // _default
// Assert.assertEquals(length, 1);
client.createPartition(collectionName, tag);
}
// drop a partition repeat created before, drop by partition name
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDropPartitionRepeat(MilvusClient client, String collectionName) throws InterruptedException {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
Response response = client.dropPartition(collectionName, tag);
assert (response.ok());
Thread.currentThread().sleep(2000);
Response newResponse = client.dropPartition(collectionName, tag);
assert (!newResponse.ok());
client.createPartition(collectionName, tag);
client.dropPartition(collectionName, tag);
Thread.sleep(2000);
client.dropPartition(collectionName, tag);
}
// drop a partition not created before
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDropPartitionNotExisted(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
client.createPartition(collectionName, tag);
String tagNew = RandomStringUtils.randomAlphabetic(10);
Response response = client.dropPartition(collectionName, tagNew);
assert(!response.ok());
client.dropPartition(collectionName, tagNew);
}
// drop a partition not created before
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class, expectedExceptions = ServerSideMilvusException.class)
public void testDropPartitionTagNotExisted(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert(createpResponse.ok());
client.createPartition(collectionName, tag);
String newTag = RandomStringUtils.randomAlphabetic(10);
Response response = client.dropPartition(collectionName, newTag);
assert(!response.ok());
client.dropPartition(collectionName, newTag);
}
// ----------------------------- show partitions cases in ---------------------------------
......@@ -127,27 +103,22 @@ public class TestPartition {
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testShowPartitions(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
ListPartitionsResponse response = client.listPartitions(collectionName);
assert (response.getResponse().ok());
Assert.assertTrue(response.getPartitionList().contains(tag));
client.createPartition(collectionName, tag);
List<String> partitions = client.listPartitions(collectionName);
Assert.assertTrue(partitions.contains(tag));
}
// create multi partition, then show partitions
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
public void testShowPartitionsMulti(MilvusClient client, String collectionName) {
String tag = RandomStringUtils.randomAlphabetic(10);
Response createpResponse = client.createPartition(collectionName, tag);
assert (createpResponse.ok());
client.createPartition(collectionName, tag);
String tagNew = RandomStringUtils.randomAlphabetic(10);
Response newCreatepResponse = client.createPartition(collectionName, tagNew);
assert (newCreatepResponse.ok());
ListPartitionsResponse response = client.listPartitions(collectionName);
assert (response.getResponse().ok());
System.out.println(response.getPartitionList());
Assert.assertTrue(response.getPartitionList().contains(tag));
Assert.assertTrue(response.getPartitionList().contains(tagNew));
client.createPartition(collectionName, tagNew);
List<String> partitions = client.listPartitions(collectionName);
System.out.println(partitions);
Assert.assertTrue(partitions.contains(tag));
Assert.assertTrue(partitions.contains(tagNew));
}
}
package com;
import io.milvus.client.*;
import org.testng.annotations.Test;
public class TestPing {
@Test(dataProvider = "DefaultConnectArgs", dataProviderClass = MainClass.class)
public void testServerStatus(String host, int port) throws ConnectFailedException {
System.out.println("Host: "+host+", Port: "+port);
MilvusClient client = new MilvusGrpcClient();
ConnectParam connectParam = new ConnectParam.Builder()
.withHost(host)
.withPort(port)
.build();
client.connect(connectParam);
Response res = client.getServerStatus();
assert (res.ok());
}
@Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
public void testServerStatusWithoutConnected(MilvusClient client, String collectionName) throws ConnectFailedException {
Response res = client.getServerStatus();
assert (!res.ok());
}
}
\ No newline at end of file
//package com1;
//
//import io.milvus.client.*;
//import org.testng.annotations.Test;
//
//public class TestPing {
// @Test(dataProvider = "DefaultConnectArgs", dataProviderClass = MainClass.class)
// public void testServerStatus(String host, int port) throws ConnectFailedException {
// System.out.println("Host: "+host+", Port: "+port);
// MilvusClient client = new MilvusGrpcClient();
// ConnectParam connectParam = new ConnectParam.Builder()
// .withHost(host)
// .withPort(port)
// .build();
// client.connect(connectParam);
// Response res = client.getServerStatus();
// assert (res.ok());
// }
//
// @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
// public void testServerStatusWithoutConnected(MilvusClient client, String collectionName) throws ConnectFailedException {
// Response res = client.getServerStatus();
// assert (!res.ok());
// }
//}
\ No newline at end of file
//package com;
package com;//package com;
//
//import io.milvus.client.*;
//import org.apache.commons.lang3.RandomStringUtils;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册