TestDeleteVectors.java 7.5 KB
Newer Older
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
//package com;
//
//import io.milvus.client.*;
//import org.testng.Assert;
//import org.testng.annotations.Test;
//
//import java.nio.ByteBuffer;
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//
//public class TestDeleteVectors {
//    int dimension = 128;
//    int nb = 8000;
//
//    List<List<Float>> vectors = Utils.genVectors(nb, dimension, true);
//    List<ByteBuffer> vectorsBinary = Utils.genBinaryVectors(nb, dimension);
//
//    @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
//    public void test_delete_vectors(MilvusClient client, String collectionName) {
//        // Add vectors
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withFloatVectors(vectors).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = res.getVectorIds();
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName, ids);
//        assert(res_delete.ok());
//        client.flush(collectionName);
//        // Assert collection row count
//        Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
//    }
//
//    @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
//    public void test_delete_single_vector(MilvusClient client, String collectionName) {
//        List<List<Float>> del_vector = new ArrayList<>();
//        del_vector.add(vectors.get(0));
//        List<Long> del_ids = new ArrayList<>();
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withFloatVectors(vectors).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = res.getVectorIds();
//        del_ids.add(ids.get(0));
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
//        assert(res_delete.ok());
//        client.flush(collectionName);
//        // Assert collection row count
//        Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb - 1);
//        GetEntityByIDResponse res_get = client.getEntityByID(collectionName, del_ids);
//        assert(res_get.getResponse().ok());
//        assert(res_get.getFloatVectors().get(0).size() == 0);
//    }
//
//    @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
//    public void test_delete_vectors_collection_not_existed(MilvusClient client, String collectionName) {
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withFloatVectors(vectors).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        client.flush(collectionName);
//        List<Long> ids = res.getVectorIds();
//        Response res_delete = client.deleteEntityByID(collectionName + "_not_existed", ids);
//        assert(!res_delete.ok());
//    }
//
//    @Test(dataProvider = "Collection", dataProviderClass = MainClass.class)
//    public void test_delete_vector_id_not_existed(MilvusClient client, String collectionName) {
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withFloatVectors(vectors).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = new ArrayList<Long>();
//        ids.add((long)123456);
//        ids.add((long)1234561);
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName, ids);
//        assert(res_delete.ok());
//        client.flush(collectionName);
//        // Assert collection row count
//        Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
//    }
//
//
//    // Below tests binary vectors
//    @Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
//    public void test_delete_vectors_binary(MilvusClient client, String collectionName) {
//        // Add vectors
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withBinaryVectors(vectorsBinary).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = res.getVectorIds();
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName, ids);
//        assert(res_delete.ok());
//        client.flush(collectionName);
//        // Assert collection row count
//        Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), 0);
//    }
//
//    @Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
//    public void test_delete_single_vector_binary(MilvusClient client, String collectionName) {
//        List<ByteBuffer> del_vector = new ArrayList<>();
//        del_vector.add(vectorsBinary.get(0));
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withBinaryVectors(vectorsBinary).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = res.getVectorIds();
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName, Collections.singletonList(ids.get(0)));
//        assert(res_delete.ok());
//        client.flush(collectionName);
//        // Assert collection row count
//        Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb - 1);
//        // Cannot search for the vector
//        SearchParam searchParam = new SearchParam.Builder(collectionName)
//            .withBinaryVectors(del_vector)
//            .withTopK(1)
//            .withParamsInJson("{\"nprobe\": 20}")
//            .build();
//        SearchResponse res_search = client.search(searchParam);
//        assert(res_search.getResultIdsList().size() == 1);
//    }
//
//    @Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
//    public void test_delete_vectors_collection_not_existed_binary(MilvusClient client, String collectionName) {
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withBinaryVectors(vectorsBinary).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = res.getVectorIds();
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName + "_not_existed", ids);
//        assert(!res_delete.ok());
//    }
//
//    @Test(dataProvider = "BinaryCollection", dataProviderClass = MainClass.class)
//    public void test_delete_vector_id_not_existed_binary(MilvusClient client, String collectionName) {
//        InsertParam insertParam = new InsertParam.Builder(collectionName).withBinaryVectors(vectorsBinary).build();
//        InsertResponse res = client.insert(insertParam);
//        assert(res.getResponse().ok());
//        List<Long> ids = new ArrayList<Long>();
//        ids.add((long)123456);
//        ids.add((long)1234561);
//        client.flush(collectionName);
//        Response res_delete = client.deleteEntityByID(collectionName, ids);
//        assert(res_delete.ok());
//        client.flush(collectionName);
//        // Assert collection row count
//        Assert.assertEquals(client.countEntities(collectionName).getCollectionEntityCount(), nb);
//    }
//
//}