use of com.xiaomi.linden.thrift.common.LindenDeleteRequest in project linden by XiaoMi.
the class TestMultiLindenCore method testIndexNameDivision.
@Test
public void testIndexNameDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "name/");
lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.INDEX_NAME);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
json.put("index", "multi_" + i / 50);
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + i);
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(8, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(400, lindenCore.getServiceInfo().getDocsNum());
String bql = "select * from linden source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(400, result.getTotalHits());
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(50, result.getTotalHits());
bql = "select * from non-existed source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
bql = "select * from multi_1, multi_2 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(100, result.getTotalHits());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_0\"}");
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_2\"}");
Assert.assertEquals(6, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(300, lindenCore.getServiceInfo().getDocsNum());
// delete doc 50, 200, 300, 390, 397, doc 0 and doc 100 doesn't exist since multi_0 and multi_1 index are deleted
bql = "delete from linden where query is 'title:0 title:50 title:100 title:200 title:300 title:390 title:397'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(295, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
Aggregations