提交 72a32001 编写于 作者: P pengys5

test case failure

上级 1d1d8d97
......@@ -18,7 +18,7 @@ public class EsConfig {
public static class Index {
public static class Initialize {
public static String model = "";
public static IndexInitMode mode;
}
public static class Shards {
......@@ -31,7 +31,7 @@ public class EsConfig {
}
}
public enum IndexInitModel {
public enum IndexInitMode {
auto, forced, manual
}
}
......@@ -25,9 +25,6 @@ public class EsConfigProvider implements ConfigProvider {
EsConfig.Es.Cluster.Transport.sniffer = System.getProperty("es.cluster.transport.sniffer");
}
if (!StringUtil.isEmpty(System.getProperty("es.index.create"))) {
EsConfig.Es.Index.create = System.getProperty("es.index.create");
}
if (!StringUtil.isEmpty(System.getProperty("es.index.shards.number"))) {
EsConfig.Es.Index.Shards.number = System.getProperty("es.index.shards.number");
}
......
......@@ -13,6 +13,7 @@ import org.elasticsearch.transport.client.PreBuiltTransportClient;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
......@@ -46,9 +47,9 @@ public enum EsClient {
public void indexRefresh(String... indexName) {
RefreshResponse response = client.admin().indices().refresh(new RefreshRequest(indexName)).actionGet();
if (response.getShardFailures().length == response.getTotalShards()) {
logger.error("All elasticsearch shard index refresh failure, reason: %s", response.getShardFailures());
logger.error("All elasticsearch shard index refresh failure, reason: %s", Arrays.toString(response.getShardFailures()));
} else if (response.getShardFailures().length > 0) {
logger.error("In parts of elasticsearch shard index refresh failure, reason: %s", response.getShardFailures());
logger.error("In parts of elasticsearch shard index refresh failure, reason: %s", Arrays.toString(response.getShardFailures()));
}
logger.info("elasticsearch index refresh success");
}
......
......@@ -17,12 +17,12 @@ public enum IndexCreator {
private Logger logger = LogManager.getFormatterLogger(IndexCreator.class);
public void create() {
if (!EsConfig.IndexInitModel.manual.name().equals(EsConfig.Es.Index.Initialize.model)) {
if (!EsConfig.IndexInitMode.manual.equals(EsConfig.Es.Index.Initialize.mode)) {
Set<AbstractIndex> indexSet = loadIndex();
for (AbstractIndex index : indexSet) {
boolean isExists = index.isExists();
if (isExists) {
if (EsConfig.IndexInitModel.forced.name().equals(EsConfig.Es.Index.Initialize.model)) {
if (EsConfig.IndexInitMode.forced.equals(EsConfig.Es.Index.Initialize.mode)) {
index.deleteIndex();
index.createIndex();
}
......
......@@ -30,7 +30,7 @@ es.cluster.nodes=127.0.0.1:9300
# Options: auto, forced, manual
# auto: just create new index when index not created.
# forced: delete the index then create
es.index.initialize.model=auto
es.index.initialize.mode=auto
es.index.shards.number=2
es.index.replicas.number=0
......
......@@ -64,16 +64,16 @@ public class IndexCreatorTestCase {
}
@Test
public void testCreateOptionOff() throws Exception {
EsConfig.Es.Index.create = EsConfig.Create_Off;
public void testCreateOptionManual() throws Exception {
EsConfig.Es.Index.Initialize.mode = EsConfig.IndexInitMode.manual;
indexCreator.create();
Mockito.verify(testIndex, Mockito.never()).createIndex();
Mockito.verify(testIndex, Mockito.never()).deleteIndex();
}
@Test
public void testCreateOptionOverWriteIndexIsExists() throws Exception {
EsConfig.Es.Index.create = EsConfig.Create_Overwrite;
public void testCreateOptionForcedIndexIsExists() throws Exception {
EsConfig.Es.Index.Initialize.mode = EsConfig.IndexInitMode.forced;
when(testIndex.isExists()).thenReturn(true);
indexCreator.create();
Mockito.verify(testIndex).createIndex();
......@@ -81,8 +81,8 @@ public class IndexCreatorTestCase {
}
@Test
public void testCreateOptionOverWriteIndexNotExists() throws Exception {
EsConfig.Es.Index.create = EsConfig.Create_Overwrite;
public void testCreateOptionForcedIndexNotExists() throws Exception {
EsConfig.Es.Index.Initialize.mode = EsConfig.IndexInitMode.forced;
when(testIndex.isExists()).thenReturn(false);
indexCreator.create();
Mockito.verify(testIndex).createIndex();
......@@ -90,8 +90,8 @@ public class IndexCreatorTestCase {
}
@Test
public void testCreateOptionIgnoreIndexNotExists() throws Exception {
EsConfig.Es.Index.create = EsConfig.Create_Ignore;
public void testCreateOptionAutoIndexNotExists() throws Exception {
EsConfig.Es.Index.Initialize.mode = EsConfig.IndexInitMode.auto;
when(testIndex.isExists()).thenReturn(false);
indexCreator.create();
Mockito.verify(testIndex).createIndex();
......@@ -99,8 +99,8 @@ public class IndexCreatorTestCase {
}
@Test
public void testCreateOptionIgnoreIndexExists() throws Exception {
EsConfig.Es.Index.create = EsConfig.Create_Ignore;
public void testCreateOptionAutoIndexExists() throws Exception {
EsConfig.Es.Index.Initialize.mode = EsConfig.IndexInitMode.auto;
when(testIndex.isExists()).thenReturn(true);
indexCreator.create();
Mockito.verify(testIndex, Mockito.never()).createIndex();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册