From 8de6cde7ea0ff5aaf43d59e4dff13484f83b7cf8 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 30 Sep 2016 23:10:28 +0200 Subject: [PATCH] SONAR-8148 do not log data and decrease log level to debug --- .../sonar/db/version/v51/FeedFileSourcesBinaryData.java | 5 +++-- .../db/version/v51/FeedFileSourcesBinaryDataTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sonar-db/src/main/java/org/sonar/db/version/v51/FeedFileSourcesBinaryData.java b/sonar-db/src/main/java/org/sonar/db/version/v51/FeedFileSourcesBinaryData.java index 22c5f649e83..9a6f23047e7 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v51/FeedFileSourcesBinaryData.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v51/FeedFileSourcesBinaryData.java @@ -21,6 +21,7 @@ package org.sonar.db.version.v51; import com.google.common.base.Function; import com.google.common.base.Splitter; +import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import java.sql.SQLException; import java.util.Date; @@ -148,8 +149,8 @@ public class FeedFileSourcesBinaryData extends BaseDataChange { } return FileSourceDto.encodeSourceData(dataBuilder.build()); } catch (Exception e) { - Loggers.get(FeedFileSourcesBinaryData.class).error( - String.format("Invalid FILE_SOURCES.DATA on row with ID %s, data will be ignored: %s", fileSourceId, data), e); + Loggers.get(FeedFileSourcesBinaryData.class).debug( + "Invalid FILE_SOURCES.DATA on row with ID {}, data will be ignored. {}", fileSourceId, Throwables.getStackTraceAsString(e)); return FileSourceDto.encodeSourceData(dataBuilder.clear().build()); } finally { IOUtils.closeQuietly(parser); diff --git a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java index 836291c23d3..d96d67b6ac7 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java @@ -23,11 +23,14 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; import org.apache.commons.dbutils.DbUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; +import org.sonar.api.utils.log.LogTester; +import org.sonar.api.utils.log.LoggerLevel; import org.sonar.db.DbTester; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; @@ -43,6 +46,9 @@ public class FeedFileSourcesBinaryDataTest { @Rule public DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedFileSourcesBinaryDataTest.class, "schema.sql"); + @Rule + public LogTester logTester = new LogTester().setLevel(LoggerLevel.DEBUG); + @Test public void convert_csv_to_protobuf() throws Exception { db.prepareDbUnit(getClass(), "data.xml"); @@ -79,6 +85,9 @@ public class FeedFileSourcesBinaryDataTest { DbFileSources.Data data = selectData(connection, 1L); assertThat(data.getLinesList()).isEmpty(); + List debugLogs = logTester.logs(LoggerLevel.DEBUG); + assertThat(debugLogs.stream() + .anyMatch(s -> s.startsWith("Invalid FILE_SOURCES.DATA on row with ID 1, data will be ignored"))).isTrue(); } } -- 2.39.5