-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
135 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/springmvc/SpringMvcAsyncTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.alipay.sofa.tracer.boot.springmvc; | ||
|
||
import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration; | ||
import com.alipay.common.tracer.core.reporter.digest.manager.SofaTracerDigestReporterAsyncManager; | ||
import com.alipay.sofa.tracer.boot.base.AbstractTestBase; | ||
import com.alipay.sofa.tracer.boot.base.controller.SampleRestController; | ||
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcLogEnum; | ||
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcTracer; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.Field; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* SpringMvcFilterTest | ||
* | ||
* @author yangguanchao | ||
* @since 2018/08/31 | ||
*/ | ||
@ActiveProfiles("async") | ||
public class SpringMvcAsyncTest extends AbstractTestBase { | ||
|
||
@Test | ||
public void testAsyncServlet() throws Exception { | ||
//clear log file handler and reoutput | ||
reflectSpringMVCClear(); | ||
//avoid close digest print | ||
SofaTracerConfiguration.setProperty(SofaTracerConfiguration.DISABLE_DIGEST_LOG_KEY, | ||
new HashMap<String, String>()); | ||
assertNotNull(testRestTemplate); | ||
String restUrl = urlHttpPrefix + "/asyncServlet"; | ||
|
||
ResponseEntity<String> response = testRestTemplate.getForEntity(restUrl, String.class); | ||
String greetingResponse = response.getBody(); | ||
assertTrue(greetingResponse.equals(SampleRestController.ASYNC_RESP)); | ||
assertTrue(response.getStatusCode() == HttpStatus.OK); | ||
// http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#boot-features-testing | ||
Thread.sleep(3000); | ||
//wait for async output | ||
List<String> contents = FileUtils.readLines(new File(logDirectoryPath | ||
+ File.separator | ||
+ SpringMvcLogEnum.SPRING_MVC_DIGEST | ||
.getDefaultLogName())); | ||
assertTrue(contents.size() == 1); | ||
} | ||
|
||
private static void reflectSpringMVCClear() throws NoSuchFieldException, IllegalAccessException { | ||
Field field = SpringMvcTracer.class.getDeclaredField("springMvcTracer"); | ||
field.setAccessible(true); | ||
field.set(null, null); | ||
//clear | ||
Field fieldAsync = SofaTracerDigestReporterAsyncManager.class | ||
.getDeclaredField("asyncCommonDigestAppenderManager"); | ||
fieldAsync.setAccessible(true); | ||
fieldAsync.set(null, null); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tracer-sofa-boot-starter/src/test/resources/application-async.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
# | ||
|
||
spring.application.name=SpringMvcAsyncServlet | ||
|
||
#default 60s and now reset to 1 | ||
com.alipay.sofa.tracer.statLogInterval=1 |