diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/config/PerformanceAnalyzerClusterSettingHandlerTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/config/PerformanceAnalyzerClusterSettingHandlerTest.java index 7a1ee31e..71d32e84 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/config/PerformanceAnalyzerClusterSettingHandlerTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/config/PerformanceAnalyzerClusterSettingHandlerTest.java @@ -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); @@ -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); } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/http_action/config/PerformanceAnalyzerResourceProviderTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/http_action/config/PerformanceAnalyzerResourceProviderTest.java index 8cbe85af..a85f4681 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/http_action/config/PerformanceAnalyzerResourceProviderTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/http_action/config/PerformanceAnalyzerResourceProviderTest.java @@ -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://"); @@ -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";