Merge branch '2.1.x'

This commit is contained in:
Marcin Grzejszczak
2019-11-20 13:26:06 +01:00
2 changed files with 52 additions and 1 deletions

View File

@@ -73,7 +73,17 @@ final class SpanSubscriptionProvider<T> implements Supplier<SpanSubscription<T>>
private Tracing tracing() {
if (this.tracing == null) {
this.tracing = this.beanFactory.getBean(Tracing.class);
try {
this.tracing = this.beanFactory.getBean(Tracing.class);
}
catch (Exception ex) {
if (log.isDebugEnabled()) {
log.debug(
"Exception occurred while trying to get the tracing bean. Will return a default instance",
ex);
}
return Tracing.newBuilder().build();
}
}
return this.tracing;
}

View File

@@ -0,0 +1,41 @@
/*
* 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
*
* 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 org.springframework.cloud.sleuth.instrument.reactor;
import org.assertj.core.api.BDDAssertions;
import org.junit.Test;
import org.mockito.BDDMockito;
import reactor.util.context.Context;
import org.springframework.beans.factory.BeanFactory;
public class SpanSubscriptionProviderTests {
@Test
public void should_return_default_tracing_instance_when_exception_thrown_upon_bean_retrieval() {
BeanFactory beanFactory = BDDMockito.mock(BeanFactory.class);
BDDMockito.when(beanFactory.getBean(BDDMockito.any(Class.class)))
.thenThrow(new IllegalStateException());
SpanSubscriptionProvider provider = new SpanSubscriptionProvider(beanFactory,
null, Context.empty(), "example");
SpanSubscription spanSubscription = provider.get();
BDDAssertions.then(spanSubscription).isNotNull();
}
}