-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAO_ITCase
105 lines (74 loc) · 2.62 KB
/
DAO_ITCase
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
package model;
import com.google.common.base.Throwables;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.junit.After;
import org.junit.Before;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.matchers.JUnitMatchers.*;
public class DAO_ITCase {
Logger logger = Logger.getLogger(getClass());
EsServer server = new EsServer();
@Before
public void setUp() throws Exception {
server.start();
}
@After
public void tearDown() throws Exception {
server.close();
}
@Test
public void testDao() {
}
public Client getClient() {
return server.client();
}
class EsServer {
private Node server;
void start(){
BasicConfigurator.configure();
server = nodeBuilder().build();
server.start();
checkServerStatus();
}
void close(){
server.close();
}
public Client client() {
return server.client();
}
ClusterHealthStatus getHealthStatus() {
return getClient().admin().cluster().prepareHealth().execute().actionGet().getStatus();
}
void checkServerStatus() {
ClusterHealthStatus status = getHealthStatus();
// Check the current status of the ES cluster.
if (ClusterHealthStatus.RED.equals(status)) {
logger.info("ES cluster status is " + status + ". Waiting for ES recovery.");
// Waits at most 30 seconds to make sure the cluster health is at least yellow.
getClient().admin().cluster().prepareHealth()
.setWaitForYellowStatus()
.setTimeout("30s")
.execute().actionGet();
}
// Check the cluster health for a final time.
status = getHealthStatus();
logger.info("ES cluster status is " + status);
// If we are still in red status, then we cannot proceed.
if (ClusterHealthStatus.RED.equals(status)) {
throw new RuntimeException("ES cluster health status is RED. Server is not able to start.");
}
}
}
}