From 9a2624cfc83ea5a3ed1d4de048029a836b162658 Mon Sep 17 00:00:00 2001 From: Vigya Sharma Date: Fri, 11 Sep 2020 14:00:45 -0700 Subject: [PATCH] Changes for java 8 compatibility (#424) * Changes for java 8 target compatibility * Use different substring fn --- .../performanceanalyzer/metricsdb/MetricsDB.java | 2 +- .../rca/persistence/SQLitePersistor.java | 2 +- .../performanceanalyzer/metricsdb/MetricsDBTests.java | 10 ++++++---- .../performanceanalyzer/rca/RcaControllerTest.java | 2 +- .../reader/ReaderMetricsProcessorTests.java | 9 +++++---- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDB.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDB.java index f1952dbeb..c85f2be3b 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDB.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDB.java @@ -348,7 +348,7 @@ public static Set listOnDiskFiles() { .map(path -> path.toString()) .forEach(s -> { try { - found.add(Long.parseUnsignedLong(s, prefixLength, s.length(), 10)); + found.add(Long.parseUnsignedLong(s.substring(prefixLength), 10)); } catch (IndexOutOfBoundsException | NumberFormatException e) { LOG.error("Unexpected file in metricsdb directory - {}", s); } diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/SQLitePersistor.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/SQLitePersistor.java index 9f026c27a..7fa6f294c 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/SQLitePersistor.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/persistence/SQLitePersistor.java @@ -280,7 +280,7 @@ synchronized int insertRow(String tableName, List row) throws SQLExcepti String nestedTableName = columnName.replace(NESTED_OBJECT_COLUMN_PREFIX, ""); if (jooqField.getType() == String.class) { String value = (String) jooqField.getValue(record); - JsonArray array = JsonParser.parseString(value).getAsJsonArray(); + JsonArray array = new JsonParser().parse(value).getAsJsonArray(); Method setter = fieldNameToGetterSetterMap.get(nestedTableName).setter; List collection = new ArrayList<>(); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDBTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDBTests.java index 52e2af9b9..dd0e170c5 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDBTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metricsdb/MetricsDBTests.java @@ -20,10 +20,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import com.google.common.collect.ImmutableSet; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -455,13 +457,13 @@ public void testDeleteOnDiskFile_notExists() throws Exception { @Test public void testListOnDiskFiles_empty() throws Exception { deleteAll(); - assertEquals(Set.of(), MetricsDB.listOnDiskFiles()); + assertEquals(Collections.EMPTY_SET, MetricsDB.listOnDiskFiles()); } @Test public void testListOnDiskFiles_one() throws Exception { deleteAll(); - Set expected = Set.of(1000000000L); + Set expected = ImmutableSet.of(1000000000L); for (Long ts : expected) { (new MetricsDB(ts)).remove(); } @@ -471,7 +473,7 @@ public void testListOnDiskFiles_one() throws Exception { @Test public void testListOnDiskFiles_two() throws Exception { deleteAll(); - Set expected = Set.of(1000000000L, 500L); + Set expected = ImmutableSet.of(1000000000L, 500L); for (Long ts : expected) { (new MetricsDB(ts)).remove(); } @@ -481,7 +483,7 @@ public void testListOnDiskFiles_two() throws Exception { @Test public void testListOnDiskFiles_many() throws Exception { deleteAll(); - Set expected = Set.of(1000000000L, 500L, 0L); + Set expected = ImmutableSet.of(1000000000L, 500L, 0L); for (Long ts : expected) { (new MetricsDB(ts)).remove(); } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java index 22515ba66..f7b85f85d 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rca/RcaControllerTest.java @@ -190,7 +190,7 @@ public void readRcaEnabledFromConf() throws IOException { @Test public void readAndUpdateMutedRcasBeforeGraphCreation() throws Exception { Method readAndUpdateMutesRcas = rcaController.getClass() - .getDeclaredMethod("readAndUpdateMutedComponents", null); + .getDeclaredMethod("readAndUpdateMutedComponents"); readAndUpdateMutesRcas.setAccessible(true); String rcaConfPath = Paths.get(RcaConsts.TEST_CONFIG_PATH, "rca_muted.conf").toString(); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java index c30bb9633..778ddf2c3 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/reader/ReaderMetricsProcessorTests.java @@ -29,6 +29,7 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.PerformanceAnalyzerMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; +import com.google.common.collect.ImmutableSet; import java.io.File; import java.io.FilenameFilter; import java.nio.file.Files; @@ -584,26 +585,26 @@ public void testCleanupMetricsDBFiles_empty() throws Exception { deleteAll(); PluginSettings.instance().setShouldCleanupMetricsDBFiles(true); ReaderMetricsProcessor mp = new ReaderMetricsProcessor(rootLocation, true, new AppContext()); - assertEquals(Set.of(), MetricsDB.listOnDiskFiles()); + assertEquals(ImmutableSet.of(), MetricsDB.listOnDiskFiles()); } @Test public void testCleanupMetricsDBFiles_enabled() throws Exception { deleteAll(); - Set expected = Set.of(1000000000L, 500L, 0L); + Set expected = ImmutableSet.of(1000000000L, 500L, 0L); for (Long ts : expected) { (new MetricsDB(ts)).remove(); } assertEquals(expected, MetricsDB.listOnDiskFiles()); PluginSettings.instance().setShouldCleanupMetricsDBFiles(true); ReaderMetricsProcessor mp = new ReaderMetricsProcessor(rootLocation, true, new AppContext()); - assertEquals(Set.of(), MetricsDB.listOnDiskFiles()); + assertEquals(ImmutableSet.of(), MetricsDB.listOnDiskFiles()); } @Test public void testCleanupMetricsDBFiles_disabled() throws Exception { deleteAll(); - Set expected = Set.of(1000000000L, 500L, 0L); + Set expected = ImmutableSet.of(1000000000L, 500L, 0L); for (Long ts : expected) { (new MetricsDB(ts)).remove(); }