Adds test case.
This commit is contained in:
@@ -75,7 +75,9 @@ class TraceLettuceClientResourcesBeanPostProcessor implements BeanPostProcessor
|
||||
throws BeansException {
|
||||
if (bean instanceof ClientResources) {
|
||||
ClientResources cr = (ClientResources) bean;
|
||||
if (cr.tracing() == null) {
|
||||
// tracing of ClientResources instance created by default is `disabled()`
|
||||
if (cr.tracing() == null
|
||||
|| cr.tracing() == io.lettuce.core.tracing.Tracing.disabled()) {
|
||||
return cr.mutate().tracing(BraveTracing.create(this.tracing)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* http://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 org.springframework.cloud.sleuth.instrument.redis;
|
||||
|
||||
import brave.Tracing;
|
||||
import io.lettuce.core.resource.ClientResources;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Chao Chang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TraceRedisAutoConfigurationTests.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class TraceRedisAutoConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
ClientResources clientResources;
|
||||
|
||||
@Autowired
|
||||
TestTraceLettuceClientResourcesBeanPostProcessor traceLettuceClientResourcesBeanPostProcessor;
|
||||
|
||||
@Test
|
||||
public void tracing_should_be_set() {
|
||||
then(this.traceLettuceClientResourcesBeanPostProcessor.tracingCalled).isTrue();
|
||||
then(this.clientResources.tracing()).isNotNull();
|
||||
then(this.clientResources.tracing())
|
||||
.isNotSameAs(io.lettuce.core.tracing.Tracing.disabled());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
protected static class Config {
|
||||
|
||||
@Bean
|
||||
ClientResources clientResources() {
|
||||
ClientResources clientResources = ClientResources.create();
|
||||
then(clientResources.tracing())
|
||||
.isSameAs(io.lettuce.core.tracing.Tracing.disabled());
|
||||
return clientResources;
|
||||
}
|
||||
|
||||
@Bean
|
||||
TestTraceLettuceClientResourcesBeanPostProcessor testTraceLettuceClientResourcesBeanPostProcessor(
|
||||
Tracing tracing) {
|
||||
return new TestTraceLettuceClientResourcesBeanPostProcessor(tracing);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestTraceLettuceClientResourcesBeanPostProcessor
|
||||
extends TraceLettuceClientResourcesBeanPostProcessor {
|
||||
|
||||
boolean tracingCalled = false;
|
||||
|
||||
TestTraceLettuceClientResourcesBeanPostProcessor(Tracing tracing) {
|
||||
super(tracing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
this.tracingCalled = true;
|
||||
return super.postProcessAfterInitialization(bean, beanName);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user