use of io.crate.http.HttpTestServer in project crate by crate.
the class PingTaskTest method testSuccessfulPingTaskRun.
@Test
public void testSuccessfulPingTaskRun() throws Exception {
testServer = new HttpTestServer(18080, false);
testServer.run();
PingTask task = new PingTask(clusterService, clusterIdService, extendedNodeInfo, "http://localhost:18080/", Settings.EMPTY);
task.run();
assertThat(testServer.responses.size(), is(1));
task.run();
assertThat(testServer.responses.size(), is(2));
for (long i = 0; i < testServer.responses.size(); i++) {
String json = testServer.responses.get((int) i);
Map<String, String> map = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
try {
//convert JSON string to Map
map = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
});
} catch (Exception e) {
e.printStackTrace();
}
assertThat(map, hasKey("kernel"));
assertThat(map.get("kernel"), is(notNullValue()));
assertThat(map, hasKey("cluster_id"));
assertThat(map.get("cluster_id"), is(notNullValue()));
assertThat(map, hasKey("master"));
assertThat(map.get("master"), is(notNullValue()));
assertThat(map, hasKey("ping_count"));
assertThat(map.get("ping_count"), is(notNullValue()));
Map<String, Long> pingCountMap;
pingCountMap = mapper.readValue(map.get("ping_count"), new TypeReference<Map<String, Long>>() {
});
assertThat(pingCountMap.get("success"), is(i));
assertThat(pingCountMap.get("failure"), is(0L));
if (task.getHardwareAddress() != null) {
assertThat(map, hasKey("hardware_address"));
assertThat(map.get("hardware_address"), is(notNullValue()));
}
assertThat(map, hasKey("crate_version"));
assertThat(map.get("crate_version"), is(notNullValue()));
assertThat(map, hasKey("java_version"));
assertThat(map.get("java_version"), is(notNullValue()));
}
}
use of io.crate.http.HttpTestServer in project crate by crate.
the class PingTaskTest method testUnsuccessfulPingTaskRun.
@Test
public void testUnsuccessfulPingTaskRun() throws Exception {
testServer = new HttpTestServer(18081, true);
testServer.run();
PingTask task = createPingTask("http://localhost:18081/");
task.run();
assertThat(testServer.responses.size(), is(1));
task.run();
assertThat(testServer.responses.size(), is(2));
for (int i = 0; i < testServer.responses.size(); i++) {
String json = testServer.responses.get(i);
Map<String, Object> map = DataTypes.UNTYPED_OBJECT.implicitCast(json);
assertThat(map, hasKey("kernel"));
assertThat(map.get("kernel"), is(notNullValue()));
assertThat(map, hasKey("cluster_id"));
assertThat(map.get("cluster_id"), is(notNullValue()));
assertThat(map, hasKey("master"));
assertThat(map.get("master"), is(notNullValue()));
assertThat(map, hasKey("ping_count"));
assertThat(map.get("ping_count"), is(notNullValue()));
Map<String, Object> pingCountMap = DataTypes.UNTYPED_OBJECT.implicitCast(map.get("ping_count"));
assertThat(pingCountMap.get("success"), is(0));
assertThat(pingCountMap.get("failure"), is(i));
if (task.getHardwareAddress() != null) {
assertThat(map, hasKey("hardware_address"));
assertThat(map.get("hardware_address"), is(notNullValue()));
}
assertThat(map, hasKey("crate_version"));
assertThat(map.get("crate_version"), is(notNullValue()));
assertThat(map, hasKey("java_version"));
assertThat(map.get("java_version"), is(notNullValue()));
}
}
use of io.crate.http.HttpTestServer in project crate by crate.
the class PingTaskTest method testSuccessfulPingTaskRunWhenLicenseIsNotNull.
@Test
public void testSuccessfulPingTaskRunWhenLicenseIsNotNull() throws Exception {
testServer = new HttpTestServer(18080, false);
testServer.run();
PingTask task = createPingTask("http://localhost:18080/");
task.run();
assertThat(testServer.responses.size(), is(1));
task.run();
assertThat(testServer.responses.size(), is(2));
for (int i = 0; i < testServer.responses.size(); i++) {
String json = testServer.responses.get(i);
Map<String, Object> map = DataTypes.UNTYPED_OBJECT.implicitCast(json);
assertThat(map, hasKey("kernel"));
assertThat(map.get("kernel"), is(notNullValue()));
assertThat(map, hasKey("cluster_id"));
assertThat(map.get("cluster_id"), is(notNullValue()));
assertThat(map, hasKey("master"));
assertThat(map.get("master"), is(notNullValue()));
assertThat(map, hasKey("ping_count"));
assertThat(map.get("ping_count"), is(notNullValue()));
Map<String, Object> pingCountMap = DataTypes.UNTYPED_OBJECT.implicitCast(map.get("ping_count"));
assertThat(pingCountMap.get("success"), is(i));
assertThat(pingCountMap.get("failure"), is(0));
if (task.getHardwareAddress() != null) {
assertThat(map, hasKey("hardware_address"));
assertThat(map.get("hardware_address"), is(notNullValue()));
}
assertThat(map, hasKey("crate_version"));
assertThat(map.get("crate_version"), is(notNullValue()));
assertThat(map, hasKey("java_version"));
assertThat(map.get("java_version"), is(notNullValue()));
}
}
Aggregations