Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
3da09021
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
Fork自
milvus / milvus
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3da09021
编写于
3月 24, 2019
作者:
J
jinhai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update test and some interface
上级
d7e75bf9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
323 addition
and
0 deletion
+323
-0
pyengine/engine/controller/tests/__init__.py
pyengine/engine/controller/tests/__init__.py
+0
-0
pyengine/engine/controller/tests/conftest.py
pyengine/engine/controller/tests/conftest.py
+17
-0
pyengine/engine/controller/tests/test_group_handler.py
pyengine/engine/controller/tests/test_group_handler.py
+36
-0
pyengine/engine/controller/tests/test_vector_engine.py
pyengine/engine/controller/tests/test_vector_engine.py
+102
-0
pyengine/engine/controller/tests/test_views.py
pyengine/engine/controller/tests/test_views.py
+71
-0
pyengine/engine/controller/views.py
pyengine/engine/controller/views.py
+84
-0
pyengine/engine/run_test.sh
pyengine/engine/run_test.sh
+1
-0
pyengine/engine/storage/storage_manager.py
pyengine/engine/storage/storage_manager.py
+12
-0
未找到文件。
pyengine/engine/controller/tests/__init__.py
0 → 100644
浏览文件 @
3da09021
pyengine/engine/controller/tests/conftest.py
0 → 100644
浏览文件 @
3da09021
import
pytest
from
flask
import
Flask
from
engine
import
app
@
pytest
.
fixture
(
scope
=
'module'
)
def
test_client
():
# Flask provides a way to test your application by exposing the Werkzeug test Client
# and handling the context locals for you.
testing_client
=
app
.
test_client
()
# Establish an application context before running the tests.
ctx
=
app
.
app_context
()
ctx
.
push
()
yield
testing_client
# this is where the testing happens!
ctx
.
pop
()
\ No newline at end of file
pyengine/engine/controller/tests/test_group_handler.py
0 → 100644
浏览文件 @
3da09021
from
engine.controller.group_handler
import
GroupHandler
from
engine.settings
import
DATABASE_DIRECTORY
import
pytest
import
os
import
logging
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger
=
logging
.
getLogger
(
__name__
)
class
TestGroupHandler
:
def
test_get_group
(
self
):
group_path
=
GroupHandler
.
GetGroupDirectory
(
'test_group'
)
verified_path
=
DATABASE_DIRECTORY
+
'/'
+
'test_group'
logger
.
debug
(
group_path
)
assert
group_path
==
verified_path
def
test_create_group
(
self
):
group_path
=
GroupHandler
.
CreateGroupDirectory
(
'test_group'
)
if
os
.
path
.
exists
(
group_path
):
assert
True
else
:
assert
False
def
test_delete_group
(
self
):
group_path
=
GroupHandler
.
GetGroupDirectory
(
'test_group'
)
if
os
.
path
.
exists
(
group_path
):
assert
True
GroupHandler
.
DeleteGroupDirectory
(
'test_group'
)
if
os
.
path
.
exists
(
group_path
):
assert
False
else
:
assert
True
else
:
assert
False
pyengine/engine/controller/tests/test_vector_engine.py
0 → 100644
浏览文件 @
3da09021
from
engine.controller.vector_engine
import
VectorEngine
from
engine.settings
import
DATABASE_DIRECTORY
from
flask
import
jsonify
import
pytest
import
os
import
logging
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger
=
logging
.
getLogger
(
__name__
)
class
TestVectorEngine
:
def
setup_class
(
self
):
self
.
__vector
=
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
self
.
__limit
=
3
def
teardown_class
(
self
):
pass
def
test_group
(
self
):
# Make sure there is no group
code
,
group_id
,
file_number
=
VectorEngine
.
DeleteGroup
(
'test_group'
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
group_id
==
'test_group'
assert
file_number
==
0
# Add a group
code
,
group_id
,
file_number
=
VectorEngine
.
AddGroup
(
'test_group'
,
8
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
group_id
==
'test_group'
assert
file_number
==
0
# Check the group existing
code
,
group_id
,
file_number
=
VectorEngine
.
GetGroup
(
'test_group'
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
group_id
==
'test_group'
assert
file_number
==
0
# Check the group list
code
,
group_list
=
VectorEngine
.
GetGroupList
()
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
group_list
==
[{
'group_name'
:
'test_group'
,
'file_number'
:
0
}]
# Add Vector for not exist group
code
=
VectorEngine
.
AddVector
(
'not_exist_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
# Check search vector interface
code
,
vector_id
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
0
# Check create index interface
code
=
VectorEngine
.
CreateIndex
(
'test_group'
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
# Remove the group
code
,
group_id
,
file_number
=
VectorEngine
.
DeleteGroup
(
'test_group'
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
group_id
==
'test_group'
assert
file_number
==
0
# Check the group is disppeared
code
,
group_id
,
file_number
=
VectorEngine
.
GetGroup
(
'test_group'
)
assert
code
==
VectorEngine
.
FAULT_CODE
assert
group_id
==
'test_group'
assert
file_number
==
0
# Check SearchVector interface
code
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
# Create Index for not exist group id
code
=
VectorEngine
.
CreateIndex
(
'test_group'
)
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
# Clear raw file
code
=
VectorEngine
.
ClearRawFile
(
'test_group'
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
def
test_raw_file
(
self
):
filename
=
VectorEngine
.
InsertVectorIntoRawFile
(
'test_group'
,
'test_group.raw'
,
self
.
__vector
)
assert
filename
==
'test_group.raw'
expected_list
=
[
self
.
__vector
]
vector_list
=
VectorEngine
.
GetVectorListFromRawFile
(
'test_group'
,
filename
)
print
(
'expected_list: '
,
expected_list
)
print
(
'vector_list: '
,
vector_list
)
assert
vector_list
==
expected_list
code
=
VectorEngine
.
ClearRawFile
(
'test_group'
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
pyengine/engine/controller/tests/test_views.py
0 → 100644
浏览文件 @
3da09021
from
engine.controller.vector_engine
import
VectorEngine
from
engine.settings
import
DATABASE_DIRECTORY
from
engine
import
app
from
flask
import
jsonify
import
pytest
import
os
import
logging
import
json
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger
=
logging
.
getLogger
(
__name__
)
class
TestViews
:
def
loads
(
self
,
resp
):
return
json
.
loads
(
resp
.
data
.
decode
())
def
test_group
(
self
,
test_client
):
data
=
{
"dimension"
:
10
}
resp
=
test_client
.
get
(
'/vector/group/6'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
1
resp
=
test_client
.
post
(
'/vector/group/6'
,
data
=
json
.
dumps
(
data
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
resp
=
test_client
.
get
(
'/vector/group/6'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
# GroupList
resp
=
test_client
.
get
(
'/vector/group'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'group_list'
]
==
[{
'file_number'
:
0
,
'group_name'
:
'6'
}]
resp
=
test_client
.
delete
(
'/vector/group/6'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
def
test_vector
(
self
,
test_client
):
dimension
=
{
"dimension"
:
10
}
resp
=
test_client
.
post
(
'/vector/group/6'
,
data
=
json
.
dumps
(
dimension
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
vector
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]}
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
resp
=
test_client
.
post
(
'/vector/index/6'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
limit
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
],
"limit"
:
3
}
resp
=
test_client
.
get
(
'/vector/search/6'
,
data
=
json
.
dumps
(
limit
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'vector_id'
]
==
0
resp
=
test_client
.
delete
(
'/vector/group/6'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
pyengine/engine/controller/views.py
0 → 100644
浏览文件 @
3da09021
from
flask
import
Flask
,
jsonify
,
request
from
flask_restful
import
Resource
,
Api
from
engine
import
app
,
db
from
engine.model.group_table
import
GroupTable
from
engine.controller.vector_engine
import
VectorEngine
# app = Flask(__name__)
api
=
Api
(
app
)
from
flask_restful
import
reqparse
from
flask_restful
import
request
class
Vector
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
])
def
post
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
vector
=
args
[
'vector'
]
code
=
VectorEngine
.
AddVector
(
group_id
,
vector
)
return
jsonify
({
'code'
:
code
})
class
VectorSearch
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
])
self
.
__parser
.
add_argument
(
'limit'
,
type
=
int
,
action
=
'append'
,
location
=
[
'json'
])
def
get
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
print
(
'vector: '
,
args
[
'vector'
])
# go to search every thing
code
,
vector_id
=
VectorEngine
.
SearchVector
(
group_id
,
args
[
'vector'
],
args
[
'limit'
])
return
jsonify
({
'code'
:
code
,
'vector_id'
:
vector_id
})
class
Index
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
# self.__parser.add_argument('group_id', type=str)
def
post
(
self
,
group_id
):
code
=
VectorEngine
.
CreateIndex
(
group_id
)
return
jsonify
({
'code'
:
code
})
class
Group
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'group_id'
,
type
=
str
)
self
.
__parser
.
add_argument
(
'dimension'
,
type
=
int
,
action
=
'append'
,
location
=
[
'json'
])
def
post
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
dimension
=
args
[
'dimension'
]
code
,
group_id
,
file_number
=
VectorEngine
.
AddGroup
(
group_id
,
dimension
)
return
jsonify
({
'code'
:
code
,
'group'
:
group_id
,
'filenumber'
:
file_number
})
def
get
(
self
,
group_id
):
code
,
group_id
,
file_number
=
VectorEngine
.
GetGroup
(
group_id
)
return
jsonify
({
'code'
:
code
,
'group'
:
group_id
,
'filenumber'
:
file_number
})
def
delete
(
self
,
group_id
):
code
,
group_id
,
file_number
=
VectorEngine
.
DeleteGroup
(
group_id
)
return
jsonify
({
'code'
:
code
,
'group'
:
group_id
,
'filenumber'
:
file_number
})
class
GroupList
(
Resource
):
def
get
(
self
):
code
,
group_list
=
VectorEngine
.
GetGroupList
()
return
jsonify
({
'code'
:
code
,
'group_list'
:
group_list
})
api
.
add_resource
(
Vector
,
'/vector/add/<group_id>'
)
api
.
add_resource
(
Group
,
'/vector/group/<group_id>'
)
api
.
add_resource
(
GroupList
,
'/vector/group'
)
api
.
add_resource
(
Index
,
'/vector/index/<group_id>'
)
api
.
add_resource
(
VectorSearch
,
'/vector/search/<group_id>'
)
# if __name__ == '__main__':
# app.run()
pyengine/engine/run_test.sh
0 → 100755
浏览文件 @
3da09021
pytest
-v
--disable-warnings
pyengine/engine/storage/storage_manager.py
0 → 100644
浏览文件 @
3da09021
import
os
import
faiss
class
StorageManager
(
object
):
def
__init__
():
pass
def
put
(
vector
,
directory
,
index_type
):
pass
def
take
(
dir
):
pass
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录