-
Notifications
You must be signed in to change notification settings - Fork 7
/
IndexServiceTest.java
57 lines (48 loc) · 2 KB
/
IndexServiceTest.java
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
package com.mzz.esdemo.service;
import com.mzz.esdemo.common.TestElasticsearchHandler;
import com.mzz.esdemo.common.constant.EsConstant;
import com.mzz.esdemo.manager.SettingManager;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.ResizeResponse;
import org.elasticsearch.common.settings.Settings;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author Zero
*
**/
class IndexServiceTest {
private IndexService indexService = new IndexService(TestElasticsearchHandler.indicesClient());
@Test
void createIndex() {
String index = "temp_index_" + UUID.randomUUID();
CreateIndexResponse response = indexService.createIndex(index);
assertTrue(response.isAcknowledged());
assertTrue(indexService.exists(EsConstant.INDEX_NAME));
indexService.deleteIndex(index);
}
@Test
void putSettings() {
Settings settings = SettingManager.getBlocksWriteSettings(false);
AcknowledgedResponse response = indexService.putSettings(EsConstant.INDEX_NAME, settings);
assertTrue(response.isAcknowledged());
}
@Test
void cloneIndexWithoutData() {
String index = "index_clone_without_data";
indexService.deleteIndex(index);
CreateIndexResponse response = indexService.cloneIndexWithoutData(EsConstant.INDEX_NAME, index);
assertTrue(response.isAcknowledged());
}
@Test
void cloneIndex() {
String indexClone = "index_clone";
indexService.deleteIndex(indexClone);
indexService.putSettings(EsConstant.INDEX_NAME, SettingManager.getBlocksWriteSettings(true));
ResizeResponse response = indexService.cloneIndex(EsConstant.INDEX_NAME, indexClone);
indexService.putSettings(EsConstant.INDEX_NAME, SettingManager.getBlocksWriteSettings(false));
assertTrue(response.isAcknowledged());
}
}