Skip to content

Commit

Permalink
add collection partition test
Browse files Browse the repository at this point in the history
  • Loading branch information
nameczz committed Apr 15, 2021
1 parent 7f12e1c commit 569dab9
Show file tree
Hide file tree
Showing 10 changed files with 3,656 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion example/Collection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MilvusNode } from "../milvus/index";
import { COLLECTION_NAME, DIMENSION, INDEX_FILE_SIZE, IP } from "./const";
import { COLLECTION_NAME, DIMENSION, INDEX_FILE_SIZE, IP } from "../const";

const milvusClient = new MilvusNode(IP);

Expand Down
2 changes: 1 addition & 1 deletion example/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DIMENSION,
INDEX_FILE_SIZE,
PARTITION_TAG,
} from "./const";
} from "../const";
/**
* 1. connect to milvus
* 2. create collection
Expand Down
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
transform: { "^.+\\.ts?$": "ts-jest" },
testEnvironment: "node",
testRegex: "/test/.*\\.(test|spec)?\\.(ts|tsx)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
2 changes: 1 addition & 1 deletion milvus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class MilvusNode {
*
* @return BoolReply
*/
async hasPartition(data: PartitionParam): Promise<Status> {
async hasPartition(data: PartitionParam): Promise<BoolReply> {
const promise = promisify(this.milvusClient, "HasPartition", data);
return promise;
}
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
"name": "milvus-node-sdk",
"scripts": {
"build": "tsc --declaration",
"test": "jest",
"example": "npx ts-node",
"doc": "npx typedoc milvus --theme ./node_modules/typedoc-neo-theme/bin/default --plugin typedoc-neo-theme"
},
"dependencies": {
"@grpc/grpc-js": "^1.2.12",
"@grpc/proto-loader": "^0.6.0",
"@grpc/proto-loader": "^0.6.0"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.13.8",
"@types/jest": "^26.0.22",
"jest": "^26.6.3",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.1",
"typedoc": "^0.20.35",
"typedoc-neo-theme": "^1.1.0",
"typescript": "^4.2.4"
}
}
}
65 changes: 65 additions & 0 deletions test/Collection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { MilvusNode } from "../milvus/index";

import { COLLECTION_NAME, DIMENSION, INDEX_FILE_SIZE, IP } from "../const";
import { ErrorCode } from "../milvus/response-types";

let milvusClient: any = null;
describe("Collection Crud", () => {
beforeAll(() => {
milvusClient = new MilvusNode(IP);
});
it(`Create Collection `, async () => {
const res = await milvusClient.createCollection({
collection_name: COLLECTION_NAME,
dimension: DIMENSION,
metric_type: 1,
index_file_size: INDEX_FILE_SIZE,
});
expect(res.error_code).toEqual(ErrorCode.SUCCESS);
});

it("Show Collections", async () => {
const res = await milvusClient.showCollections();
expect(res.collection_names).toEqual([COLLECTION_NAME]);
});

it("Has Collection ", async function () {
const res = await milvusClient.hasCollection({
collection_name: COLLECTION_NAME,
});
expect(res.bool_reply).toBe(true);
});

it("Describe Collection", async function () {
const res = await milvusClient.describeCollection({
collection_name: COLLECTION_NAME,
});
expect(res.collection_name).toEqual(COLLECTION_NAME);
expect(Number(res.dimension)).toEqual(DIMENSION);
expect(Number(res.index_file_size)).toEqual(INDEX_FILE_SIZE);
expect(res.metric_type).toEqual(1);
});

it("Count Collection", async function () {
const res = await milvusClient.countCollection({
collection_name: COLLECTION_NAME,
});
expect(Number(res.collection_row_count)).toEqual(0);
});

it("Show Collection Info", async function () {
const res = await milvusClient.showCollectionsInfo({
collection_name: COLLECTION_NAME,
});
// const infos = JSON.parse(res.json_info);
expect(res).toHaveProperty("json_info");
expect(res).toHaveProperty("status");
});

it("Drop Collection", async function () {
const res = await milvusClient.dropCollection({
collection_name: COLLECTION_NAME,
});
expect(res.error_code).toEqual("SUCCESS");
});
});
61 changes: 61 additions & 0 deletions test/Partition.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { MilvusNode } from "../milvus/index";

import {
COLLECTION_NAME,
DIMENSION,
INDEX_FILE_SIZE,
IP,
PARTITION_TAG,
} from "../const";
import { ErrorCode } from "../milvus/response-types";

let milvusClient = new MilvusNode(IP);
describe("Partition Crud", () => {
it(`Create Collection `, async () => {
const res = await milvusClient.createCollection({
collection_name: COLLECTION_NAME,
dimension: DIMENSION,
metric_type: 1,
index_file_size: INDEX_FILE_SIZE,
});
expect(res.error_code).toEqual(ErrorCode.SUCCESS);
});

it("Create Partitions", async () => {
const res = await milvusClient.createPartition({
collection_name: COLLECTION_NAME,
tag: PARTITION_TAG,
});
expect(res.error_code).toEqual(ErrorCode.SUCCESS);
});

it("Has Partitions", async () => {
const res = await milvusClient.hasPartition({
tag: PARTITION_TAG,
collection_name: COLLECTION_NAME,
});
expect(res.bool_reply).toBeTruthy();
});

it("Show Partitions", async () => {
const res = await milvusClient.showPartitions({
collection_name: COLLECTION_NAME,
});
expect(res.partition_tag_array).toContain(PARTITION_TAG);
});

it("Drop Partitions", async () => {
const res = await milvusClient.dropPartition({
collection_name: COLLECTION_NAME,
tag: PARTITION_TAG,
});
expect(res.error_code).toContain(ErrorCode.SUCCESS);
});

it("Drop Collection", async function () {
const res = await milvusClient.dropCollection({
collection_name: COLLECTION_NAME,
});
expect(res.error_code).toEqual("SUCCESS");
});
});
Loading

0 comments on commit 569dab9

Please sign in to comment.