Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
730a09be
M
milvus
项目概览
milvus
/
milvus
9 个月 前同步成功
通知
260
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
730a09be
编写于
8月 25, 2020
作者:
T
ThreadDao
提交者:
GitHub
8月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[skip ci] add assert by collection stats (#3437)
Signed-off-by:
N
zongyufen
<
zongyufen@foxmail.com
>
上级
41f844f8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
142 addition
and
72 deletion
+142
-72
tests/milvus-java-test/src/main/java/com/MainClass.java
tests/milvus-java-test/src/main/java/com/MainClass.java
+1
-2
tests/milvus-java-test/src/main/java/com/TestCompact.java
tests/milvus-java-test/src/main/java/com/TestCompact.java
+35
-12
tests/milvus-java-test/src/main/java/com/TestDeleteEntities.java
...ilvus-java-test/src/main/java/com/TestDeleteEntities.java
+6
-6
tests/milvus-java-test/src/main/java/com/TestIndex.java
tests/milvus-java-test/src/main/java/com/TestIndex.java
+39
-13
tests/milvus-java-test/src/main/java/com/TestInsertEntities.java
...ilvus-java-test/src/main/java/com/TestInsertEntities.java
+45
-37
tests/milvus-java-test/src/main/java/com/Utils.java
tests/milvus-java-test/src/main/java/com/Utils.java
+16
-2
未找到文件。
tests/milvus-java-test/src/main/java/com/MainClass.java
浏览文件 @
730a09be
...
...
@@ -21,7 +21,6 @@ public class MainClass {
private
static
String
HOST
=
"127.0.0.1"
;
private
static
int
PORT
=
19530
;
private
int
segmentRowCount
=
5000
;
public
int
dimension
=
128
;
private
static
ConnectParam
CONNECT_PARAM
=
new
ConnectParam
.
Builder
()
.
withHost
(
HOST
)
.
withPort
(
PORT
)
...
...
@@ -69,7 +68,7 @@ public class MainClass {
private
Object
[][]
genCollection
(
boolean
isBinary
,
boolean
autoId
)
throws
ConnectFailedException
{
Object
[][]
collection
;
String
collectionName
=
Utils
.
genUniqueStr
(
"collection"
);
List
<
Map
<
String
,
Object
>>
defaultFields
=
Utils
.
genDefaultFields
(
dimension
,
isBinary
);
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
();
...
...
tests/milvus-java-test/src/main/java/com/TestCompact.java
浏览文件 @
730a09be
package
com
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
io.milvus.client.*
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
import
java.util.List
;
public
class
TestCompact
{
int
nb
=
Constants
.
nb
;
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testCompactAfterDelete
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
build
();
...
...
@@ -16,11 +20,13 @@ public class TestCompact {
Response
res_delete
=
client
.
deleteEntityByID
(
collectionName
,
ids
);
assert
(
res_delete
.
ok
());
client
.
flush
(
collectionName
);
CompactParam
compactParam
=
new
CompactParam
.
Builder
(
collectionName
)
.
withThreshold
(
0.3
)
.
build
();
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
());
Assert
.
assertEquals
(
jsonObject
.
getIntValue
(
"data_size"
),
0
);
Assert
.
assertEquals
(
client
.
countEntities
(
collectionName
).
getCollectionEntityCount
(),
0
);
}
...
...
@@ -34,31 +40,48 @@ public class TestCompact {
Response
res_delete
=
client
.
deleteEntityByID
(
collectionName
,
ids
);
assert
(
res_delete
.
ok
());
client
.
flush
(
collectionName
);
CompactParam
compactParam
=
new
CompactParam
.
Builder
(
collectionName
)
.
withThreshold
(
0.3
)
.
build
();
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
());
Assert
.
assertEquals
(
jsonObject
.
getIntValue
(
"data_size"
),
0
);
Assert
.
assertEquals
(
client
.
countEntities
(
collectionName
).
getCollectionEntityCount
(),
0
);
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testCompactNoCollection
(
MilvusClient
client
,
String
collectionName
)
{
String
name
=
""
;
CompactParam
compactParam
=
new
CompactParam
.
Builder
(
name
)
.
withThreshold
(
0.3
)
.
build
();
CompactParam
compactParam
=
new
CompactParam
.
Builder
(
name
).
build
();
Response
res_compact
=
client
.
compact
(
compactParam
);
assert
(!
res_compact
.
ok
());
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testCompactEmptyCollection
(
MilvusClient
client
,
String
collectionName
)
{
CompactParam
compactParam
=
new
CompactParam
.
Builder
(
collectionName
)
.
withThreshold
(
0.3
)
.
build
();
CompactParam
compactParam
=
new
CompactParam
.
Builder
(
collectionName
).
build
();
Response
res_compact
=
client
.
compact
(
compactParam
);
assert
(
res_compact
.
ok
());
}
@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"
));
}
}
tests/milvus-java-test/src/main/java/com/TestDeleteEntities.java
浏览文件 @
730a09be
...
...
@@ -14,7 +14,7 @@ import java.util.stream.LongStream;
public
class
TestDeleteEntities
{
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testDelete
Vector
s
(
MilvusClient
client
,
String
collectionName
)
{
public
void
testDelete
Entitie
s
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
...
...
@@ -28,7 +28,7 @@ public class TestDeleteEntities {
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testDeleteSingle
Vector
(
MilvusClient
client
,
String
collectionName
)
{
public
void
testDeleteSingle
Entity
(
MilvusClient
client
,
String
collectionName
)
{
List
<
List
<
Float
>>
del_vector
=
new
ArrayList
<>();
del_vector
.
add
(
Constants
.
vectors
.
get
(
0
));
List
<
Long
>
del_ids
=
new
ArrayList
<>();
...
...
@@ -50,7 +50,7 @@ public class TestDeleteEntities {
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testDelete
Vector
sCollectionNotExisted
(
MilvusClient
client
,
String
collectionName
)
{
public
void
testDelete
Entitie
sCollectionNotExisted
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
...
...
@@ -62,7 +62,7 @@ public class TestDeleteEntities {
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testDelete
Vector
sEmptyCollection
(
MilvusClient
client
,
String
collectionName
)
{
public
void
testDelete
Entitie
sEmptyCollection
(
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
);
...
...
@@ -70,7 +70,7 @@ public class TestDeleteEntities {
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
test
_delete_vector_id_not_e
xisted
(
MilvusClient
client
,
String
collectionName
)
{
public
void
test
DeleteEntityIdNotE
xisted
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
...
...
@@ -87,7 +87,7 @@ public class TestDeleteEntities {
// Below tests binary vectors
@Test
(
dataProvider
=
"BinaryCollection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
test
_delete_vectors_b
inary
(
MilvusClient
client
,
String
collectionName
)
{
public
void
test
DeleteEntitiesB
inary
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultBinaryEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
...
...
tests/milvus-java-test/src/main/java/com/TestIndex.java
浏览文件 @
730a09be
package
com
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
io.milvus.client.*
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.logging.Logger
;
public
class
TestIndex
{
...
...
@@ -17,7 +16,13 @@ public class TestIndex {
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
);
// TODO: should check getCollectionStats
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
));
}
}
@Test
(
dataProvider
=
"BinaryCollection"
,
dataProviderClass
=
MainClass
.
class
)
...
...
@@ -27,6 +32,13 @@ public class TestIndex {
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
);
// TODO: should check getCollectionStats
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
));
}
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
...
...
@@ -91,9 +103,16 @@ public class TestIndex {
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());
// TODO: getCollectionStats
Response
res_drop
=
client
.
dropIndex
(
collectionName
,
Constants
.
floatFieldName
);
assert
(
res_drop
.
ok
());
Response
statsResponse
=
client
.
getCollectionStats
(
collectionName
);
// TODO: should check getCollectionStats
if
(
statsResponse
.
ok
())
{
JSONArray
filesJsonArray
=
Utils
.
parseJsonArray
(
statsResponse
.
getMessage
(),
"files"
);
filesJsonArray
.
stream
().
map
(
item
->
(
JSONObject
)
item
).
forEach
(
file
->{
assert
(!
file
.
containsKey
(
"index_type"
));
});
}
}
@Test
(
dataProvider
=
"BinaryCollection"
,
dataProviderClass
=
MainClass
.
class
)
...
...
@@ -103,22 +122,29 @@ public class TestIndex {
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());
// TODO: getCollectionStats
Response
res_drop
=
client
.
dropIndex
(
collectionName
,
Constants
.
binaryFieldName
);
assert
(
res_drop
.
ok
());
Response
statsResponse
=
client
.
getCollectionStats
(
collectionName
);
// TODO: should check getCollectionStats
if
(
statsResponse
.
ok
())
{
JSONArray
filesJsonArray
=
Utils
.
parseJsonArray
(
statsResponse
.
getMessage
(),
"files"
);
filesJsonArray
.
stream
().
map
(
item
->
(
JSONObject
)
item
).
forEach
(
file
->{
assert
(!
file
.
containsKey
(
"index_type"
));
});
}
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testDropIndexTableNotExisted
(
MilvusClient
client
,
String
collectionName
)
{
String
collectionNameNew
=
Utils
.
genUniqueStr
(
collectionName
);
//
Response res_drop = client.dropIndex(collectionNameNew, Constants.floatFieldName);
//
assert(!res_drop.ok());
Response
res_drop
=
client
.
dropIndex
(
collectionNameNew
,
Constants
.
floatFieldName
);
assert
(!
res_drop
.
ok
());
}
@Test
(
dataProvider
=
"DisConnectInstance"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testDropIndexWithoutConnect
(
MilvusClient
client
,
String
collectionName
)
{
// Response res_drop = client.dropIndex(collectionNameNew
, Constants.floatFieldName);
//
assert(!res_drop.ok());
Response
res_drop
=
client
.
dropIndex
(
collectionName
,
Constants
.
floatFieldName
);
assert
(!
res_drop
.
ok
());
}
}
tests/milvus-java-test/src/main/java/com/TestInsertEntities.java
浏览文件 @
730a09be
package
com
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
io.milvus.client.*
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.testng.Assert
;
...
...
@@ -11,33 +13,29 @@ import java.util.stream.Collectors;
import
java.util.stream.LongStream
;
public
class
TestInsertEntities
{
int
dimension
=
128
;
int
dimension
=
Constants
.
dimension
;
String
tag
=
"tag"
;
int
nb
=
8000
;
List
<
List
<
Float
>>
vectors
=
Utils
.
genVectors
(
nb
,
dimension
,
true
);
List
<
ByteBuffer
>
vectorsBinary
=
Utils
.
genBinaryVectors
(
nb
,
dimension
);
List
<
Map
<
String
,
Object
>>
defaultEntities
=
Utils
.
genDefaultEntities
(
dimension
,
nb
,
vectors
);
List
<
Map
<
String
,
Object
>>
defaultBinaryEntities
=
Utils
.
genDefaultBinaryEntities
(
dimension
,
nb
,
vectorsBinary
);
int
nb
=
Constants
.
nb
;
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntitiesCollectionNotExisted
(
MilvusClient
client
,
String
collectionName
)
throws
InterruptedException
{
public
void
testInsertEntitiesCollectionNotExisted
(
MilvusClient
client
,
String
collectionName
)
{
String
collectionNameNew
=
collectionName
+
"_"
;
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionNameNew
)
.
withFields
(
defaultEntities
).
build
();
.
withFields
(
Constants
.
defaultEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
}
@Test
(
dataProvider
=
"DisConnectInstance"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntitiesWithoutConnect
(
MilvusClient
client
,
String
collectionName
)
throws
InterruptedException
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultEntities
).
build
();
public
void
testInsertEntitiesWithoutConnect
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntities
(
MilvusClient
client
,
String
collectionName
)
{
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultEntities
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
Response
res_flush
=
client
.
flush
(
collectionName
);
...
...
@@ -51,14 +49,15 @@ public class TestInsertEntities {
// Add vectors with ids
List
<
Long
>
entityIds
=
LongStream
.
range
(
0
,
nb
).
boxed
().
collect
(
Collectors
.
toList
());
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
)
.
withFields
(
defaultEntities
)
.
withFields
(
Constants
.
defaultEntities
)
.
withEntityIds
(
entityIds
)
.
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
Response
res_flush
=
client
.
flush
(
collectionName
);
assert
(
res_flush
.
ok
());
// Assert collection row count
// Assert ids and collection row count
Assert
.
assertEquals
(
res
.
getEntityIds
(),
entityIds
);
Assert
.
assertEquals
(
client
.
countEntities
(
collectionName
).
getCollectionEntityCount
(),
nb
);
}
...
...
@@ -66,29 +65,23 @@ public class TestInsertEntities {
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
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultEntities
).
withEntityIds
(
entityIds
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
withEntityIds
(
entityIds
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
}
//
@Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
//
public void testInsertEntityWithInvalidDimension(MilvusClient client, String collectionName) {
//// vectors.get(0).add((float) 0
);
//
List<Map<String,Object>> entities = Utils.genDefaultEntities(dimension+1,nb,vectors);
//
InsertParam insertParam = new InsertParam.Builder(collectionName).withFields(entities).build();
//
InsertResponse res = client.insert(insertParam);
//
assert(!res.getResponse().ok());
//
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntityWithInvalidDimension
(
MilvusClient
client
,
String
collectionName
)
{
List
<
List
<
Float
>>
vectors
=
Utils
.
genVectors
(
nb
,
dimension
+
1
,
true
);
List
<
Map
<
String
,
Object
>>
entities
=
Utils
.
genDefaultEntities
(
dimension
+
1
,
nb
,
vectors
);
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
entities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
}
@Test
(
dataProvider
=
"Collection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntityWithInvalidVectors
(
MilvusClient
client
,
String
collectionName
)
{
// vectors.set(0, new ArrayList<>());
List
<
Map
<
String
,
Object
>>
invalidEntities
=
Utils
.
genDefaultEntities
(
dimension
,
nb
,
new
ArrayList
<>());
invalidEntities
.
forEach
(
entity
->{
if
(
"float_vector"
.
equals
(
entity
.
get
(
"field"
))){
entity
.
put
(
"values"
,
new
ArrayList
<>());
}
});
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
invalidEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
...
...
@@ -100,13 +93,20 @@ public class TestInsertEntities {
public
void
testInsertEntityPartition
(
MilvusClient
client
,
String
collectionName
)
{
Response
createpResponse
=
client
.
createPartition
(
collectionName
,
tag
);
assert
(
createpResponse
.
ok
());
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultEntities
).
withPartitionTag
(
tag
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
withPartitionTag
(
tag
).
build
();
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
);
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
);
});
}
}
// Add vectors into collection, which tag not existed
...
...
@@ -115,7 +115,7 @@ public class TestInsertEntities {
Response
createpResponse
=
client
.
createPartition
(
collectionName
,
tag
);
assert
(
createpResponse
.
ok
());
String
tag
=
RandomStringUtils
.
randomAlphabetic
(
10
);
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultEntities
).
withPartitionTag
(
tag
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultEntities
).
withPartitionTag
(
tag
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
}
...
...
@@ -124,19 +124,26 @@ public class TestInsertEntities {
@Test
(
dataProvider
=
"BinaryCollection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntityPartitionABinary
(
MilvusClient
client
,
String
collectionName
)
{
Response
createpResponse
=
client
.
createPartition
(
collectionName
,
tag
);
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultBinaryEntities
).
withPartitionTag
(
tag
).
build
();
assert
(
createpResponse
.
ok
());
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultBinaryEntities
).
withPartitionTag
(
tag
).
build
();
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
);
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
);
});
}
}
@Test
(
dataProvider
=
"BinaryCollection"
,
dataProviderClass
=
MainClass
.
class
)
public
void
testInsertEntityBinary
(
MilvusClient
client
,
String
collectionName
)
{
System
.
out
.
println
(
collectionName
);
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultBinaryEntities
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultBinaryEntities
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(
res
.
getResponse
().
ok
());
Response
res_flush
=
client
.
flush
(
collectionName
);
...
...
@@ -149,12 +156,13 @@ public class TestInsertEntities {
public
void
testInsertBinaryEntityWithIds
(
MilvusClient
client
,
String
collectionName
)
{
// Add vectors with ids
List
<
Long
>
entityIds
=
LongStream
.
range
(
0
,
nb
).
boxed
().
collect
(
Collectors
.
toList
());
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultBinaryEntities
).
withEntityIds
(
entityIds
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultBinaryEntities
).
withEntityIds
(
entityIds
).
build
();
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
);
}
...
...
@@ -162,7 +170,7 @@ public class TestInsertEntities {
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
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
defaultBinaryEntities
).
withEntityIds
(
invalidEntityIds
).
build
();
InsertParam
insertParam
=
new
InsertParam
.
Builder
(
collectionName
).
withFields
(
Constants
.
defaultBinaryEntities
).
withEntityIds
(
invalidEntityIds
).
build
();
InsertResponse
res
=
client
.
insert
(
insertParam
);
assert
(!
res
.
getResponse
().
ok
());
}
...
...
tests/milvus-java-test/src/main/java/com/Utils.java
浏览文件 @
730a09be
...
...
@@ -9,6 +9,7 @@ import org.apache.commons.lang3.RandomStringUtils;
import
java.nio.ByteBuffer
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
public
class
Utils
{
...
...
@@ -89,8 +90,6 @@ public class Utils {
List
<
Map
<
String
,
Object
>>
fieldsMap
=
genDefaultFields
(
dimension
,
false
);
List
<
Long
>
intValues
=
new
ArrayList
<>(
vectorCount
);
List
<
Float
>
floatValues
=
new
ArrayList
<>(
vectorCount
);
// List<List<Float>> vectors = genVectors(vectorCount,dimension,false);
// List<ByteBuffer> binaryVectors = genBinaryVectors(vectorCount,dimension);
for
(
int
i
=
0
;
i
<
vectorCount
;
++
i
)
{
intValues
.
add
((
long
)
i
);
floatValues
.
add
((
float
)
i
);
...
...
@@ -225,4 +224,19 @@ public class Utils {
});
return
vector
;
}
public
static
JSONArray
parseJsonArray
(
String
message
,
String
type
)
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
message
);
JSONArray
partitionsJsonArray
=
jsonObject
.
getJSONArray
(
"partitions"
);
if
(
"partitions"
.
equals
(
type
))
return
partitionsJsonArray
;
JSONArray
segmentsJsonArray
=
((
JSONObject
)
partitionsJsonArray
.
get
(
0
)).
getJSONArray
(
"segments"
);
if
(
"segments"
.
equals
(
type
))
return
segmentsJsonArray
;
JSONArray
filesJsonArray
=
((
JSONObject
)
segmentsJsonArray
.
get
(
0
)).
getJSONArray
(
"files"
);
if
(
"files"
.
equals
(
type
))
return
filesJsonArray
;
throw
new
RuntimeException
(
"unsupported type"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录