aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-04-11 15:43:35 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-04-11 20:48:58 +0200
commit0a55cf048ee3140a83dafaf51edf6b54456d65d6 (patch)
tree8159e8a5e489bc8d4fb32968414d7d994e5309af /server/sonar-ce
parente1c38c60c2b287284ab38243eff1f5c716bea8d5 (diff)
downloadsonarqube-0a55cf048ee3140a83dafaf51edf6b54456d65d6.tar.gz
sonarqube-0a55cf048ee3140a83dafaf51edf6b54456d65d6.zip
Delete unused class LogarithmicLogger
Diffstat (limited to 'server/sonar-ce')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/LogarithmicLogger.java250
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/app/LogarithmicLoggerTest.java110
2 files changed, 0 insertions, 360 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/LogarithmicLogger.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/LogarithmicLogger.java
deleted file mode 100644
index 5336f83f091..00000000000
--- a/server/sonar-ce/src/main/java/org/sonar/ce/app/LogarithmicLogger.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.ce.app;
-
-import javax.annotation.Nullable;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.LoggerLevel;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- *
- */
-public final class LogarithmicLogger implements Logger {
- private final Logger logger;
- private final long callRatio;
- private long callCounter = -1;
- private long logCounter = -1;
-
- private LogarithmicLogger(Builder builder) {
- this.logger = builder.logger;
- this.callRatio = builder.callRatio;
- }
-
- public static Builder from(Logger logger) {
- return new Builder(logger);
- }
-
- public static final class Builder {
- private final Logger logger;
- private long callRatio = 1;
-
- public Builder(Logger logger) {
- this.logger = logger;
- }
-
- public Builder applyingCallRatio(long callRatio) {
- checkArgument(callRatio >= 1, "callRatio must be => 1");
- this.callRatio = callRatio;
- return this;
- }
-
- public Logger build() {
- return new LogarithmicLogger(this);
- }
- }
-
-
- private boolean shouldLog() {
- callCounter++;
- long ratioed = callCounter / callRatio;
- long log = (long) Math.log(ratioed);
- if (log > logCounter) {
- logCounter = log;
- return true;
- }
- return false;
- }
-
- @Override
- public boolean isTraceEnabled() {
- return logger.isTraceEnabled();
- }
-
- @Override
- public boolean isDebugEnabled() {
- return logger.isDebugEnabled();
- }
-
- @Override
- public boolean setLevel(LoggerLevel level) {
- return logger.setLevel(level);
- }
-
- @Override
- public LoggerLevel getLevel() {
- return logger.getLevel();
- }
-
- @Override
- public void trace(String msg) {
- if (shouldLog()) {
- logger.trace(msg);
- }
- }
-
- @Override
- public void trace(String pattern, @Nullable Object arg) {
- if (shouldLog()) {
- logger.trace(pattern, arg);
- }
- }
-
- @Override
- public void trace(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- if (shouldLog()) {
- logger.trace(msg, arg1, arg2);
- }
- }
-
- @Override
- public void trace(String msg, Object... args) {
- if (shouldLog()) {
- logger.trace(msg, args);
- }
- }
-
- @Override
- public void debug(String msg) {
- if (shouldLog()) {
- logger.debug(msg);
- }
- }
-
- @Override
- public void debug(String pattern, @Nullable Object arg) {
- if (shouldLog()) {
- logger.debug(pattern, arg);
- }
- }
-
- @Override
- public void debug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- if (shouldLog()) {
- logger.debug(msg, arg1, arg2);
- }
- }
-
- @Override
- public void debug(String msg, Object... args) {
- if (shouldLog()) {
- logger.debug(msg, args);
- }
- }
-
- @Override
- public void info(String msg) {
- if (shouldLog()) {
- logger.info(msg);
- }
- }
-
- @Override
- public void info(String msg, @Nullable Object arg) {
- if (shouldLog()) {
- logger.info(msg, arg);
- }
- }
-
- @Override
- public void info(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- if (shouldLog()) {
- logger.info(msg, arg1, arg2);
- }
- }
-
- @Override
- public void info(String msg, Object... args) {
- if (shouldLog()) {
- logger.info(msg, args);
- }
- }
-
- @Override
- public void warn(String msg) {
- if (shouldLog()) {
- logger.warn(msg);
- }
- }
-
- @Override
- public void warn(String msg, Throwable throwable) {
- if (shouldLog()) {
- logger.warn(msg, throwable);
- }
- }
-
- @Override
- public void warn(String msg, @Nullable Object arg) {
- if (shouldLog()) {
- logger.warn(msg, arg);
- }
- }
-
- @Override
- public void warn(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- if (shouldLog()) {
- logger.warn(msg, arg1, arg2);
- }
- }
-
- @Override
- public void warn(String msg, Object... args) {
- if (shouldLog()) {
- logger.warn(msg, args);
- }
- }
-
- @Override
- public void error(String msg) {
- if (shouldLog()) {
- logger.error(msg);
- }
- }
-
- @Override
- public void error(String msg, @Nullable Object arg) {
- if (shouldLog()) {
- logger.error(msg, arg);
- }
- }
-
- @Override
- public void error(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- if (shouldLog()) {
- logger.error(msg, arg1, arg2);
- }
- }
-
- @Override
- public void error(String msg, Object... args) {
- if (shouldLog()) {
- logger.error(msg, args);
- }
- }
-
- @Override
- public void error(String msg, Throwable thrown) {
- if (shouldLog()) {
- logger.error(msg, thrown);
- }
- }
-}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/LogarithmicLoggerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/LogarithmicLoggerTest.java
deleted file mode 100644
index 5863486673c..00000000000
--- a/server/sonar-ce/src/test/java/org/sonar/ce/app/LogarithmicLoggerTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.ce.app;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.api.utils.log.LoggerLevel.DEBUG;
-import static org.sonar.api.utils.log.LoggerLevel.ERROR;
-import static org.sonar.api.utils.log.LoggerLevel.INFO;
-import static org.sonar.api.utils.log.LoggerLevel.TRACE;
-import static org.sonar.api.utils.log.LoggerLevel.WARN;
-
-public class LogarithmicLoggerTest {
- @Rule
- public LogTester logTester = new LogTester();
-
- @Test
- public void logarithmically_logs_less_and_less_frequently_calls_to_same_Logger_method() throws InterruptedException {
- Logger logarithmicLogger = LogarithmicLogger.from(Loggers.get(getClass())).build();
- for (int i = 0; i < 1000; i++) {
- logarithmicLogger.error(String.valueOf(i));
- }
-
- assertThat(logTester.logs(ERROR)).containsOnly(
- "1", "3", "8", "21", "55", "149", "404"
- );
- assertThat(logTester.logs()).containsOnly(
- "1", "3", "8", "21", "55", "149", "404"
- );
- }
-
- @Test
- public void logarithmically_logs_less_and_less_frequently_calls_across_log_levels() throws InterruptedException {
- Logger logarithmicLogger = LogarithmicLogger.from(Loggers.get(getClass())).build();
- for (int i = 0; i < 1000; i++) {
- spawnMessageOnLevels(logarithmicLogger, i, String.valueOf(i));
- }
-
- assertThat(logTester.logs()).containsOnly(
- "1", "3", "8", "21", "55", "149", "404"
- );
- assertThat(logTester.logs(ERROR)).containsOnly("55");
- assertThat(logTester.logs(WARN)).containsOnly("1", "21");
- assertThat(logTester.logs(INFO)).isEmpty();
- assertThat(logTester.logs(DEBUG)).containsOnly("3", "8");
- assertThat(logTester.logs(TRACE)).containsOnly("149", "404");
- }
-
- @Test
- public void call_ratio_is_applied_before_logarithm() {
- int callRatio = 10;
- Logger logarithmicLogger = LogarithmicLogger.from(Loggers.get(getClass())).applyingCallRatio(callRatio).build();
- for (int i = 0; i < 1000 + callRatio; i++) {
- logarithmicLogger.error(String.valueOf(i));
- }
-
- assertThat(logTester.logs(ERROR)).containsOnly(
- "10", "30", "80", "210", "550"
- );
- assertThat(logTester.logs()).containsOnly(
- "10", "30", "80", "210", "550"
- );
- }
-
- private static void spawnMessageOnLevels(Logger logarithmicLogger, int i, String msg) {
- int c = i % 5;
- switch (c) {
- case 0:
- logarithmicLogger.error(msg);
- break;
- case 1:
- logarithmicLogger.warn(msg);
- break;
- case 2:
- logarithmicLogger.info(msg);
- break;
- case 3:
- logarithmicLogger.debug(msg);
- break;
- case 4:
- logarithmicLogger.trace(msg);
- break;
- default:
- throw new IllegalArgumentException("Unsupported value " + c);
- }
- }
-
-}