Search in sources :

Example 16 with Logger

use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.

the class FailFastProblemReporterTests method testWarn.

@Test
public void testWarn() throws Exception {
    Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")), null, new IllegalArgumentException());
    Logger log = mock(Logger.class);
    FailFastProblemReporter reporter = new FailFastProblemReporter();
    reporter.setLogger(log);
    reporter.warning(problem);
    verify(log).warn(any(), isA(IllegalArgumentException.class));
}
Also used : DescriptiveResource(cn.taketoday.core.io.DescriptiveResource) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 17 with Logger

use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.

the class LoggingCacheErrorHandlerTests method handleEvictCacheErrorLogsAppropriateMessage.

@Test
void handleEvictCacheErrorLogsAppropriateMessage() {
    Logger logger = mock(Logger.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
    handler.handleCacheEvictError(new RuntimeException(), new NoOpCache("NOOP"), "key");
    verify(logger).warn("Cache 'NOOP' failed to evict entry with key 'key'");
}
Also used : NoOpCache(cn.taketoday.cache.support.NoOpCache) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 18 with Logger

use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.

the class LoggingCacheErrorHandlerTests method handleGetCacheErrorLogsAppropriateMessage.

@Test
void handleGetCacheErrorLogsAppropriateMessage() {
    Logger logger = mock(Logger.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
    handler.handleCacheGetError(new RuntimeException(), new NoOpCache("NOOP"), "key");
    verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'");
}
Also used : NoOpCache(cn.taketoday.cache.support.NoOpCache) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 19 with Logger

use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.

the class LambdaSafeTests method callbackWithLoggerShouldUseLogger.

@Test
@SuppressWarnings("unchecked")
void callbackWithLoggerShouldUseLogger() {
    Logger logger = mock(Logger.class);
    given(logger.isDebugEnabled()).willReturn(true);
    GenericCallback<StringBuilder> callbackInstance = (s) -> fail("Should not get here");
    String argument = "foo";
    LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).withLogger(logger).invoke((c) -> c.handle(argument));
    verify(logger).debug(contains("Non-matching CharSequence type for callback LambdaSafeTests.GenericCallback"), any(Throwable.class));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Filter.allowAll(cn.taketoday.util.LambdaSafe.Filter.allowAll) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArgumentMatchers.contains(org.mockito.ArgumentMatchers.contains) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Test(org.junit.jupiter.api.Test) List(java.util.List) InvocationResult(cn.taketoday.util.LambdaSafe.InvocationResult) Stream(java.util.stream.Stream) BDDMockito.given(org.mockito.BDDMockito.given) Logger(cn.taketoday.logging.Logger) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 20 with Logger

use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.

the class ResourceHttpMessageWriter method writeResource.

private Mono<Void> writeResource(Resource resource, ResolvableType type, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) {
    HttpHeaders headers = message.getHeaders();
    MediaType resourceMediaType = getResourceMediaType(mediaType, resource, hints);
    headers.setContentType(resourceMediaType);
    if (headers.getContentLength() < 0) {
        long length = lengthOf(resource);
        if (length != -1) {
            headers.setContentLength(length);
        }
    }
    return zeroCopy(resource, null, message, hints).orElseGet(() -> {
        Mono<Resource> input = Mono.just(resource);
        DataBufferFactory factory = message.bufferFactory();
        Flux<DataBuffer> body = this.encoder.encode(input, factory, type, resourceMediaType, hints);
        if (logger.isDebugEnabled()) {
            body = body.doOnNext(buffer -> Hints.touchDataBuffer(buffer, hints, logger));
        }
        return message.writeWith(body);
    });
}
Also used : DataBufferFactory(cn.taketoday.core.io.buffer.DataBufferFactory) Resource(cn.taketoday.core.io.Resource) ResourceDecoder(cn.taketoday.core.codec.ResourceDecoder) ZeroCopyHttpOutputMessage(cn.taketoday.http.ZeroCopyHttpOutputMessage) HttpHeaders(cn.taketoday.http.HttpHeaders) ResourceEncoder(cn.taketoday.core.codec.ResourceEncoder) ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) Hints(cn.taketoday.core.codec.Hints) Map(java.util.Map) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) ResourceRegion(cn.taketoday.core.io.ResourceRegion) Publisher(org.reactivestreams.Publisher) ResolvableType(cn.taketoday.core.ResolvableType) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) MimeTypeUtils(cn.taketoday.util.MimeTypeUtils) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) File(java.io.File) HttpRange(cn.taketoday.http.HttpRange) Flux(reactor.core.publisher.Flux) List(java.util.List) ServerHttpRequest(cn.taketoday.http.server.reactive.ServerHttpRequest) Nullable(cn.taketoday.lang.Nullable) HttpLogging(cn.taketoday.http.HttpLogging) MediaTypeFactory(cn.taketoday.http.MediaTypeFactory) Logger(cn.taketoday.logging.Logger) Optional(java.util.Optional) HttpStatus(cn.taketoday.http.HttpStatus) ResourceRegionEncoder(cn.taketoday.core.codec.ResourceRegionEncoder) MediaType(cn.taketoday.http.MediaType) InputStreamResource(cn.taketoday.core.io.InputStreamResource) HttpHeaders(cn.taketoday.http.HttpHeaders) Resource(cn.taketoday.core.io.Resource) InputStreamResource(cn.taketoday.core.io.InputStreamResource) MediaType(cn.taketoday.http.MediaType) DataBufferFactory(cn.taketoday.core.io.buffer.DataBufferFactory) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer)

Aggregations

Logger (cn.taketoday.logging.Logger)34 Test (org.junit.jupiter.api.Test)32 MethodInvocation (org.aopalliance.intercept.MethodInvocation)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 NoOpCache (cn.taketoday.cache.support.NoOpCache)10 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)10 List (java.util.List)4 ResolvableType (cn.taketoday.core.ResolvableType)2 Hints (cn.taketoday.core.codec.Hints)2 ResourceDecoder (cn.taketoday.core.codec.ResourceDecoder)2 ResourceEncoder (cn.taketoday.core.codec.ResourceEncoder)2 ResourceRegionEncoder (cn.taketoday.core.codec.ResourceRegionEncoder)2 DescriptiveResource (cn.taketoday.core.io.DescriptiveResource)2 InputStreamResource (cn.taketoday.core.io.InputStreamResource)2 Resource (cn.taketoday.core.io.Resource)2 ResourceRegion (cn.taketoday.core.io.ResourceRegion)2 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 DataBufferFactory (cn.taketoday.core.io.buffer.DataBufferFactory)2 HttpHeaders (cn.taketoday.http.HttpHeaders)2 HttpLogging (cn.taketoday.http.HttpLogging)2