From 0ec8f2f79b4e004480223cabc71aae7ae5fc6194 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 15 Nov 2016 09:50:20 +0100 Subject: [PATCH] SONAR-8332 use name ID instead of UID in classe naming and comments --- .../platform/platformlevel/PlatformLevel4.java | 6 +++--- ...uestUidModule.java => HttpRequestIdModule.java} | 8 ++++---- .../web/requestid/RequestIdConfiguration.java | 2 +- ...{RequestUidFilter.java => RequestIdFilter.java} | 12 ++++++------ ...stUidGenerator.java => RequestIdGenerator.java} | 2 +- ...eratorBase.java => RequestIdGeneratorBase.java} | 4 ++-- ...seImpl.java => RequestIdGeneratorBaseImpl.java} | 2 +- ...eratorImpl.java => RequestIdGeneratorImpl.java} | 14 +++++++------- ...UidMDCStorage.java => RequestIdMDCStorage.java} | 12 ++++++------ ...oduleTest.java => HttpRequestIdModuleTest.java} | 4 ++-- ...plTest.java => RequestIdGeneratorImplTest.java} | 8 ++++---- ...orageTest.java => RequestIdMDCStorageTest.java} | 10 +++++----- server/sonar-web/src/main/webapp/WEB-INF/web.xml | 2 +- 13 files changed, 43 insertions(+), 43 deletions(-) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{HttpRequestUidModule.java => HttpRequestIdModule.java} (81%) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{RequestUidFilter.java => RequestIdFilter.java} (80%) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{RequestUidGenerator.java => RequestIdGenerator.java} (96%) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{RequestUidGeneratorBase.java => RequestIdGeneratorBase.java} (91%) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{RequestUidGeneratorBaseImpl.java => RequestIdGeneratorBaseImpl.java} (93%) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{RequestUidGeneratorImpl.java => RequestIdGeneratorImpl.java} (85%) rename server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/{RequestUidMDCStorage.java => RequestIdMDCStorage.java} (71%) rename server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/{HttpRequestUidModuleTest.java => HttpRequestIdModuleTest.java} (92%) rename server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/{RequestUidGeneratorImplTest.java => RequestIdGeneratorImplTest.java} (91%) rename server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/{RequestUidMDCStorageTest.java => RequestIdMDCStorageTest.java} (87%) diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index d45e135c13f..809e02c0643 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -120,7 +120,7 @@ import org.sonar.server.platform.monitoring.PluginsMonitor; import org.sonar.server.platform.monitoring.SettingsMonitor; import org.sonar.server.platform.monitoring.SonarQubeMonitor; import org.sonar.server.platform.monitoring.SystemMonitor; -import org.sonar.server.platform.web.requestid.HttpRequestUidModule; +import org.sonar.server.platform.web.requestid.HttpRequestIdModule; import org.sonar.server.platform.ws.ChangeLogLevelAction; import org.sonar.server.platform.ws.DbMigrationStatusAction; import org.sonar.server.platform.ws.InfoAction; @@ -545,8 +545,8 @@ public class PlatformLevel4 extends PlatformLevel { // webhooks WebhooksWsModule.class, - // Http Request UID - HttpRequestUidModule.class); + // Http Request ID + HttpRequestIdModule.class); addAll(level4AddedComponents); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/HttpRequestUidModule.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/HttpRequestIdModule.java similarity index 81% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/HttpRequestUidModule.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/HttpRequestIdModule.java index 3a2e5d531e9..86f38a07d13 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/HttpRequestUidModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/HttpRequestIdModule.java @@ -21,11 +21,11 @@ package org.sonar.server.platform.web.requestid; import org.sonar.core.platform.Module; -public class HttpRequestUidModule extends Module { +public class HttpRequestIdModule extends Module { @Override protected void configureModule() { - add(new RequestIdConfiguration(RequestUidGeneratorImpl.UUID_GENERATOR_RENEWAL_COUNT), - RequestUidGeneratorBaseImpl.class, - RequestUidGeneratorImpl.class); + add(new RequestIdConfiguration(RequestIdGeneratorImpl.UUID_GENERATOR_RENEWAL_COUNT), + RequestIdGeneratorBaseImpl.class, + RequestIdGeneratorImpl.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdConfiguration.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdConfiguration.java index 750aeec03c9..c4868941bdf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdConfiguration.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdConfiguration.java @@ -21,7 +21,7 @@ package org.sonar.server.platform.web.requestid; public class RequestIdConfiguration { /** - * @see RequestUidGeneratorImpl#mustRenewUuidGenerator(long) + * @see RequestIdGeneratorImpl#mustRenewUuidGenerator(long) */ private final long uuidGeneratorRenewalCount; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidFilter.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdFilter.java similarity index 80% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidFilter.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdFilter.java index e9d365c966b..9807cd91190 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidFilter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdFilter.java @@ -30,17 +30,17 @@ import javax.servlet.ServletResponse; import org.sonar.server.platform.Platform; /** - * A {@link Filter} that puts and removes the HTTP request UID from the {@link org.slf4j.MDC}. + * A {@link Filter} that puts and removes the HTTP request ID from the {@link org.slf4j.MDC}. */ -public class RequestUidFilter implements Filter { +public class RequestIdFilter implements Filter { private final Platform platform; - public RequestUidFilter() { + public RequestIdFilter() { this(Platform.getInstance()); } @VisibleForTesting - RequestUidFilter(Platform platform) { + RequestIdFilter(Platform platform) { this.platform = platform; } @@ -51,9 +51,9 @@ public class RequestUidFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - RequestUidGenerator requestUidGenerator = platform.getContainer().getComponentByType(RequestUidGenerator.class); + RequestIdGenerator requestIdGenerator = platform.getContainer().getComponentByType(RequestIdGenerator.class); - try (RequestUidMDCStorage mdcStorage = new RequestUidMDCStorage(requestUidGenerator.generate())) { + try (RequestIdMDCStorage mdcStorage = new RequestIdMDCStorage(requestIdGenerator.generate())) { chain.doFilter(request, response); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGenerator.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGenerator.java similarity index 96% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGenerator.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGenerator.java index 90fa322ca26..39ebdf87a4e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGenerator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGenerator.java @@ -22,7 +22,7 @@ package org.sonar.server.platform.web.requestid; /** * Generate a Unique Identifier for Http Requests. */ -public interface RequestUidGenerator { +public interface RequestIdGenerator { /** * Generate a new and unique request id for each call. */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorBase.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorBase.java similarity index 91% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorBase.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorBase.java index 65e0cb76ff8..85b717711a9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorBase.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorBase.java @@ -21,9 +21,9 @@ package org.sonar.server.platform.web.requestid; import org.sonar.core.util.UuidGenerator; -public interface RequestUidGeneratorBase { +public interface RequestIdGeneratorBase { /** - * Provides a new instance of {@link UuidGenerator.WithFixedBase} to be used by {@link RequestUidGeneratorImpl}. + * Provides a new instance of {@link UuidGenerator.WithFixedBase} to be used by {@link RequestIdGeneratorImpl}. */ UuidGenerator.WithFixedBase createNew(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorBaseImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorBaseImpl.java similarity index 93% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorBaseImpl.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorBaseImpl.java index 059f5f6efbe..e60e6c15bd8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorBaseImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorBaseImpl.java @@ -22,7 +22,7 @@ package org.sonar.server.platform.web.requestid; import org.sonar.core.util.UuidGenerator; import org.sonar.core.util.UuidGeneratorImpl; -public class RequestUidGeneratorBaseImpl implements RequestUidGeneratorBase { +public class RequestIdGeneratorBaseImpl implements RequestIdGeneratorBase { @Override public UuidGenerator.WithFixedBase createNew() { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorImpl.java similarity index 85% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorImpl.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorImpl.java index 961f568d201..096a999969d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorImpl.java @@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.sonar.core.util.UuidGenerator; /** - * This implementation of {@link RequestUidGenerator} creates unique identifiers for HTTP requests leveraging + * This implementation of {@link RequestIdGenerator} creates unique identifiers for HTTP requests leveraging * {@link UuidGenerator.WithFixedBase#generate(int)} and a counter of HTTP requests. *

* To work around the limit of unique values produced by {@link UuidGenerator.WithFixedBase#generate(int)}, the @@ -37,7 +37,7 @@ import org.sonar.core.util.UuidGenerator; * This implementation is Thread safe. *

*/ -public class RequestUidGeneratorImpl implements RequestUidGenerator { +public class RequestIdGeneratorImpl implements RequestIdGenerator { /** * The value to which the HTTP request count will be compared to (using a modulo operator, * see {@link #mustRenewUuidGenerator(long)}). @@ -55,13 +55,13 @@ public class RequestUidGeneratorImpl implements RequestUidGenerator { public static final long UUID_GENERATOR_RENEWAL_COUNT = 4_194_304; private final AtomicLong counter = new AtomicLong(); - private final RequestUidGeneratorBase requestUidGeneratorBase; + private final RequestIdGeneratorBase requestIdGeneratorBase; private final RequestIdConfiguration requestIdConfiguration; private final AtomicReference uuidGenerator; - public RequestUidGeneratorImpl(RequestUidGeneratorBase requestUidGeneratorBase, RequestIdConfiguration requestIdConfiguration) { - this.requestUidGeneratorBase = requestUidGeneratorBase; - this.uuidGenerator = new AtomicReference<>(requestUidGeneratorBase.createNew()); + public RequestIdGeneratorImpl(RequestIdGeneratorBase requestIdGeneratorBase, RequestIdConfiguration requestIdConfiguration) { + this.requestIdGeneratorBase = requestIdGeneratorBase; + this.uuidGenerator = new AtomicReference<>(requestIdGeneratorBase.createNew()); this.requestIdConfiguration = requestIdConfiguration; } @@ -70,7 +70,7 @@ public class RequestUidGeneratorImpl implements RequestUidGenerator { UuidGenerator.WithFixedBase currentUuidGenerator = this.uuidGenerator.get(); long counterValue = counter.getAndIncrement(); if (counterValue != 0 && mustRenewUuidGenerator(counterValue)) { - UuidGenerator.WithFixedBase newUuidGenerator = requestUidGeneratorBase.createNew(); + UuidGenerator.WithFixedBase newUuidGenerator = requestIdGeneratorBase.createNew(); uuidGenerator.set(newUuidGenerator); return generate(newUuidGenerator, counterValue); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidMDCStorage.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdMDCStorage.java similarity index 71% rename from server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidMDCStorage.java rename to server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdMDCStorage.java index d5c5a3b2ac9..3130a32699c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestUidMDCStorage.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/requestid/RequestIdMDCStorage.java @@ -24,17 +24,17 @@ import org.slf4j.MDC; import static java.util.Objects.requireNonNull; /** - * Wraps MDC calls to store the HTTP request UID in the {@link MDC} into an {@link AutoCloseable}. + * Wraps MDC calls to store the HTTP request ID in the {@link MDC} into an {@link AutoCloseable}. */ -class RequestUidMDCStorage implements AutoCloseable { - private static final String HTTP_REQUEST_UID_MDC_KEY = "HTTP_REQUEST_ID"; +class RequestIdMDCStorage implements AutoCloseable { + private static final String HTTP_REQUEST_ID_MDC_KEY = "HTTP_REQUEST_ID"; - public RequestUidMDCStorage(String requestUid) { - MDC.put(HTTP_REQUEST_UID_MDC_KEY, requireNonNull(requestUid, "Request UID can't be null")); + public RequestIdMDCStorage(String requestId) { + MDC.put(HTTP_REQUEST_ID_MDC_KEY, requireNonNull(requestId, "Request ID can't be null")); } @Override public void close() { - MDC.remove(HTTP_REQUEST_UID_MDC_KEY); + MDC.remove(HTTP_REQUEST_ID_MDC_KEY); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/HttpRequestUidModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/HttpRequestIdModuleTest.java similarity index 92% rename from server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/HttpRequestUidModuleTest.java rename to server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/HttpRequestIdModuleTest.java index e8b4c173d57..ba1a1c59534 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/HttpRequestUidModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/HttpRequestIdModuleTest.java @@ -24,10 +24,10 @@ import org.sonar.core.platform.ComponentContainer; import static org.assertj.core.api.Assertions.assertThat; -public class HttpRequestUidModuleTest { +public class HttpRequestIdModuleTest { private static final int COMPONENTS_HARDCODED_IN_CONTAINER = 2; - private HttpRequestUidModule underTest = new HttpRequestUidModule(); + private HttpRequestIdModule underTest = new HttpRequestIdModule(); @Test public void count_components_in_module() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorImplTest.java similarity index 91% rename from server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorImplTest.java rename to server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorImplTest.java index f49c4568d0d..edd38b174b9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestUidGeneratorImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestIdGeneratorImplTest.java @@ -28,14 +28,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class RequestUidGeneratorImplTest { +public class RequestIdGeneratorImplTest { @Rule public ExpectedException expectedException = ExpectedException.none(); private UuidGenerator.WithFixedBase generator1 = increment -> new byte[] {124, 22, 66, 96, 55, 88, 2, 9}; private UuidGenerator.WithFixedBase generator2 = increment -> new byte[] {0, 5, 88, 81, 8, 6, 44, 19}; private UuidGenerator.WithFixedBase generator3 = increment -> new byte[] {126, 9, 35, 76, 2, 1, 2}; - private RequestUidGeneratorBase uidGeneratorBase = mock(RequestUidGeneratorBase.class); + private RequestIdGeneratorBase uidGeneratorBase = mock(RequestIdGeneratorBase.class); private IllegalStateException expected = new IllegalStateException("Unexpected third call to createNew"); @Test @@ -46,7 +46,7 @@ public class RequestUidGeneratorImplTest { .thenReturn(generator3) .thenThrow(expected); - RequestUidGeneratorImpl underTest = new RequestUidGeneratorImpl(uidGeneratorBase, new RequestIdConfiguration(2)); + RequestIdGeneratorImpl underTest = new RequestIdGeneratorImpl(uidGeneratorBase, new RequestIdConfiguration(2)); assertThat(underTest.generate()).isEqualTo("fBZCYDdYAgk="); // using generator1 assertThat(underTest.generate()).isEqualTo("fBZCYDdYAgk="); // still using generator1 @@ -69,7 +69,7 @@ public class RequestUidGeneratorImplTest { .thenReturn(generator3) .thenThrow(expected); - RequestUidGeneratorImpl underTest = new RequestUidGeneratorImpl(uidGeneratorBase, new RequestIdConfiguration(3)); + RequestIdGeneratorImpl underTest = new RequestIdGeneratorImpl(uidGeneratorBase, new RequestIdConfiguration(3)); assertThat(underTest.generate()).isEqualTo("fBZCYDdYAgk="); // using generator1 assertThat(underTest.generate()).isEqualTo("fBZCYDdYAgk="); // still using generator1 diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestUidMDCStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestIdMDCStorageTest.java similarity index 87% rename from server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestUidMDCStorageTest.java rename to server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestIdMDCStorageTest.java index 53595b2db69..01a638c6561 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestUidMDCStorageTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/web/requestid/RequestIdMDCStorageTest.java @@ -27,7 +27,7 @@ import org.junit.rules.ExpectedException; import static org.assertj.core.api.Assertions.assertThat; -public class RequestUidMDCStorageTest { +public class RequestIdMDCStorageTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -39,21 +39,21 @@ public class RequestUidMDCStorageTest { @Test public void constructor_fails_with_NPE_when_argument_is_null() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("Request UID can't be null"); + expectedException.expectMessage("Request ID can't be null"); - new RequestUidMDCStorage(null); + new RequestIdMDCStorage(null); } @Test public void constructor_adds_specified_value_in_MDC_under_HTTP_REQUEST_ID_key() { - new RequestUidMDCStorage("toto"); + new RequestIdMDCStorage("toto"); assertThat(MDC.get("HTTP_REQUEST_ID")).isEqualTo("toto"); } @Test public void close_removes_value_from_MDC() { - RequestUidMDCStorage underTest = new RequestUidMDCStorage("boum"); + RequestIdMDCStorage underTest = new RequestIdMDCStorage("boum"); assertThat(MDC.get("HTTP_REQUEST_ID")).isEqualTo("boum"); underTest.close(); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/web.xml b/server/sonar-web/src/main/webapp/WEB-INF/web.xml index 33a2fb2bd9c..11382a11f5b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/web.xml +++ b/server/sonar-web/src/main/webapp/WEB-INF/web.xml @@ -66,7 +66,7 @@ RequestUidFilter - org.sonar.server.platform.web.requestid.RequestUidFilter + org.sonar.server.platform.web.requestid.RequestIdFilter -- 2.39.5