|
| 1 | +/** |
| 2 | + * Copyright 2017-2019 The OpenTracing Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | +package io.opentracing.contrib.spring.cloud.async; |
| 15 | + |
| 16 | +import io.opentracing.contrib.spring.cloud.MockTracingConfiguration; |
| 17 | +import io.opentracing.contrib.spring.cloud.async.instrument.TracedAsyncConfigurer; |
| 18 | +import java.util.concurrent.Executor; |
| 19 | +import org.assertj.core.api.BDDAssertions; |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.runner.RunWith; |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.boot.test.context.SpringBootTest; |
| 24 | +import org.springframework.context.annotation.Configuration; |
| 25 | +import org.springframework.scheduling.annotation.AsyncConfigurer; |
| 26 | +import org.springframework.scheduling.annotation.AsyncConfigurerSupport; |
| 27 | +import org.springframework.scheduling.annotation.EnableAsync; |
| 28 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 29 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +/** |
| 35 | + * @Author wuyupeng |
| 36 | + **/ |
| 37 | +@SpringBootTest(classes = {AsyncConfigurerTest.AsyncConfigurerConfig.class, MockTracingConfiguration.class, CustomAsyncConfigurerAutoConfiguration.class}) |
| 38 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 39 | +public class AsyncConfigurerTest { |
| 40 | + |
| 41 | + @Autowired |
| 42 | + private AsyncConfigurer asyncConfigurer; |
| 43 | + |
| 44 | + |
| 45 | + @Configuration |
| 46 | + @EnableAsync |
| 47 | + static class AsyncConfigurerConfig extends AsyncConfigurerSupport { |
| 48 | + @Override |
| 49 | + public Executor getAsyncExecutor() { |
| 50 | + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 51 | + executor.initialize(); |
| 52 | + return executor; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Test if the AsyncConfigurer configured by developer can be replaced with TracedAsyncConfigurer by CustomAsyncConfigurerAutoConfiguration |
| 58 | + */ |
| 59 | + @Test |
| 60 | + public void testIsTracedAsyncConfigurer() { |
| 61 | + BDDAssertions.then(asyncConfigurer).isInstanceOf(TracedAsyncConfigurer.class); |
| 62 | + } |
| 63 | +} |
0 commit comments