Migrate to Flogger (green)

This is a 'green' Flogger migration CL. Green CLs are intended to be as
safe as possible and should be easy to review and submit.

No changes should be necessary to the code itself prior to submission,
but small changes to BUILD files may be required.

Changes within files are completely independent of each other, so this CL
can be safely split up for review using tools such as Rosie.

For more information, see []
Base CL: 197826149

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198560170
This commit is contained in:
jianglai 2018-05-30 07:58:51 -07:00
parent 0d2fb3a8f0
commit 70b13596e4
178 changed files with 984 additions and 988 deletions

View file

@ -125,6 +125,7 @@ public class UpdateSnapshotViewActionTest {
.thenThrow(new IOException("I'm sorry Dave, I can't let you do that"));
InternalServerErrorException thrown =
assertThrows(InternalServerErrorException.class, action::run);
assertThat(thrown).hasMessageThat().contains("Error in update snapshot view action");
assertThat(thrown).hasMessageThat().contains("Could not update snapshot view for table");
assertThat(thrown).hasCauseThat().hasMessageThat().contains("I'm sorry Dave");
}
}

View file

@ -133,7 +133,7 @@ public class FlowRunnerTest extends ShardableTestCase {
"StatelessRequestSessionMetadata"
+ "{clientId=TheRegistrar, failedLoginAttempts=0, serviceExtensionUris=}",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>",
"", // Extra newline at the end of the XML.
"", // Extra newline at the end of the XML.
"PasswordOnlyTransportCredentials{}",
"UNIT_TEST",
"LIVE",

View file

@ -18,7 +18,6 @@ java_library(
resources = [
] + glob(["**/testdata/*"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/dns/writer",
"//java/google/registry/flows",
@ -31,6 +30,8 @@ java_library(
"@com_google_appengine_api_1_0_sdk//:testonly",
"@com_google_appengine_testing",
"@com_google_code_findbugs_jsr305",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_guava_testlib",
"@com_google_monitoring_client_contrib",

View file

@ -12,7 +12,6 @@ java_library(
srcs = glob(["*.java"]),
resources = glob(["testdata/*"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/gcs",
"//java/google/registry/keyring/api",
@ -35,6 +34,8 @@ java_library(
"@com_google_appengine_tools_appengine_gcs_client",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_truth",
"@com_google_truth_extensions_truth_java8_extension",

View file

@ -22,8 +22,8 @@ import static org.bouncycastle.bcpg.HashAlgorithmTags.SHA256;
import static org.bouncycastle.bcpg.PublicKeyAlgorithmTags.RSA_GENERAL;
import static org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags.AES_128;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.CharStreams;
import com.google.common.logging.FormattingLogger;
import google.registry.testing.BouncyCastleProviderRule;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -120,7 +120,7 @@ public class BouncyCastleTest {
+ "Be poet's or fanatic's will be known\n"
+ "When this warm scribe my hand is in the grave.\n";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@ -136,7 +136,7 @@ public class BouncyCastleTest {
}
data = output.toByteArray();
}
logger.infofmt("Compressed data: %s", dumpHex(data));
logger.atInfo().log("Compressed data: %s", dumpHex(data));
// Decompress the data.
try (ByteArrayInputStream input = new ByteArrayInputStream(data)) {
@ -167,7 +167,7 @@ public class BouncyCastleTest {
ByteArrayOutputStream output = new ByteArrayOutputStream();
signer.generate().encode(output);
byte[] signatureFileData = output.toByteArray();
logger.infofmt(".sig file data: %s", dumpHex(signatureFileData));
logger.atInfo().log(".sig file data: %s", dumpHex(signatureFileData));
// Load algorithm information and signature data from "signatureFileData".
PGPSignature sig;
@ -207,7 +207,7 @@ public class BouncyCastleTest {
signer.update(FALL_OF_HYPERION_A_DREAM.getBytes(UTF_8));
signer.generate().encode(output);
byte[] signatureFileData = output.toByteArray();
logger.infofmt(".sig file data: %s", dumpHex(signatureFileData));
logger.atInfo().log(".sig file data: %s", dumpHex(signatureFileData));
// Load algorithm information and signature data from "signatureFileData".
PGPSignature sig;
@ -252,7 +252,7 @@ public class BouncyCastleTest {
}
encryptedData = output.toByteArray();
}
logger.infofmt("Encrypted data: %s", dumpHex(encryptedData));
logger.atInfo().log("Encrypted data: %s", dumpHex(encryptedData));
// Bob loads his "privateKey" into memory.
PGPSecretKeyRing privateKeyRing = new BcPGPSecretKeyRing(PRIVATE_KEY);
@ -296,7 +296,7 @@ public class BouncyCastleTest {
}
encryptedData = output.toByteArray();
}
logger.infofmt("Encrypted data: %s", dumpHex(encryptedData));
logger.atInfo().log("Encrypted data: %s", dumpHex(encryptedData));
// Bob loads his chain of private keys into memory.
PGPSecretKeyRingCollection privateKeyRings = new BcPGPSecretKeyRingCollection(
@ -344,7 +344,7 @@ public class BouncyCastleTest {
}
encryptedData = output.toByteArray();
}
logger.infofmt("Encrypted data: %s", dumpHex(encryptedData));
logger.atInfo().log("Encrypted data: %s", dumpHex(encryptedData));
// Bob loads his chain of private keys into memory.
PGPSecretKeyRingCollection privateKeyRings = new BcPGPSecretKeyRingCollection(

View file

@ -21,8 +21,8 @@ import static google.registry.testing.SystemInfo.hasCommand;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assume.assumeTrue;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.CharStreams;
import com.google.common.logging.FormattingLogger;
import google.registry.keyring.api.Keyring;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.FakeKeyringModule;
@ -50,7 +50,7 @@ import org.junit.runner.RunWith;
@SuppressWarnings("resource")
public class RydeGpgIntegrationTest extends ShardableTestCase {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@ -145,7 +145,7 @@ public class RydeGpgIntegrationTest extends ShardableTestCase {
// mode b (62), created 1287273600, name="lol_2010-10-17_full_S1_R0.tar",
// raw data: 10752 bytes
// gpg: WARNING: message was not integrity protected
logger.info("Running GPG to list info about OpenPGP message...");
logger.atInfo().log("Running GPG to list info about OpenPGP message...");
{
Process pid =
gpg.exec(
@ -192,7 +192,7 @@ public class RydeGpgIntegrationTest extends ShardableTestCase {
// jart@jart:/tmp$ gpg --verify /tmp/deposit.sig /tmp/deposit.ryde
// gpg: Signature made Mon 26 Aug 2013 12:04:27 PM EDT using RSA-S key ID 2774D88E
// gpg: Good signature from <rde-unittest@registry.test>
logger.info("Running GPG to verify signature...");
logger.atInfo().log("Running GPG to verify signature...");
{
Process pid = gpg.exec(cmd.get(), "--verify", sigFile.toString(), rydeFile.toString());
String stderr = slurp(pid.getErrorStream());
@ -210,7 +210,7 @@ public class RydeGpgIntegrationTest extends ShardableTestCase {
// gpg: AES encrypted data
// gpg: original file name='lol_2010-10-17_full_S1_R0.tar'
// gpg: WARNING: message was not integrity protected
logger.info("Running GPG to extract tar...");
logger.atInfo().log("Running GPG to extract tar...");
{
Process pid =
gpg.exec(cmd.get(), "--use-embedded-filename", "--ignore-mdc-error", rydeFile.toString());
@ -222,7 +222,7 @@ public class RydeGpgIntegrationTest extends ShardableTestCase {
.isTrue();
// ...and finally, Iron Mountain extracts the tar file to get a happy XML file ^__^
logger.info("Running GNU tar to extract content...");
logger.atInfo().log("Running GNU tar to extract content...");
{
Process pid = gpg.exec("tar", "-xf", tarFile.toString());
String stderr = slurp(pid.getErrorStream());

View file

@ -145,7 +145,11 @@ public class BillingEmailUtilsTest {
);
RuntimeException thrown =
assertThrows(RuntimeException.class, () -> emailUtils.emailOverallInvoice());
assertThat(thrown).hasMessageThat().isEqualTo("javax.mail.MessagingException: expected");
assertThat(thrown).hasMessageThat().isEqualTo("Emailing invoice failed");
assertThat(thrown)
.hasCauseThat()
.hasMessageThat()
.isEqualTo("javax.mail.MessagingException: expected");
// Verify we sent an e-mail alert
verify(emailService).sendMessage(msgCaptor.capture());
validateAlertMessage(msgCaptor.getValue(), "Emailing invoice failed due to expected");

View file

@ -133,9 +133,10 @@ public class IcannReportingStagingActionTest {
createAction(ImmutableList.of(ReportType.ACTIVITY));
when(stager.stageReports(ReportType.ACTIVITY))
.thenThrow(new BigqueryJobFailureException("Expected failure", null, null, null));
BigqueryJobFailureException thrown =
assertThrows(BigqueryJobFailureException.class, action::run);
assertThat(thrown).hasMessageThat().isEqualTo("Expected failure");
RuntimeException thrown = assertThrows(RuntimeException.class, action::run);
assertThat(thrown).hasCauseThat().isInstanceOf(BigqueryJobFailureException.class);
assertThat(thrown).hasMessageThat().isEqualTo("Staging action failed.");
assertThat(thrown).hasCauseThat().hasMessageThat().isEqualTo("Expected failure");
verify(stager, times(3)).stageReports(ReportType.ACTIVITY);
verify(emailUtils)
.emailResults(

View file

@ -17,11 +17,12 @@ java_library(
],
visibility = ["//visibility:public"],
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/util",
"@com_google_appengine_tools_sdk",
"@com_google_auto_value",
"@com_google_code_findbugs_jsr305",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@javax_servlet_api",
"@org_mortbay_jetty",

View file

@ -20,7 +20,7 @@ import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import com.google.common.collect.ImmutableMap;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.MediaType;
import com.google.common.primitives.Ints;
import java.io.IOException;
@ -44,7 +44,7 @@ import org.mortbay.jetty.servlet.ServletHolder;
*/
public final class StaticResourceServlet extends HttpServlet {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final MediaType DEFAULT_MIME_TYPE = MediaType.OCTET_STREAM;
@ -122,12 +122,12 @@ public final class StaticResourceServlet extends HttpServlet {
verify(req.getRequestURI().startsWith(prefix));
Path file = root.resolve(req.getRequestURI().substring(prefix.length()));
if (!Files.exists(file)) {
logger.infofmt("Not found: %s (%s)", req.getRequestURI(), file);
logger.atInfo().log("Not found: %s (%s)", req.getRequestURI(), file);
rsp.sendError(SC_NOT_FOUND, "Not found");
return Optional.empty();
}
if (Files.isDirectory(file)) {
logger.infofmt("Directory listing forbidden: %s (%s)", req.getRequestURI(), file);
logger.atInfo().log("Directory listing forbidden: %s (%s)", req.getRequestURI(), file);
rsp.sendError(SC_FORBIDDEN, "No directory listing");
return Optional.empty();
}

View file

@ -21,7 +21,6 @@ java_library(
] + glob(["*.csv"]) + glob(["testdata/*"]),
exports = ["//third_party/junit"],
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/dns",
"//java/google/registry/dns:constants",
@ -45,6 +44,8 @@ java_library(
"@com_google_auto_value",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_guava_testlib",
"@com_google_truth",

View file

@ -14,7 +14,7 @@
package google.registry.testing;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@ -29,19 +29,19 @@ import org.junit.rules.TestName;
*/
public abstract class ShardableTestCase {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Rule
public final TestName testName = new TestName();
@Before
public void beforeShardable() {
logger.infofmt("Starting test %s", testName.getMethodName());
logger.atInfo().log("Starting test %s", testName.getMethodName());
}
@After
public void afterShardable() {
logger.infofmt("Finishing test %s", testName.getMethodName());
logger.atInfo().log("Finishing test %s", testName.getMethodName());
}
@Test

View file

@ -17,7 +17,7 @@ package google.registry.testing;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import javax.annotation.concurrent.ThreadSafe;
@ -26,22 +26,25 @@ import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
public final class SystemInfo {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final LoadingCache<String, Boolean> hasCommandCache = CacheBuilder.newBuilder()
.build(new CacheLoader<String, Boolean>() {
@Override
public Boolean load(String cmd) throws InterruptedException {
try {
Process pid = Runtime.getRuntime().exec(cmd);
pid.getOutputStream().close();
pid.waitFor();
} catch (IOException e) {
logger.warningfmt(e, "%s command not available", cmd);
return false;
}
return true;
}});
private static final LoadingCache<String, Boolean> hasCommandCache =
CacheBuilder.newBuilder()
.build(
new CacheLoader<String, Boolean>() {
@Override
public Boolean load(String cmd) throws InterruptedException {
try {
Process pid = Runtime.getRuntime().exec(cmd);
pid.getOutputStream().close();
pid.waitFor();
} catch (IOException e) {
logger.atWarning().withCause(e).log("%s command not available", cmd);
return false;
}
return true;
}
});
/**
* Returns {@code true} if system command can be run from path.

View file

@ -11,7 +11,6 @@ java_library(
name = "mapreduce",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/mapreduce",
"//java/google/registry/model",
@ -22,6 +21,8 @@ java_library(
"@com_google_appengine_tools_appengine_mapreduce",
"@com_google_appengine_tools_appengine_pipeline",
"@com_google_code_findbugs_jsr305",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_truth",
"@com_google_truth_extensions_truth_java8_extension",

View file

@ -33,7 +33,7 @@ import com.google.appengine.tools.pipeline.impl.servlets.PipelineServlet;
import com.google.appengine.tools.pipeline.impl.servlets.TaskHandler;
import com.google.apphosting.api.ApiProxy;
import com.google.common.base.CharMatcher;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.mapreduce.MapreduceRunner;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
@ -64,7 +64,7 @@ import org.junit.Rule;
*/
public abstract class MapreduceTestCase<T> extends ShardableTestCase {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
protected T action;
@ -97,8 +97,8 @@ public abstract class MapreduceTestCase<T> extends ShardableTestCase {
protected void executeTask(String queueName, QueueStateInfo.TaskStateInfo taskStateInfo)
throws Exception {
logger.finefmt("Executing task %s with URL %s",
taskStateInfo.getTaskName(), taskStateInfo.getUrl());
logger.atFine().log(
"Executing task %s with URL %s", taskStateInfo.getTaskName(), taskStateInfo.getUrl());
// Hack to allow for deferred tasks. Exploits knowing how they work.
if (taskStateInfo.getUrl().endsWith("__deferred__")) {
ObjectInputStream oin =
@ -130,7 +130,7 @@ public abstract class MapreduceTestCase<T> extends ShardableTestCase {
for (HeaderWrapper header : taskStateInfo.getHeaders()) {
int value = parseAsQuotedInt(header.getValue());
when(request.getIntHeader(header.getKey())).thenReturn(value);
logger.finefmt("header: %s=%s", header.getKey(), header.getValue());
logger.atFine().log("header: %s=%s", header.getKey(), header.getValue());
when(request.getHeader(header.getKey())).thenReturn(header.getValue());
}

View file

@ -9,9 +9,10 @@ java_library(
name = "sftp",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/util",
"@com_google_code_findbugs_jsr305",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@junit",
"@org_apache_ftpserver_core",

View file

@ -16,7 +16,7 @@ package google.registry.testing.sftp;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
@ -47,7 +47,7 @@ import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
/** In-process SFTP server using Apache SSHD. */
public class TestSftpServer implements FtpServer {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static SingletonRandomFactory secureRandomFactory;
@ -93,10 +93,10 @@ public class TestSftpServer implements FtpServer {
try (PEMParser pemParser = new PEMParser(new StringReader(key))) {
PEMKeyPair pemPair = (PEMKeyPair) pemParser.readObject();
KeyPair result = new JcaPEMKeyConverter().setProvider("BC").getKeyPair(pemPair);
logger.infofmt("Read key pair %s", result);
logger.atInfo().log("Read key pair %s", result);
return result;
} catch (IOException e) {
logger.severe(e, "Couldn't read key pair from string.");
logger.atSevere().withCause(e).log("Couldn't read key pair from string.");
return null;
}
}
@ -185,18 +185,18 @@ public class TestSftpServer implements FtpServer {
@Override
public synchronized void stop() {
try {
logger.info("Stopping server");
logger.atInfo().log("Stopping server");
server.stop(true);
stopped = true;
} catch (IOException e) {
logger.warning(e, "Error shutting down server");
logger.atWarning().withCause(e).log("Error shutting down server");
}
}
@Override
public synchronized void start() throws FtpException {
try {
logger.info("Starting server");
logger.atInfo().log("Starting server");
server.start();
stopped = false;
} catch (IOException e) {