From 0f90bf4fbb6a868684460638b33bf29de458f6f2 Mon Sep 17 00:00:00 2001 From: "Ricardo L. Stephen" <43506361+ricardolstephen@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:52:55 -0700 Subject: [PATCH] Add batch metrics tests --- ...anceAnalyzerClusterSettingHandlerTest.java | 12 ++++++---- ...rformanceAnalyzerResourceProviderTest.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) 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 d8e39ee4..87a31f11 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";