HADOOP-16222. Fix new deprecations after guava 27.0 update in trunk. Contributed by Gabor Bota.

This commit is contained in:
Sean Mackrory 2019-04-24 10:39:00 -06:00
parent e1c5ddf2aa
commit a703dae25e
11 changed files with 29 additions and 23 deletions

View File

@ -58,7 +58,7 @@ public ArrayWritable(Class<? extends Writable> 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]);
}

View File

@ -107,7 +107,7 @@ public <T> ListenableFuture<T> submit(Callable<T> 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 <T> ListenableFuture<T> 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));
}

View File

@ -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();
}
/**

View File

@ -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());
}

View File

@ -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();

View File

@ -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());

View File

@ -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()));

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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(),

View File

@ -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);