Skip to content

Commit

Permalink
add testcases for rangeSearch、renameCollection and so on (#660)
Browse files Browse the repository at this point in the history
Signed-off-by: yongpengli-z <[email protected]>
  • Loading branch information
yongpengli-z committed Oct 17, 2023
1 parent e0e63eb commit 35eeb05
Show file tree
Hide file tree
Showing 13 changed files with 1,000 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/milvustest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.19.2</version>
<version>3.19.6</version>
</dependency>
<!--Allure-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void initCollection() {
initStringPKCollection();
// create String PK collection with binary Vector
initStringPKBinaryCollection();

// create database
milvusClient.createDatabase(CreateDatabaseParam.newBuilder().withDatabaseName(CommonData.databaseName1).build());
}

@AfterSuite(alwaysRun = true)
Expand Down Expand Up @@ -108,6 +109,8 @@ public void cleanTestData() {
logger.info("delete Default Credential:" + CommonData.defaultUserName);
milvusClient.deleteCredential(
DeleteCredentialParam.newBuilder().withUsername(CommonData.defaultUserName).build());
milvusClient.dropDatabase(DropDatabaseParam.newBuilder()
.withDatabaseName(CommonData.databaseName1).build());
milvusClient.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public class CommonData {
public static String defaultColStrJson = "colStrJson";
public static String defaultRoleName = "roleTest";
public static String defaultRoleName2 = "roleTest2";
public static String databaseName1="db1";
public static String databaseName2="db2";
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import io.milvus.grpc.DataType;
import io.milvus.param.*;
import io.milvus.param.alias.CreateAliasParam;
import io.milvus.param.collection.CreateCollectionParam;
import io.milvus.param.collection.FieldType;
import io.milvus.param.collection.LoadCollectionParam;
import io.milvus.param.collection.*;
import io.milvus.param.dml.InsertParam;
import io.milvus.param.index.CreateIndexParam;
import io.milvus.param.partition.CreatePartitionParam;
Expand Down Expand Up @@ -432,8 +430,8 @@ public static List<InsertParam.Field> generateStringData(int num) {
List<String> book_content_array = new ArrayList<>();
List<List<Float>> book_intro_array = new ArrayList<>();
for (long i = 0L; i < num; ++i) {
book_name_array.add(MathUtil.genRandomStringAndChinese(10) + "-" + i);
book_content_array.add(i + "-" + MathUtil.genRandomStringAndChinese(10));
book_name_array.add(MathUtil.genRandomStringAndChinese(5) + "-" + i);
book_content_array.add(i + "-" + MathUtil.genRandomStringAndChinese(5));
List<Float> vector = new ArrayList<>();
for (int k = 0; k < 128; ++k) {
vector.add(ran.nextFloat());
Expand All @@ -453,8 +451,8 @@ public static List<InsertParam.Field> generateStringPKBinaryData(int num) {
List<String> book_name_array = new ArrayList<>();
List<String> book_content_array = new ArrayList<>();
for (long i = 0L; i < num; ++i) {
book_name_array.add(MathUtil.genRandomStringAndChinese(10) + "-" + i);
book_content_array.add(i + "-" + MathUtil.genRandomStringAndChinese(10));
book_name_array.add(MathUtil.genRandomStringAndChinese(5) + "-" + i);
book_content_array.add(i + "-" + MathUtil.genRandomStringAndChinese(5));
}
List<ByteBuffer> book_intro_array = generateBinaryVectors(num, 128);
List<InsertParam.Field> fields = new ArrayList<>();
Expand All @@ -467,52 +465,52 @@ public static List<InsertParam.Field> generateStringPKBinaryData(int num) {

// provide extra param
public static String provideExtraParam(IndexType indexType) {
String extraParm;
String extraParam;
switch (indexType) {
case FLAT:
extraParm = "{}";
extraParam = "{}";
break;
case IVF_FLAT:
extraParm = "{\"nlist\":128}";
extraParam = "{\"nlist\":128}";
break;
case IVF_SQ8:
extraParm = "{\"nlist\":128}";
extraParam = "{\"nlist\":128}";
break;
case IVF_PQ:
extraParm = "{\"nlist\":128, \"m\":16, \"nbits\":8}";
extraParam = "{\"nlist\":128, \"m\":16, \"nbits\":8}";
break;
/* case ANNOY:
extraParm = "{\"n_trees\":16}";
break;*/
case HNSW:
extraParm = "{\"M\":16,\"efConstruction\":64}";
extraParam = "{\"M\":16,\"efConstruction\":64}";
break;
/* case RHNSW_FLAT:
extraParm = "{\"M\":16,\"efConstruction\":64}";
extraParam = "{\"M\":16,\"efConstruction\":64}";
break;*/
/* case RHNSW_PQ:
extraParm = "{\"M\":16,\"efConstruction\":64, \"PQM\":16}";
extraParam = "{\"M\":16,\"efConstruction\":64, \"PQM\":16}";
break;
case RHNSW_SQ:
extraParm = "{\"M\":16,\"efConstruction\":64}";
extraParam = "{\"M\":16,\"efConstruction\":64}";
break;*/
case BIN_IVF_FLAT:
extraParm = "{\"nlist\": 128}";
extraParam = "{\"nlist\": 128}";
break;
case SCANN:
extraParm="{\"nlist\":1024}";
extraParam="{\"nlist\":1024,\"with_raw_data\":"+true+"}";
break;
case GPU_IVF_FLAT:
extraParm="{\"nlist\": 64}";
extraParam="{\"nlist\": 64}";
break;
case GPU_IVF_PQ:
extraParm="{\"nlist\": 64, \"m\": 16, \"nbits\": 8}";
extraParam="{\"nlist\": 64, \"m\": 16, \"nbits\": 8}";
break;
default:
extraParm = "{\"nlist\":128}";
extraParam = "{\"nlist\":128}";
break;
}
return extraParm;
return extraParam;
}

public static String createNewCollectionWithDynamicField() {
Expand Down Expand Up @@ -743,4 +741,48 @@ public static void createIndexWithLoad(String collection, IndexType indexType, M

}

public static void prepareCollectionForSearch(String collection,String database){
List<InsertParam.Field> fields = generateData(2000);
milvusClient.insert(InsertParam.newBuilder()
.withCollectionName(collection)
.withDatabaseName(database)
.withFields(fields).build());
milvusClient.createIndex(
CreateIndexParam.newBuilder()
.withCollectionName(collection)
.withFieldName(CommonData.defaultVectorField)
.withIndexName(CommonData.defaultIndex)
.withMetricType(MetricType.L2)
.withIndexType(IndexType.HNSW)
.withExtraParam(CommonFunction.provideExtraParam(IndexType.HNSW))
.withSyncMode(Boolean.FALSE)
.withDatabaseName(database)
.build());
milvusClient.loadCollection(LoadCollectionParam.newBuilder()
.withCollectionName(collection)
.withDatabaseName(database)
.withSyncLoad(true)
.withSyncLoadWaitingTimeout(30L)
.withSyncLoadWaitingInterval(50L)
.build());

}

public static void clearCollection(String collection,String database){
milvusClient.releaseCollection(ReleaseCollectionParam.newBuilder()
.withCollectionName(collection).build());
milvusClient.dropCollection(DropCollectionParam.newBuilder()
.withCollectionName(collection)
.withDatabaseName(database).build());
}

public static void insertDataIntoCollection(String collection,String database,int num){
List<InsertParam.Field> fields = generateData(num);
milvusClient.insert(InsertParam.newBuilder()
.withCollectionName(collection)
.withDatabaseName(database)
.withFields(fields).build());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,15 @@ public static String genRandomStringAndChinese(int length){
}
return sb.toString();
}

public static float generalRandomLargeThanFloat(float floatNum){
Random random=new Random();
return random.nextInt(10)+floatNum+1;
}

public static float generalRandomLessThanFloat(float floatNum){
Random random=new Random();
return floatNum-random.nextInt(5)-1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class DropCollectionTest extends BaseTest {

@BeforeClass(description = "Create collection before test",alwaysRun=true)
public void provideCollectionName() {
String newCollection = CommonFunction.createNewCollection();
commonCollection = newCollection;
commonCollection = CommonFunction.createNewCollection();
}

@Severity(SeverityLevel.BLOCKER)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.zilliz.milvustest.collection;

import com.zilliz.milvustest.common.BaseTest;
import com.zilliz.milvustest.common.CommonFunction;
import com.zilliz.milvustest.util.MathUtil;
import io.milvus.param.MetricType;
import io.milvus.param.R;
import io.milvus.param.RpcStatus;
import io.milvus.param.collection.DropCollectionParam;
import io.milvus.param.collection.RenameCollectionParam;
import io.milvus.param.highlevel.collection.ListCollectionsParam;
import io.milvus.param.highlevel.collection.response.ListCollectionsResponse;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

/**
* @Author yongpeng.li
* @Date 2023/10/13 11:32
*/
@Epic("Collection")
@Feature("RenameCollection")
public class RenameCollectionTest extends BaseTest {
private String rnCollection;
private String newName;

@BeforeTest(alwaysRun = true)
public void initData(){
rnCollection= CommonFunction.createNewCollection();
newName = "collection_" + MathUtil.getRandomString(10);

}

@AfterClass(description = "delete test data after CreateCollectionTest", alwaysRun = true)
public void deleteTestData() {
if (rnCollection != null) {
milvusClient.dropCollection(
DropCollectionParam.newBuilder().withCollectionName(newName).build());
}
}

@Severity(SeverityLevel.BLOCKER)
@Test(
description = "Rename collection",
groups = {"Smoke"})
public void renameCollectionSuccess() {
R<ListCollectionsResponse> listCollectionsResponseR = milvusClient.listCollections(ListCollectionsParam.newBuilder().build());
logger.info("List0:"+listCollectionsResponseR.getData().collectionNames);
logger.info("rnCollection:"+rnCollection);
logger.info("newCollection:"+newName);
Assert.assertTrue(listCollectionsResponseR.getData().collectionNames.contains(rnCollection));
R<RpcStatus> rpcStatusR = milvusClient.renameCollection(RenameCollectionParam.newBuilder()
.withOldCollectionName(rnCollection)
.withNewCollectionName(newName)
.build());
Assert.assertEquals(rpcStatusR.getStatus().intValue(),0);
R<ListCollectionsResponse> listCollectionsResponseR1 = milvusClient.listCollections(ListCollectionsParam.newBuilder().build());
logger.info("List1:"+listCollectionsResponseR1.getData().collectionNames);
Assert.assertFalse(listCollectionsResponseR1.getData().collectionNames.contains(rnCollection));
Assert.assertTrue(listCollectionsResponseR1.getData().collectionNames.contains(newName));
}

}
Loading

0 comments on commit 35eeb05

Please sign in to comment.