TestTable.java 6.3 KB
Newer Older
J
JinHai-CN 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package com;


import io.milvus.client.*;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.List;

public class TestTable {
    int index_file_size = 50;
    int dimension = 128;

    @Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
    public void test_create_table(MilvusClient client, String tableName){
        TableSchema tableSchema = new TableSchema.Builder(tableName, dimension)
                .withIndexFileSize(index_file_size)
                .withMetricType(MetricType.L2)
                .build();
20
        Response res = client.createTable(tableSchema);
J
JinHai-CN 已提交
21 22 23 24 25 26 27 28 29 30
        assert(res.ok());
        Assert.assertEquals(res.ok(), true);
    }

    @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
    public void test_create_table_disconnect(MilvusClient client, String tableName){
        TableSchema tableSchema = new TableSchema.Builder(tableName, dimension)
                .withIndexFileSize(index_file_size)
                .withMetricType(MetricType.L2)
                .build();
31
        Response res = client.createTable(tableSchema);
J
JinHai-CN 已提交
32 33 34 35 36 37 38 39 40
        assert(!res.ok());
    }

    @Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
    public void test_create_table_repeatably(MilvusClient client, String tableName){
        TableSchema tableSchema = new TableSchema.Builder(tableName, dimension)
                .withIndexFileSize(index_file_size)
                .withMetricType(MetricType.L2)
                .build();
41
        Response res = client.createTable(tableSchema);
J
JinHai-CN 已提交
42
        Assert.assertEquals(res.ok(), true);
43
        Response res_new = client.createTable(tableSchema);
J
JinHai-CN 已提交
44 45 46 47 48 49 50 51 52 53
        Assert.assertEquals(res_new.ok(), false);
    }

    @Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
    public void test_create_table_wrong_params(MilvusClient client, String tableName){
        Integer dimension = 0;
        TableSchema tableSchema = new TableSchema.Builder(tableName, dimension)
                .withIndexFileSize(index_file_size)
                .withMetricType(MetricType.L2)
                .build();
54
        Response res = client.createTable(tableSchema);
J
JinHai-CN 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68
        System.out.println(res.toString());
        Assert.assertEquals(res.ok(), false);
    }

    @Test(dataProvider = "ConnectInstance", dataProviderClass = MainClass.class)
    public void test_show_tables(MilvusClient client, String tableName){
        Integer tableNum = 10;
        ShowTablesResponse res = null;
        for (int i = 0; i < tableNum; ++i) {
            String tableNameNew = tableName+"_"+Integer.toString(i);
            TableSchema tableSchema = new TableSchema.Builder(tableNameNew, dimension)
                    .withIndexFileSize(index_file_size)
                    .withMetricType(MetricType.L2)
                    .build();
69
            client.createTable(tableSchema);
J
JinHai-CN 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82
            List<String> tableNames = client.showTables().getTableNames();
            Assert.assertTrue(tableNames.contains(tableNameNew));
        }
    }

    @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
    public void test_show_tables_without_connect(MilvusClient client, String tableName){
        ShowTablesResponse res = client.showTables();
        assert(!res.getResponse().ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_drop_table(MilvusClient client, String tableName) throws InterruptedException {
83
        Response res = client.dropTable(tableName);
J
JinHai-CN 已提交
84 85 86 87 88 89 90 91
        assert(res.ok());
        Thread.currentThread().sleep(1000);
        List<String> tableNames = client.showTables().getTableNames();
        Assert.assertFalse(tableNames.contains(tableName));
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_drop_table_not_existed(MilvusClient client, String tableName) throws InterruptedException {
92
        Response res = client.dropTable(tableName+"_");
J
JinHai-CN 已提交
93 94 95 96 97 98 99
        assert(!res.ok());
        List<String> tableNames = client.showTables().getTableNames();
        Assert.assertTrue(tableNames.contains(tableName));
    }

    @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
    public void test_drop_table_without_connect(MilvusClient client, String tableName) throws InterruptedException {
100
        Response res = client.dropTable(tableName);
J
JinHai-CN 已提交
101 102 103 104 105
        assert(!res.ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_describe_table(MilvusClient client, String tableName) throws InterruptedException {
106
        DescribeTableResponse res = client.describeTable(tableName);
J
JinHai-CN 已提交
107 108 109 110 111 112 113 114 115 116
        assert(res.getResponse().ok());
        TableSchema tableSchema = res.getTableSchema().get();
        Assert.assertEquals(tableSchema.getDimension(), dimension);
        Assert.assertEquals(tableSchema.getTableName(), tableName);
        Assert.assertEquals(tableSchema.getIndexFileSize(), index_file_size);
        Assert.assertEquals(tableSchema.getMetricType().name(), tableName.substring(0,2));
    }

    @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
    public void test_describe_table_without_connect(MilvusClient client, String tableName) throws InterruptedException {
117
        DescribeTableResponse res = client.describeTable(tableName);
J
JinHai-CN 已提交
118 119 120 121 122
        assert(!res.getResponse().ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_has_table_not_existed(MilvusClient client, String tableName) throws InterruptedException {
123
        HasTableResponse res = client.hasTable(tableName+"_");
J
JinHai-CN 已提交
124 125 126 127 128 129
        assert(res.getResponse().ok());
        Assert.assertFalse(res.hasTable());
    }

    @Test(dataProvider = "DisConnectInstance", dataProviderClass = MainClass.class)
    public void test_has_table_without_connect(MilvusClient client, String tableName) throws InterruptedException {
130
        HasTableResponse res = client.hasTable(tableName);
J
JinHai-CN 已提交
131 132 133 134 135
        assert(!res.getResponse().ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_has_table(MilvusClient client, String tableName) throws InterruptedException {
136
        HasTableResponse res = client.hasTable(tableName);
J
JinHai-CN 已提交
137 138 139 140 141 142
        assert(res.getResponse().ok());
        Assert.assertTrue(res.hasTable());
    }


}