@Test public void get_returns_started_from_System2_now_at_constructor_time() { Properties properties = new Properties(); long now = setRequiredPropertiesAndMocks(properties); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); NodeHealth nodeHealth = underTest.get(); assertThat(nodeHealth.getDetails().getStartedAt()).isEqualTo(now); // change now when(clock.now()).thenReturn(now); NodeHealth newNodeHealth = underTest.get(); assertThat(newNodeHealth.getDetails().getStartedAt()).isEqualTo(now); }
@Test public void get_returns_status_GREEN_if_elasticsearch_process_is_operational_in_ClusterAppState() { Properties properties = new Properties(); setRequiredPropertiesAndMocks(properties); when(clusterAppState.isOperational(ProcessId.ELASTICSEARCH, true)).thenReturn(true); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); NodeHealth nodeHealth = underTest.get(); assertThat(nodeHealth.getStatus()).isEqualTo(NodeHealth.Status.GREEN); }
private void getReturnsHostFromNetworkUtils(@Nullable String hostPropertyValue) { String host = randomAlphanumeric(34); Properties properties = new Properties(); properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4))); if (hostPropertyValue != null) { properties.setProperty(CLUSTER_NODE_HOST.getKey(), hostPropertyValue); } when(clock.now()).thenReturn(1L + random.nextInt(87)); when(networkUtils.getHostname()).thenReturn(host); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); NodeHealth nodeHealth = underTest.get(); assertThat(nodeHealth.getDetails().getHost()).isEqualTo(host); // change now when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(96)); NodeHealth newNodeHealth = underTest.get(); assertThat(newNodeHealth.getDetails().getHost()).isEqualTo(host); }
@Test public void get_returns_host_from_property_if_set_at_constructor_time() { String host = randomAlphanumeric(55); Properties properties = new Properties(); properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4))); properties.setProperty(CLUSTER_NODE_HOST.getKey(), host); when(clock.now()).thenReturn(1L + random.nextInt(87)); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); NodeHealth nodeHealth = underTest.get(); assertThat(nodeHealth.getDetails().getHost()).isEqualTo(host); // change now properties.setProperty(CLUSTER_NODE_HOST.getKey(), randomAlphanumeric(96)); NodeHealth newNodeHealth = underTest.get(); assertThat(newNodeHealth.getDetails().getHost()).isEqualTo(host); }
@Test public void get_returns_name_and_port_from_properties_at_constructor_time() { String name = randomAlphanumeric(3); int port = 1 + random.nextInt(4); Properties properties = new Properties(); properties.setProperty(CLUSTER_NODE_NAME.getKey(), name); properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(port)); when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); when(clock.now()).thenReturn(1L + random.nextInt(87)); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); NodeHealth nodeHealth = underTest.get(); assertThat(nodeHealth.getDetails().getName()).isEqualTo(name); assertThat(nodeHealth.getDetails().getPort()).isEqualTo(port); // change values in properties properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(6)); properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(99))); NodeHealth newNodeHealth = underTest.get(); assertThat(newNodeHealth.getDetails().getName()).isEqualTo(name); assertThat(newNodeHealth.getDetails().getPort()).isEqualTo(port); }
@Test public void get_returns_status_RED_with_cause_if_elasticsearch_process_is_not_operational_in_ClusterAppState() { Properties properties = new Properties(); setRequiredPropertiesAndMocks(properties); when(clusterAppState.isOperational(ProcessId.ELASTICSEARCH, true)).thenReturn(false); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); NodeHealth nodeHealth = underTest.get(); assertThat(nodeHealth.getStatus()).isEqualTo(NodeHealth.Status.RED); assertThat(nodeHealth.getCauses()).containsOnly("Elasticsearch is not operational"); }