From 087481a53525549b11fe3fce15534b489a44b4cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 22 Aug 2016 10:19:18 +0200 Subject: [PATCH] SONAR-7825 changeloglevel WS now change CE's log level too --- .../main/java/org/sonar/ce/CeHttpModule.java | 4 +- .../java/org/sonar/ce/httpd/HttpAction.java | 2 +- .../ce/logging/ChangeLogLevelHttpAction.java | 74 +++++++++++ .../org/sonar/ce/logging/package-info.java | 23 ++++ .../ComputeEngineContainerImplTest.java | 6 +- .../java/org/sonar/ce/httpd/CeHttpUtils.java | 46 +++++++ .../logging/ChangeLogLevelHttpActionTest.java | 117 ++++++++++++++++++ .../systeminfo/SystemInfoHttpActionTest.java | 11 +- .../java/org/sonar/ce/http/CeHttpClient.java | 93 +++++++++++++- .../platform/ws/ChangeLogLevelAction.java | 6 +- .../platform/ws/ChangeLogLevelActionTest.java | 13 +- 11 files changed, 372 insertions(+), 23 deletions(-) create mode 100644 server/sonar-ce/src/main/java/org/sonar/ce/logging/ChangeLogLevelHttpAction.java create mode 100644 server/sonar-ce/src/main/java/org/sonar/ce/logging/package-info.java create mode 100644 server/sonar-ce/src/test/java/org/sonar/ce/httpd/CeHttpUtils.java create mode 100644 server/sonar-ce/src/test/java/org/sonar/ce/logging/ChangeLogLevelHttpActionTest.java diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/CeHttpModule.java b/server/sonar-ce/src/main/java/org/sonar/ce/CeHttpModule.java index 69afca02955..00d011638a6 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/CeHttpModule.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/CeHttpModule.java @@ -20,6 +20,7 @@ package org.sonar.ce; import org.sonar.ce.httpd.CeHttpServer; +import org.sonar.ce.logging.ChangeLogLevelHttpAction; import org.sonar.ce.systeminfo.SystemInfoHttpAction; import org.sonar.core.platform.Module; @@ -28,6 +29,7 @@ public class CeHttpModule extends Module { protected void configureModule() { add( CeHttpServer.class, - SystemInfoHttpAction.class); + SystemInfoHttpAction.class, + ChangeLogLevelHttpAction.class); } } diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/httpd/HttpAction.java b/server/sonar-ce/src/main/java/org/sonar/ce/httpd/HttpAction.java index c4d633269a1..b5891be7ac2 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/httpd/HttpAction.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/httpd/HttpAction.java @@ -27,7 +27,7 @@ import fi.iki.elonen.NanoHTTPD.Response; * *

* Method {@link #register(ActionRegistry)} of the action will be called right before the HTTP server is started (server - * is started by the Pico Container). It's the action's responsability to call the method + * is started by the Pico Container). It's the action's responsibility to call the method * {@link ActionRegistry#register(ActionRegistry)} to register itself for a given path. *

*

diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/logging/ChangeLogLevelHttpAction.java b/server/sonar-ce/src/main/java/org/sonar/ce/logging/ChangeLogLevelHttpAction.java new file mode 100644 index 00000000000..626eb20c4a6 --- /dev/null +++ b/server/sonar-ce/src/main/java/org/sonar/ce/logging/ChangeLogLevelHttpAction.java @@ -0,0 +1,74 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.logging; + +import fi.iki.elonen.NanoHTTPD; +import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.api.utils.log.Loggers; +import org.sonar.ce.httpd.HttpAction; +import org.sonar.db.Database; +import org.sonar.server.platform.ServerLogging; + +import static fi.iki.elonen.NanoHTTPD.MIME_PLAINTEXT; +import static fi.iki.elonen.NanoHTTPD.Response.Status.BAD_REQUEST; +import static fi.iki.elonen.NanoHTTPD.Response.Status.METHOD_NOT_ALLOWED; +import static fi.iki.elonen.NanoHTTPD.Response.Status.OK; +import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse; +import static java.lang.String.format; + +public class ChangeLogLevelHttpAction implements HttpAction { + + private static final String PATH = "changeLogLevel"; + private static final String PARAM_LEVEL = "level"; + + private final ServerLogging logging; + private final Database db; + + public ChangeLogLevelHttpAction(ServerLogging logging, Database db) { + this.logging = logging; + this.db = db; + } + + @Override + public void register(ActionRegistry registry) { + registry.register(PATH, this); + } + + @Override + public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { + if (session.getMethod() != NanoHTTPD.Method.POST) { + return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); + } + + String levelStr = session.getParms().get(PARAM_LEVEL); + if (levelStr == null || levelStr.isEmpty()) { + return newFixedLengthResponse(BAD_REQUEST, MIME_PLAINTEXT, format("Parameter '%s' is missing", PARAM_LEVEL)); + } + try { + LoggerLevel level = LoggerLevel.valueOf(levelStr); + db.enableSqlLogging(level.equals(LoggerLevel.TRACE)); + logging.changeLevel(level); + return newFixedLengthResponse(OK, MIME_PLAINTEXT, null); + } catch (IllegalArgumentException e) { + Loggers.get(ChangeLogLevelHttpAction.class).debug("Value '{}' for parameter '{}' is invalid", levelStr, PARAM_LEVEL, e); + return newFixedLengthResponse(BAD_REQUEST, MIME_PLAINTEXT, format("Value '%s' for parameter '%s' is invalid", levelStr, PARAM_LEVEL)); + } + } +} diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/logging/package-info.java b/server/sonar-ce/src/main/java/org/sonar/ce/logging/package-info.java new file mode 100644 index 00000000000..83bd486343c --- /dev/null +++ b/server/sonar-ce/src/main/java/org/sonar/ce/logging/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.ce.logging; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index e220ecfb360..ed1a0ceb7c3 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -88,9 +88,9 @@ public class ComputeEngineContainerImplTest { assertThat(picoContainer.getComponentAdapters()) .hasSize( CONTAINER_ITSELF - + 75 // level 4 - + 7 // content of CeConfigurationModule - + 2 // content of CeHttpModule + + 79 // level 4 + + 4 // content of CeConfigurationModule + + 3 // content of CeHttpModule + 5 // content of CeQueueModule + 4 // content of ProjectAnalysisTaskModule + 4 // content of CeTaskProcessorModule diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/httpd/CeHttpUtils.java b/server/sonar-ce/src/test/java/org/sonar/ce/httpd/CeHttpUtils.java new file mode 100644 index 00000000000..b4771598be2 --- /dev/null +++ b/server/sonar-ce/src/test/java/org/sonar/ce/httpd/CeHttpUtils.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.httpd; + +import fi.iki.elonen.NanoHTTPD; +import java.util.Map; +import javax.annotation.Nullable; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public abstract class CeHttpUtils { + private CeHttpUtils() { + // prevents instantiation + } + + public static NanoHTTPD.IHTTPSession createHttpSession(NanoHTTPD.Method method) { + return createHttpSession(method, null); + } + + public static NanoHTTPD.IHTTPSession createHttpSession(NanoHTTPD.Method method, @Nullable Map params) { + NanoHTTPD.IHTTPSession res = mock(NanoHTTPD.IHTTPSession.class); + when(res.getMethod()).thenReturn(method); + if (params != null) { + when(res.getParms()).thenReturn(params); + } + return res; + } +} diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/logging/ChangeLogLevelHttpActionTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/logging/ChangeLogLevelHttpActionTest.java new file mode 100644 index 00000000000..cce5313c2f5 --- /dev/null +++ b/server/sonar-ce/src/test/java/org/sonar/ce/logging/ChangeLogLevelHttpActionTest.java @@ -0,0 +1,117 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.logging; + +import com.google.common.collect.ImmutableMap; +import fi.iki.elonen.NanoHTTPD; +import java.io.IOException; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.ce.httpd.HttpAction; +import org.sonar.db.Database; +import org.sonar.server.platform.ServerLogging; + +import static fi.iki.elonen.NanoHTTPD.Method.GET; +import static fi.iki.elonen.NanoHTTPD.Method.POST; +import static fi.iki.elonen.NanoHTTPD.Response.Status.BAD_REQUEST; +import static fi.iki.elonen.NanoHTTPD.Response.Status.METHOD_NOT_ALLOWED; +import static fi.iki.elonen.NanoHTTPD.Response.Status.OK; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.sonar.ce.httpd.CeHttpUtils.createHttpSession; + +public class ChangeLogLevelHttpActionTest { + private ServerLogging serverLogging = mock(ServerLogging.class); + private Database database = mock(Database.class); + private ChangeLogLevelHttpAction underTest = new ChangeLogLevelHttpAction(serverLogging, database); + + @Test + public void register_to_path_systemInfo() { + HttpAction.ActionRegistry actionRegistry = mock(HttpAction.ActionRegistry.class); + + underTest.register(actionRegistry); + + verify(actionRegistry).register("changeLogLevel", underTest); + } + + @Test + public void serves_METHOD_NOT_ALLOWED_error_when_method_is_not_POST() { + NanoHTTPD.Response response = underTest.serve(createHttpSession(GET)); + assertThat(response.getStatus()).isEqualTo(METHOD_NOT_ALLOWED); + } + + @Test + public void serves_BAD_REQUEST_error_when_parameter_level_is_missing() throws IOException { + NanoHTTPD.Response response = underTest.serve(createHttpSession(POST)); + + assertThat(response.getStatus()).isEqualTo(BAD_REQUEST); + assertThat(IOUtils.toString(response.getData())).isEqualTo("Parameter 'level' is missing"); + } + + @Test + public void serves_BAD_REQUEST_error_when_value_of_parameter_level_is_not_LEVEL_in_uppercase() throws IOException { + NanoHTTPD.Response response = underTest.serve(createHttpSession(POST, ImmutableMap.of("level", "info"))); + + assertThat(response.getStatus()).isEqualTo(BAD_REQUEST); + assertThat(IOUtils.toString(response.getData())).isEqualTo("Value 'info' for parameter 'level' is invalid"); + } + + @Test + public void changes_server_logging_and_disabled_database_logging_if_level_is_ERROR() { + NanoHTTPD.Response response = underTest.serve(createHttpSession(POST, ImmutableMap.of("level", "ERROR"))); + + assertThat(response.getStatus()).isEqualTo(OK); + + verify(serverLogging).changeLevel(LoggerLevel.ERROR); + verify(database).enableSqlLogging(false); + } + + @Test + public void changes_server_logging_and_disabled_database_logging_if_level_is_INFO() { + NanoHTTPD.Response response = underTest.serve(createHttpSession(POST, ImmutableMap.of("level", "INFO"))); + + assertThat(response.getStatus()).isEqualTo(OK); + + verify(serverLogging).changeLevel(LoggerLevel.INFO); + verify(database).enableSqlLogging(false); + } + + @Test + public void changes_server_logging_and_disabled_database_logging_if_level_is_DEBUG() { + NanoHTTPD.Response response = underTest.serve(createHttpSession(POST, ImmutableMap.of("level", "DEBUG"))); + + assertThat(response.getStatus()).isEqualTo(OK); + + verify(serverLogging).changeLevel(LoggerLevel.DEBUG); + verify(database).enableSqlLogging(false); + } + + @Test + public void changes_server_logging_and_enable_database_logging_if_level_is_TRACE() { + NanoHTTPD.Response response = underTest.serve(createHttpSession(POST, ImmutableMap.of("level", "TRACE"))); + + assertThat(response.getStatus()).isEqualTo(OK); + + verify(serverLogging).changeLevel(LoggerLevel.TRACE); + verify(database).enableSqlLogging(true); + } +} diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/systeminfo/SystemInfoHttpActionTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/systeminfo/SystemInfoHttpActionTest.java index 2561872e9ea..2b96f545a70 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/systeminfo/SystemInfoHttpActionTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/systeminfo/SystemInfoHttpActionTest.java @@ -32,11 +32,12 @@ import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; import static fi.iki.elonen.NanoHTTPD.Method.GET; import static fi.iki.elonen.NanoHTTPD.Method.POST; -import static fi.iki.elonen.NanoHTTPD.Response.Status.*; +import static fi.iki.elonen.NanoHTTPD.Response.Status.METHOD_NOT_ALLOWED; +import static fi.iki.elonen.NanoHTTPD.Response.Status.OK; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.sonar.ce.httpd.CeHttpUtils.createHttpSession; public class SystemInfoHttpActionTest { @@ -77,10 +78,4 @@ public class SystemInfoHttpActionTest { assertThat(systemInfo.getSections(1).getName()).isEqualTo("state2"); } - private NanoHTTPD.IHTTPSession createHttpSession(NanoHTTPD.Method method) { - NanoHTTPD.IHTTPSession res = mock(NanoHTTPD.IHTTPSession.class); - when(res.getMethod()).thenReturn(method); - return res; - } - } diff --git a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java b/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java index 026dd8ef511..c663ee68f85 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java +++ b/server/sonar-server/src/main/java/org/sonar/ce/http/CeHttpClient.java @@ -22,10 +22,15 @@ package org.sonar.ce.http; import java.io.File; import java.net.URI; import java.util.Optional; +import okhttp3.OkHttpClient; +import okhttp3.RequestBody; import org.apache.commons.io.IOUtils; import org.sonar.api.config.Settings; +import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.api.utils.log.Loggers; import org.sonar.process.DefaultProcessCommands; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; +import org.sonar.server.platform.ws.ChangeLogLevelAction; import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH; import static org.sonar.process.ProcessId.COMPUTE_ENGINE; @@ -35,6 +40,9 @@ import static org.sonar.process.ProcessId.COMPUTE_ENGINE; */ public class CeHttpClient { + private static final String PATH_CHANGE_LOG_LEVEL = "changeLogLevel"; + private static final String PATH_SYSTEM_INFO = "systemInfo"; + private final File ipcSharedDir; public CeHttpClient(Settings props) { @@ -47,15 +55,92 @@ public class CeHttpClient { * is not registered into IPC. */ public Optional retrieveSystemInfo() { + return call(SystemInfoActionClient.INSTANCE); + } + + private enum SystemInfoActionClient implements ActionClient> { + INSTANCE; + + @Override + public String getPath() { + return PATH_SYSTEM_INFO; + } + + @Override + public Optional getDefault() { + return Optional.empty(); + } + + @Override + public Optional call(String url) throws Exception { + byte[] protobuf = IOUtils.toByteArray(new URI(url)); + return Optional.of(ProtobufSystemInfo.SystemInfo.parseFrom(protobuf)); + } + } + + public void changeLogLevel(LoggerLevel level) { + call(new ChangeLogLevelActionClient(level)); + } + + private static final class ChangeLogLevelActionClient implements ActionClient { + private final LoggerLevel newLogLevel; + + private ChangeLogLevelActionClient(LoggerLevel newLogLevel) { + this.newLogLevel = newLogLevel; + } + + @Override + public String getPath() { + return PATH_CHANGE_LOG_LEVEL; + } + + @Override + public Void getDefault() { + return null; + } + + @Override + public Void call(String url) throws Exception { + okhttp3.Request request = new okhttp3.Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url + "?level=" + newLogLevel.name()) + .build(); + okhttp3.Response response = new OkHttpClient().newCall(request).execute(); + if (response.code() != 200) { + Loggers.get(ChangeLogLevelAction.class).error( + "Failed to change log level in Compute Engine. Code was '{}' and response was '{}'", + response.code(), + response.body().string()); + } + return null; + } + } + + private T call(ActionClient actionClient) { try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(ipcSharedDir, COMPUTE_ENGINE.getIpcIndex())) { if (commands.isUp()) { - String url = commands.getHttpUrl() + "/systemInfo"; - byte[] protobuf = IOUtils.toByteArray(new URI(url)); - return Optional.of(ProtobufSystemInfo.SystemInfo.parseFrom(protobuf)); + return actionClient.call(commands.getHttpUrl() + "/" + actionClient.getPath()); } - return Optional.empty(); + return actionClient.getDefault(); } catch (Exception e) { throw new IllegalStateException("Can not get system info of process " + COMPUTE_ENGINE, e); } } + + private interface ActionClient { + /** + * Path of the action. + */ + String getPath(); + + /** + * Value to return when the Compute Engine is not ready. + */ + T getDefault(); + + /** + * Delegates to perform the call to the Compute Engine's specified absolute URL. + */ + T call(String url) throws Exception; + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelAction.java index 61bee1fe604..b23e595e1a7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelAction.java @@ -24,6 +24,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.api.web.UserRole; +import org.sonar.ce.http.CeHttpClient; import org.sonar.db.Database; import org.sonar.server.platform.ServerLogging; import org.sonar.server.user.UserSession; @@ -35,11 +36,13 @@ public class ChangeLogLevelAction implements SystemWsAction { private final UserSession userSession; private final ServerLogging logging; private final Database db; + private final CeHttpClient ceHttpClient; - public ChangeLogLevelAction(UserSession userSession, ServerLogging logging, Database db) { + public ChangeLogLevelAction(UserSession userSession, ServerLogging logging, Database db, CeHttpClient ceHttpClient) { this.userSession = userSession; this.logging = logging; this.db = db; + this.ceHttpClient = ceHttpClient; } @Override @@ -63,6 +66,7 @@ public class ChangeLogLevelAction implements SystemWsAction { LoggerLevel level = LoggerLevel.valueOf(wsRequest.mandatoryParam(PARAM_LEVEL)); db.enableSqlLogging(level.equals(LoggerLevel.TRACE)); logging.changeLevel(level); + ceHttpClient.changeLogLevel(level); wsResponse.noContent(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java index 19ab7b79a20..e0b457f2d8e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.api.web.UserRole; +import org.sonar.ce.http.CeHttpClient; import org.sonar.db.Database; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.platform.ServerLogging; @@ -37,14 +38,14 @@ public class ChangeLogLevelActionTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public ExpectedException expectedException = ExpectedException.none(); - ServerLogging serverLogging = mock(ServerLogging.class); - Database db = mock(Database.class); - ChangeLogLevelAction underTest = new ChangeLogLevelAction(userSession, serverLogging, db); - WsActionTester actionTester = new WsActionTester(underTest); + private ServerLogging serverLogging = mock(ServerLogging.class); + private Database db = mock(Database.class); + private CeHttpClient ceHttpClient = mock(CeHttpClient.class); + private ChangeLogLevelAction underTest = new ChangeLogLevelAction(userSession, serverLogging, db, ceHttpClient); + private WsActionTester actionTester = new WsActionTester(underTest); @Test public void enable_debug_logs() { @@ -55,6 +56,7 @@ public class ChangeLogLevelActionTest { .setMethod("POST") .execute(); verify(serverLogging).changeLevel(LoggerLevel.DEBUG); + verify(ceHttpClient).changeLogLevel(LoggerLevel.DEBUG); verify(db).enableSqlLogging(false); } @@ -67,6 +69,7 @@ public class ChangeLogLevelActionTest { .setMethod("POST") .execute(); verify(serverLogging).changeLevel(LoggerLevel.TRACE); + verify(ceHttpClient).changeLogLevel(LoggerLevel.TRACE); verify(db).enableSqlLogging(true); } -- 2.39.5