-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Missing Use of
SuccessFunction
in Determining Response Success …
…for Log Levels Motivation: The `ResponseLogLevelMapper.of()` did not use the `SuccessFunction` to determine whether a response was successful. Modifications: - Updated `ResponseLogLevelMapper.of()` to use the `SuccessFunction` when determining the success of a response. Result: - Log levels for responses are now correctly mapped based on the `SuccessFunction`.
- Loading branch information
Showing
7 changed files
with
123 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/test/java/com/linecorp/armeria/common/logging/ResponseLogLevelMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linecorp.armeria.common.logging; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import com.linecorp.armeria.client.ClientRequestContext; | ||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
import com.linecorp.armeria.common.RequestContext; | ||
import com.linecorp.armeria.common.ResponseHeaders; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
|
||
class ResponseLogLevelMapperTest { | ||
|
||
@MethodSource("contexts") | ||
@ParameterizedTest | ||
void foo(RequestContext ctx, int status) { | ||
final ResponseLogLevelMapper logLevelMapper = ResponseLogLevelMapper.of(LogLevel.DEBUG, LogLevel.WARN); | ||
final RequestLogBuilder logBuilder = ctx.logBuilder(); | ||
logBuilder.endRequest(); | ||
logBuilder.responseHeaders(ResponseHeaders.of(status)); | ||
logBuilder.endResponse(); | ||
final LogLevel expected = status == 200 ? LogLevel.DEBUG : LogLevel.WARN; | ||
assertThat(logLevelMapper.apply(ctx.log().ensureComplete())).isSameAs(expected); | ||
} | ||
|
||
private static Stream<Arguments> contexts() { | ||
final HttpRequest request = HttpRequest.of(HttpMethod.GET, "/"); | ||
return Stream.of( | ||
Arguments.of(ClientRequestContext.of(request), 200), | ||
Arguments.of(ServiceRequestContext.of(request), 200), | ||
Arguments.of(ClientRequestContext.of(request), 500), | ||
Arguments.of(ServiceRequestContext.of(request), 500) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters