TestTable.java 7.4 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 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
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();
        TableSchemaParam tableSchemaParam = new TableSchemaParam.Builder(tableSchema).build();
        Response res = client.createTable(tableSchemaParam);
        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();
        TableSchemaParam tableSchemaParam = new TableSchemaParam.Builder(tableSchema).build();
        Response res = client.createTable(tableSchemaParam);
        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();
        TableSchemaParam tableSchemaParam = new TableSchemaParam.Builder(tableSchema).build();
        Response res = client.createTable(tableSchemaParam);
        Assert.assertEquals(res.ok(), true);
        Response res_new = client.createTable(tableSchemaParam);
        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();
        TableSchemaParam tableSchemaParam = new TableSchemaParam.Builder(tableSchema).build();
        Response res = client.createTable(tableSchemaParam);
        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();
            TableSchemaParam tableSchemaParam = new TableSchemaParam.Builder(tableSchema).build();
            client.createTable(tableSchemaParam);
            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 {
        TableParam tableParam = new TableParam.Builder(tableName).build();
        Response res = client.dropTable(tableParam);
        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 {
        TableParam tableParam = new TableParam.Builder(tableName+"_").build();
        Response res = client.dropTable(tableParam);
        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 {
        TableParam tableParam = new TableParam.Builder(tableName).build();
        Response res = client.dropTable(tableParam);
        assert(!res.ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_describe_table(MilvusClient client, String tableName) throws InterruptedException {
        TableParam tableParam = new TableParam.Builder(tableName).build();
        DescribeTableResponse res = client.describeTable(tableParam);
        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 {
        TableParam tableParam = new TableParam.Builder(tableName).build();
        DescribeTableResponse res = client.describeTable(tableParam);
        assert(!res.getResponse().ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_has_table_not_existed(MilvusClient client, String tableName) throws InterruptedException {
        TableParam tableParam = new TableParam.Builder(tableName+"_").build();
        HasTableResponse res = client.hasTable(tableParam);
        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 {
        TableParam tableParam = new TableParam.Builder(tableName).build();
        HasTableResponse res = client.hasTable(tableParam);
        assert(!res.getResponse().ok());
    }

    @Test(dataProvider = "Table", dataProviderClass = MainClass.class)
    public void test_has_table(MilvusClient client, String tableName) throws InterruptedException {
        TableParam tableParam = new TableParam.Builder(tableName).build();
        HasTableResponse res = client.hasTable(tableParam);
        assert(res.getResponse().ok());
        Assert.assertTrue(res.hasTable());
    }


}