From a703dae25e3c75a4e6086efd4b620ef956e6fe54 Mon Sep 17 00:00:00 2001 From: Sean Mackrory Date: Wed, 24 Apr 2019 10:39:00 -0600 Subject: [PATCH] HADOOP-16222. Fix new deprecations after guava 27.0 update in trunk. Contributed by Gabor Bota. --- .../java/org/apache/hadoop/io/ArrayWritable.java | 2 +- .../util/SemaphoredDelegatingExecutor.java | 6 +++--- .../main/java/org/apache/hadoop/util/ZKUtil.java | 2 +- .../org/apache/hadoop/io/TestArrayWritable.java | 2 +- .../org/apache/hadoop/net/TestTableMapping.java | 16 ++++++++-------- .../apache/hadoop/security/TestSecurityUtil.java | 3 ++- .../java/org/apache/hadoop/util/TestZKUtil.java | 2 +- .../hdfs/tools/TestDFSHAAdminMiniCluster.java | 6 +++--- .../hadoop/yarn/service/ServiceTestUtils.java | 3 ++- .../resources/fpga/TestFpgaResourceHandler.java | 7 +++++-- .../applicationsmanager/TestAMRestart.java | 3 ++- 11 files changed, 29 insertions(+), 23 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayWritable.java index 122aa5ca1e..44b6aaa7af 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayWritable.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayWritable.java @@ -58,7 +58,7 @@ public ArrayWritable(Class valueClass, Writable[] values) { } public ArrayWritable(String[] strings) { - this(UTF8.class, new Writable[strings.length]); + this(Text.class, new Writable[strings.length]); for (int i = 0; i < strings.length; i++) { values[i] = new UTF8(strings[i]); } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SemaphoredDelegatingExecutor.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SemaphoredDelegatingExecutor.java index 22ba52af3a..4ec77e75ba 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SemaphoredDelegatingExecutor.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/SemaphoredDelegatingExecutor.java @@ -107,7 +107,7 @@ public ListenableFuture submit(Callable task) { queueingPermits.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - return Futures.immediateFailedCheckedFuture(e); + return Futures.immediateFailedFuture(e); } return super.submit(new CallableWithPermitRelease<>(task)); } @@ -118,7 +118,7 @@ public ListenableFuture submit(Runnable task, T result) { queueingPermits.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - return Futures.immediateFailedCheckedFuture(e); + return Futures.immediateFailedFuture(e); } return super.submit(new RunnableWithPermitRelease(task), result); } @@ -129,7 +129,7 @@ public ListenableFuture submit(Runnable task) { queueingPermits.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - return Futures.immediateFailedCheckedFuture(e); + return Futures.immediateFailedFuture(e); } return super.submit(new RunnableWithPermitRelease(task)); } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java index fe64adb74e..48cef5f06f 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java @@ -172,7 +172,7 @@ public static String resolveConfIndirection(String valInConf) return valInConf; } String path = valInConf.substring(1).trim(); - return Files.toString(new File(path), Charsets.UTF_8).trim(); + return Files.asCharSource(new File(path), Charsets.UTF_8).read().trim(); } /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestArrayWritable.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestArrayWritable.java index a75a7bb6fb..ac8ad2e725 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestArrayWritable.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestArrayWritable.java @@ -106,7 +106,7 @@ public void testArrayWritableStringConstructor() { String[] original = { "test1", "test2", "test3" }; ArrayWritable arrayWritable = new ArrayWritable(original); assertEquals("testArrayWritableStringConstructor class error!!!", - UTF8.class, arrayWritable.getValueClass()); + Text.class, arrayWritable.getValueClass()); assertArrayEquals("testArrayWritableStringConstructor toString error!!!", original, arrayWritable.toStrings()); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java index a93f9ea5e4..4b8b02f017 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestTableMapping.java @@ -41,8 +41,8 @@ public class TestTableMapping { public void testResolve() throws IOException { File mapFile = File.createTempFile(getClass().getSimpleName() + ".testResolve", ".txt"); - Files.write(hostName1 + " /rack1\n" + - hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8); + Files.asCharSink(mapFile, Charsets.UTF_8).write( + hostName1 + " /rack1\n" + hostName2 + "\t/rack2\n"); mapFile.deleteOnExit(); TableMapping mapping = new TableMapping(); @@ -64,8 +64,8 @@ public void testResolve() throws IOException { public void testTableCaching() throws IOException { File mapFile = File.createTempFile(getClass().getSimpleName() + ".testTableCaching", ".txt"); - Files.write(hostName1 + " /rack1\n" + - hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8); + Files.asCharSink(mapFile, Charsets.UTF_8).write( + hostName1 + " /rack1\n" + hostName2 + "\t/rack2\n"); mapFile.deleteOnExit(); TableMapping mapping = new TableMapping(); @@ -128,8 +128,8 @@ public void testFileDoesNotExist() { public void testClearingCachedMappings() throws IOException { File mapFile = File.createTempFile(getClass().getSimpleName() + ".testClearingCachedMappings", ".txt"); - Files.write(hostName1 + " /rack1\n" + - hostName2 + "\t/rack2\n", mapFile, Charsets.UTF_8); + Files.asCharSink(mapFile, Charsets.UTF_8).write( + hostName1 + " /rack1\n" + hostName2 + "\t/rack2\n"); mapFile.deleteOnExit(); TableMapping mapping = new TableMapping(); @@ -147,7 +147,7 @@ public void testClearingCachedMappings() throws IOException { assertEquals("/rack1", result.get(0)); assertEquals("/rack2", result.get(1)); - Files.write("", mapFile, Charsets.UTF_8); + Files.asCharSink(mapFile, Charsets.UTF_8).write(""); mapping.reloadCachedMappings(); @@ -166,7 +166,7 @@ public void testClearingCachedMappings() throws IOException { public void testBadFile() throws IOException { File mapFile = File.createTempFile(getClass().getSimpleName() + ".testBadFile", ".txt"); - Files.write("bad contents", mapFile, Charsets.UTF_8); + Files.asCharSink(mapFile, Charsets.UTF_8).write("bad contents"); mapFile.deleteOnExit(); TableMapping mapping = new TableMapping(); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSecurityUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSecurityUtil.java index f7a7f8b2dd..016c589ae3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSecurityUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSecurityUtil.java @@ -434,7 +434,8 @@ public void testAuthPlainTextFile() throws Exception { Configuration conf = new Configuration(); File passwordTxtFile = File.createTempFile( getClass().getSimpleName() + ".testAuthAtPathNotation-", ".txt"); - Files.write(ZK_AUTH_VALUE, passwordTxtFile, StandardCharsets.UTF_8); + Files.asCharSink(passwordTxtFile, StandardCharsets.UTF_8) + .write(ZK_AUTH_VALUE); try { conf.set(CommonConfigurationKeys.ZK_AUTH, "@" + passwordTxtFile.getAbsolutePath()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java index 0e39ca94de..3d985e40fb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java @@ -131,7 +131,7 @@ public void testConfIndirection() throws IOException { assertEquals("x", ZKUtil.resolveConfIndirection("x")); TEST_FILE.getParentFile().mkdirs(); - Files.write("hello world", TEST_FILE, Charsets.UTF_8); + Files.asCharSink(TEST_FILE, Charsets.UTF_8).write("hello world"); assertEquals("hello world", ZKUtil.resolveConfIndirection( "@" + TEST_FILE.getAbsolutePath())); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java index 2bb82f6b26..fc569d0aa7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java @@ -208,7 +208,7 @@ public void testFencer() throws Exception { assertEquals(0, runTool("-ns", "minidfs-ns", "-failover", "nn2", "nn1")); // Fencer has not run yet, since none of the above required fencing - assertEquals("", Files.toString(tmpFile, Charsets.UTF_8)); + assertEquals("", Files.asCharSource(tmpFile, Charsets.UTF_8).read()); // Test failover with fencer and forcefence option assertEquals(0, runTool("-failover", "nn1", "nn2", "--forcefence")); @@ -216,8 +216,8 @@ public void testFencer() throws Exception { // The fence script should run with the configuration from the target // node, rather than the configuration from the fencing node. Strip // out any trailing spaces and CR/LFs which may be present on Windows. - String fenceCommandOutput =Files.toString(tmpFile, Charsets.UTF_8). - replaceAll(" *[\r\n]+", ""); + String fenceCommandOutput = Files.asCharSource(tmpFile, Charsets.UTF_8) + .read().replaceAll(" *[\r\n]+", ""); assertEquals("minidfs-ns.nn1 " + nn1Port + " nn1", fenceCommandOutput); tmpFile.delete(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java index 5a522b47c3..fd2b00a482 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java @@ -410,7 +410,8 @@ protected void starting(Description description) { fs = new SliderFileSystem(conf); fs.setAppDir(new Path(serviceBasePath.toString())); } catch (IOException e) { - Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java index 0b7c3566a5..809b307896 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/fpga/TestFpgaResourceHandler.java @@ -74,6 +74,7 @@ import org.junit.rules.ExpectedException; import com.google.common.io.Files; +import com.google.common.io.FileWriteMode; public class TestFpgaResourceHandler { @Rule @@ -133,7 +134,8 @@ public void setup() throws IOException, YarnException { dummyAocx = new File(aocxPath); Files.createParentDirs(dummyAocx); Files.touch(dummyAocx); - Files.append(HASHABLE_STRING, dummyAocx, StandardCharsets.UTF_8); + Files.asCharSink(dummyAocx, StandardCharsets.UTF_8, FileWriteMode.APPEND) + .write(HASHABLE_STRING); } @After @@ -358,7 +360,8 @@ public void testsAllocationWithExistingIPIDDevices() // Case 2. id-2 container request preStart, with 1 plugin.configureIP called // Add some characters to the dummy file to have its hash changed - Files.append("12345", dummyAocx, StandardCharsets.UTF_8); + Files.asCharSink(dummyAocx, StandardCharsets.UTF_8, FileWriteMode.APPEND) + .write("12345"); fpgaResourceHandler.preStart(mockContainer(1, 1, "GZIP")); // we should have 4 times invocation verify(mockVendorPlugin, times(4)).configureIP(anyString(), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java index 0083f40a86..4f2fb1ac06 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java @@ -1172,7 +1172,8 @@ public void testContainersFromPreviousAttemptsWithRMRestart() return true; } } catch (Exception e) { - Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } return false; }, 2000, 200000);