Search in sources :

Example 11 with Logger

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

the class PerformanceMonitorInterceptorTests method testSunnyDayPathLogsPerformanceMetricsCorrectly.

@Test
public void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
    Logger log = mock(Logger.class);
    PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
    interceptor.invokeUnderTrace(mi, log);
    verify(log).trace(anyString());
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 12 with Logger

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

the class PerformanceMonitorInterceptorTests method testExceptionPathStillLogsPerformanceMetricsCorrectly.

@Test
public void testExceptionPathStillLogsPerformanceMetricsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
    given(mi.proceed()).willThrow(new IllegalArgumentException());
    Logger log = mock(Logger.class);
    PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
    assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invokeUnderTrace(mi, log));
    verify(log).trace(anyString());
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(cn.taketoday.logging.Logger) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 13 with Logger

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

the class LoggingCacheErrorHandlerTests method handleClearErrorLogsAppropriateMessage.

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

Example 14 with Logger

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

the class LoggingCacheErrorHandlerTests method handleCacheErrorWithStacktrace.

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

Example 15 with Logger

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

the class LoggingCacheErrorHandlerTests method handlePutCacheErrorLogsAppropriateMessage.

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

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