Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add batch metrics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardolstephen committed Aug 13, 2020
1 parent 22bf9c7 commit 9686ab8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setup() {

@Test
public void disabledClusterStateTest() {
setControllerValues(DISABLED_STATE, DISABLED_STATE, DISABLED_STATE);
setControllerValues(DISABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE);
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
Expand All @@ -50,25 +50,27 @@ public void disabledClusterStateTest() {

@Test
public void enabledClusterStateTest() {
setControllerValues(ENABLED_STATE, ENABLED_STATE, ENABLED_STATE);
setControllerValues(ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE);
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
assertEquals(7, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(15, clusterSettingHandler.getCurrentClusterSettingValue());
}

@Test
public void paDisabledClusterStateTest() {
setControllerValues(DISABLED_STATE, ENABLED_STATE, ENABLED_STATE);
setControllerValues(DISABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE);
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue());
}

private void setControllerValues(final Boolean paEnabled, final Boolean rcaEnabled, final Boolean loggingEnabled) {
private void setControllerValues(final Boolean paEnabled, final Boolean rcaEnabled, final Boolean loggingEnabled,
final Boolean batchMetricsEnabled) {
when(mockPerformanceAnalyzerController.isPerformanceAnalyzerEnabled()).thenReturn(paEnabled);
when(mockPerformanceAnalyzerController.isRcaEnabled()).thenReturn(rcaEnabled);
when(mockPerformanceAnalyzerController.isLoggingEnabled()).thenReturn(loggingEnabled);
when(mockPerformanceAnalyzerController.isBatchMetricsEnabled()).thenReturn(batchMetricsEnabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ private void assertAgentUriWithRcaRedirection(final String protocolScheme) throw
}


private void assertAgentUriWithBatchRedirection(final String protocolScheme) throws IOException {
initPerformanceAnalyzerResourceProvider(protocolScheme.equals("https://"));

String requestUri = protocolScheme + "localhost:9200/_opendistro/_performanceanalyzer/_agent/batch" +
"?metrics=CPU_Utilization,IO_TotThroughput&starttime=1594412650000&endtime=1594412665000&samplingperiod=5";
String expectedResponseUri = protocolScheme + "localhost:9650/_opendistro/_performanceanalyzer/batch" +
"?metrics=CPU_Utilization,IO_TotThroughput&starttime=1594412650000&endtime=1594412665000&samplingperiod=5";

RestRequest restRequest = generateRestRequest(requestUri, "batch");
URL actualResponseURI = performanceAnalyzerRp.getAgentUri(restRequest);
assertEquals(new URL(expectedResponseUri), actualResponseURI);
}


@Test
public void testGetAgentUri_WithHttp_WithMetricRedirection() throws Exception {
assertAgentUriWithMetricsRedirection("http://");
Expand All @@ -140,6 +154,16 @@ public void testGetAgentUri_WithHttps_WithRcaRedirection() throws Exception {
assertAgentUriWithRcaRedirection("https://");
}

@Test
public void testGetAgentUri_WithHttp_WithBatchRedirection() throws Exception {
assertAgentUriWithBatchRedirection("http://");
}

@Test
public void testGetAgentUri_WithHttps_WithBatchRedirection() throws Exception {
assertAgentUriWithBatchRedirection("https://");
}

@Test
public void testGetAgentUri_WithHttp_WithUnsupportedRedirection() throws Exception {
String requestUri = "http://localhost:9200/_opendistro/_performanceanalyzer/_agent/invalid";
Expand Down

0 comments on commit 9686ab8

Please sign in to comment.