From 6f9b66cb6f5fb28d3d3a271ad4e7a3941e750a28 Mon Sep 17 00:00:00 2001 From: acgist <289547414@qq.com> Date: Tue, 18 Jul 2023 08:24:44 +0800 Subject: [PATCH] =?UTF-8?q?[*]=20=E6=97=A5=E5=B8=B8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- taoyao-signal-server/pom.xml | 524 +++++++++--------- .../acgist/taoyao/boot/utils/NetUtils.java | 12 +- taoyao-signal-server/taoyao-server/pom.xml | 74 +-- .../TaoyaoAutoConfiguration.java | 36 +- .../taoyao/controller/ConfigController.java | 54 +- .../taoyao/controller/ControlController.java | 55 +- .../taoyao/controller/PlatformController.java | 6 +- .../taoyao/controller/SystemController.java | 6 +- .../interceptor/SecurityInterceptor.java | 173 +++--- .../taoyao/interceptor/SlowInterceptor.java | 81 ++- .../acgist/taoyao/main/TaoyaoApplication.java | 6 +- .../src/main/resources/static/index.html | 16 +- .../acgist/taoyao/annotation/CostedTest.java | 48 +- .../CostedTestTestExecutionListener.java | 84 +-- .../acgist/taoyao/annotation/TaoyaoTest.java | 4 +- .../java/com/acgist/taoyao/rtp/RtpTest.java | 190 +++---- .../acgist/taoyao/service/IdServiceTest.java | 50 +- 17 files changed, 720 insertions(+), 699 deletions(-) diff --git a/taoyao-signal-server/pom.xml b/taoyao-signal-server/pom.xml index 63267d9..0e45626 100644 --- a/taoyao-signal-server/pom.xml +++ b/taoyao-signal-server/pom.xml @@ -1,282 +1,282 @@ - 4.0.0 + 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.1.0 - - + + org.springframework.boot + spring-boot-starter-parent + 3.1.0 + + - com.acgist - taoyao - 1.0.0 - pom + com.acgist + taoyao + 1.0.0 + pom - https://gitee.com/acgist/taoyao - taoyao - 桃夭:桃夭是套基于`Mediasoup`开发的`WebRTC`音视频信令服务,可以非常方便的扩展信令接入更多智能终端。 - 2022 + https://gitee.com/acgist/taoyao + taoyao + 桃夭:桃夭是套基于`Mediasoup`开发的`WebRTC`音视频信令服务,可以非常方便的扩展信令接入更多智能终端。 + 2022 - - - 17 - 1.18.28 - 2.1.0 - 1.5.5.Final - - ${project.basedir} - UTF-8 - true - + + + 17 + 1.18.28 + 2.1.0 + 1.5.5.Final + + ${project.basedir} + UTF-8 + true + - - taoyao-boot - taoyao-signal - taoyao-server - + + taoyao-boot + taoyao-signal + taoyao-server + - - - - org.mapstruct - mapstruct - - - org.mapstruct - mapstruct-processor - - - org.projectlombok - lombok - - - - org.apache.commons - commons-lang3 - - - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - - - - org.springframework.boot - spring-boot-starter-aop - - - - org.springframework.boot - spring-boot-starter-logging - - - - - org.springframework.boot - spring-boot-starter-test - test - - + + + + org.mapstruct + mapstruct + + + org.mapstruct + mapstruct-processor + + + org.projectlombok + lombok + + + + org.apache.commons + commons-lang3 + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-test + test + + - - - - com.acgist - taoyao-boot - ${project.version} - - - com.acgist - taoyao-signal - ${project.version} - - - com.acgist - taoyao-server - ${project.version} - - - - org.mapstruct - mapstruct - ${mapstruct.version} - provided - - - org.mapstruct - mapstruct-processor - ${mapstruct.version} - provided - - - - org.projectlombok - lombok - ${lombok.version} - provided - - - + + + + com.acgist + taoyao-boot + ${project.version} + + + com.acgist + taoyao-signal + ${project.version} + + + com.acgist + taoyao-server + ${project.version} + + + + org.mapstruct + mapstruct + ${mapstruct.version} + provided + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + provided + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + - - - - src/main/resources - - **/*.yml - **/*.properties - - true - - - src/main/resources - - - - **/*.* - - - **/*.yml - **/*.properties - - false - - + + + + src/main/resources + + **/*.yml + **/*.properties + + true + + + src/main/resources + + + + **/*.* + + + **/*.yml + **/*.properties + + false + + - - - org.apache.maven.plugins - maven-compiler-plugin - - + + + org.apache.maven.plugins + maven-compiler-plugin + + - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - ${taoyao.maven.encoding} - - - - org.apache.maven.plugins - maven-jar-plugin - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + ${taoyao.maven.encoding} + + + + org.apache.maven.plugins + maven-jar-plugin + + + *.cer *.jks *.p12 *.pfx - *.yml - *.properties - - - - - ../config/ - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - assembly - package - - single - - - false - ${taoyao.maven.skip.assembly} - false - - - - - - - + *.yml + *.properties + + + + + ../config/ + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assembly + package + + single + + + false + ${taoyao.maven.skip.assembly} + false + + + + + + + - - - dev - - true - - - dev - - -Xms512M -Xmx1024M -XX:NewRatio=1 -XX:SurvivorRatio=2 - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - ${taoyao.maven.basedir}/docs/assembly/dev.xml - - - - - - - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - ${springdoc.version} - - - - - - prd - - prd - - -Xms2048M -Xmx4096M -XX:NewRatio=1 -XX:SurvivorRatio=2 - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - ${taoyao.maven.basedir}/docs/assembly/prd.xml - - - - - - - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - ${springdoc.version} - provided - - - - - + + + dev + + true + + + dev + + -Xms512M -Xmx1024M -XX:NewRatio=1 -XX:SurvivorRatio=2 + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${taoyao.maven.basedir}/docs/assembly/dev.xml + + + + + + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + + + prd + + prd + + -Xms2048M -Xmx4096M -XX:NewRatio=1 -XX:SurvivorRatio=2 + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${taoyao.maven.basedir}/docs/assembly/prd.xml + + + + + + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + provided + + + + + \ No newline at end of file diff --git a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/NetUtils.java b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/NetUtils.java index 1541bd7..4b36a87 100644 --- a/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/NetUtils.java +++ b/taoyao-signal-server/taoyao-boot/src/main/java/com/acgist/taoyao/boot/utils/NetUtils.java @@ -118,8 +118,11 @@ public final class NetUtils { final InetAddress clientAddress = NetUtils.realAddress(clientIP); final boolean sourceLocal = NetUtils.localAddress(sourceAddress); final boolean clientLocal = NetUtils.localAddress(clientAddress); - // 内网服务 && 内网设备 + // 内网服务 && 内网设备 => 重写服务地址 if(sourceLocal && clientLocal) { + if(NetUtils.subnetIP(sourceIP, clientIP)) { + return sourceIP; + } final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream() .filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP)) .findFirst() @@ -127,11 +130,10 @@ public final class NetUtils { if(rule == null) { return sourceIP; } - log.debug("地址重写:{} - {} - {}", sourceIP, clientIP, rule.getNetwork()); - // 明确配置 if(StringUtils.isNotEmpty(rule.getInnerHost())) { return rule.getInnerHost(); } + log.debug("地址重写:{} - {} - {}", sourceIP, clientIP, rule.getNetwork()); // 地址 = 网络号 + 主机号 final byte[] sourceBytes = sourceAddress.getAddress(); final byte[] clientBytes = clientAddress.getAddress(); @@ -151,7 +153,7 @@ public final class NetUtils { return InetAddress.getByAddress(bytes).getHostAddress(); } } - // 内网服务 && 公网设备 + // 内网服务 && 公网设备 => 公网服务地址 if(sourceLocal && !clientLocal) { final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream() .filter(v -> NetUtils.subnetIP(v.getNetwork(), sourceIP)) @@ -164,7 +166,7 @@ public final class NetUtils { return rule.getOuterHost(); } } - // 公网服务 && 内网设备 + // 公网服务 && 内网设备 => 内网服务地址 if(!sourceLocal && clientLocal) { final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream() .filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP)) diff --git a/taoyao-signal-server/taoyao-server/pom.xml b/taoyao-signal-server/taoyao-server/pom.xml index 8a7dbd2..06e6f2a 100644 --- a/taoyao-signal-server/taoyao-server/pom.xml +++ b/taoyao-signal-server/taoyao-server/pom.xml @@ -2,52 +2,52 @@ - 4.0.0 + 4.0.0 - - com.acgist - taoyao - 1.0.0 - + + com.acgist + taoyao + 1.0.0 + - taoyao-server - jar + taoyao-server + jar - taoyao-server - 启动服务 + taoyao-server + 启动服务 - - ${project.parent.basedir} - false - + + ${project.parent.basedir} + false + - - - com.acgist - taoyao-signal - + + + com.acgist + taoyao-signal + org.hibernate.validator hibernate-validator - + - - - - org.apache.maven.plugins - maven-jar-plugin - - - - com.acgist.taoyao.main.TaoyaoApplication - true - ./ - - - - - - + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.acgist.taoyao.main.TaoyaoApplication + true + ./ + + + + + + \ No newline at end of file diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/configuration/TaoyaoAutoConfiguration.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/configuration/TaoyaoAutoConfiguration.java index 04bd149..e717b82 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/configuration/TaoyaoAutoConfiguration.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/configuration/TaoyaoAutoConfiguration.java @@ -22,29 +22,29 @@ import com.acgist.taoyao.signal.service.impl.SecurityServiceImpl; @AutoConfiguration public class TaoyaoAutoConfiguration { - @Bean - @ConditionalOnMissingBean - public SlowInterceptor slowInterceptor(TaoyaoProperties taoyaoProperties) { - return new SlowInterceptor(taoyaoProperties); - } - + @Bean + @ConditionalOnMissingBean + public SlowInterceptor slowInterceptor(TaoyaoProperties taoyaoProperties) { + return new SlowInterceptor(taoyaoProperties); + } + @Bean @ConditionalOnMissingBean public SecurityService securityService( - SecurityProperties securityProperties, + @Autowired(required = true) SecurityProperties securityProperties, @Autowired(required = false) UsernamePasswordService usernamePasswordService ) { return new SecurityServiceImpl(securityProperties, usernamePasswordService); } - - @Bean - @ConditionalOnProperty(prefix = "taoyao.security", name = "enabled", havingValue = "true", matchIfMissing = true) - @ConditionalOnMissingBean - public SecurityInterceptor securityInterceptor( - SecurityService securityService, - SecurityProperties securityProperties - ) { - return new SecurityInterceptor(securityService, securityProperties); - } - + + @Bean + @ConditionalOnProperty(prefix = "taoyao.security", name = "enabled", havingValue = "true", matchIfMissing = true) + @ConditionalOnMissingBean + public SecurityInterceptor securityInterceptor( + SecurityService securityService, + SecurityProperties securityProperties + ) { + return new SecurityInterceptor(securityService, securityProperties); + } + } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ConfigController.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ConfigController.java index a1568df..8d58bae 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ConfigController.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ConfigController.java @@ -5,8 +5,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.acgist.taoyao.boot.config.FfmpegProperties; -import com.acgist.taoyao.boot.config.RewriteProperties; import com.acgist.taoyao.boot.config.MediaProperties; +import com.acgist.taoyao.boot.config.RewriteProperties; import com.acgist.taoyao.boot.config.SocketProperties; import com.acgist.taoyao.boot.config.WebrtcProperties; import com.acgist.taoyao.boot.model.Message; @@ -29,18 +29,18 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class ConfigController { - private final MediaProperties mediaProperties; - private final FfmpegProperties ffmpegProperties; - private final SocketProperties socketProperties; - private final WebrtcProperties webrtcProperties; - private final RewriteProperties rewriteProperties; - + private final MediaProperties mediaProperties; + private final FfmpegProperties ffmpegProperties; + private final SocketProperties socketProperties; + private final WebrtcProperties webrtcProperties; + private final RewriteProperties rewriteProperties; + @Operation(summary = "媒体配置", description = "媒体配置") - @GetMapping("/media") - @ApiResponse(content = @Content(schema = @Schema(implementation = MediaProperties.class))) - public Message media() { - return Message.success(this.mediaProperties); - } + @GetMapping("/media") + @ApiResponse(content = @Content(schema = @Schema(implementation = MediaProperties.class))) + public Message media() { + return Message.success(this.mediaProperties); + } @Operation(summary = "FFmpeg配置", description = "FFmpeg配置") @GetMapping("/ffmpeg") @@ -55,19 +55,19 @@ public class ConfigController { public Message socket() { return Message.success(this.socketProperties); } - - @Operation(summary = "WebRTC配置", description = "WebRTC配置") - @GetMapping("/webrtc") - @ApiResponse(content = @Content(schema = @Schema(implementation = WebrtcProperties.class))) - public Message webrtc() { - return Message.success(this.webrtcProperties); - } - - @Operation(summary = "地址重写配置", description = "地址重写配置") - @GetMapping("/rewrite") - @ApiResponse(content = @Content(schema = @Schema(implementation = WebrtcProperties.class))) - public Message rewrite() { - return Message.success(this.rewriteProperties); - } - + + @Operation(summary = "WebRTC配置", description = "WebRTC配置") + @GetMapping("/webrtc") + @ApiResponse(content = @Content(schema = @Schema(implementation = WebrtcProperties.class))) + public Message webrtc() { + return Message.success(this.webrtcProperties); + } + + @Operation(summary = "地址重写配置", description = "地址重写配置") + @GetMapping("/rewrite") + @ApiResponse(content = @Content(schema = @Schema(implementation = WebrtcProperties.class))) + public Message rewrite() { + return Message.success(this.rewriteProperties); + } + } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ControlController.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ControlController.java index 4422ab9..4417123 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ControlController.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/ControlController.java @@ -17,6 +17,7 @@ import com.acgist.taoyao.signal.protocol.control.IControlPhotographProtocol; import com.acgist.taoyao.signal.protocol.control.IControlServerRecordProtocol; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -34,31 +35,22 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class ControlController { - private final IControlBellProtocol controlBellProtocol; - private final IControlPhotographProtocol controlPhotographProtocol; - private final IControlConfigAudioProtocol controlConfigAudioProtocol; - private final IControlConfigVideoProtocol controlConfigVideoProtocol; + private final IControlBellProtocol controlBellProtocol; + private final IControlPhotographProtocol controlPhotographProtocol; + private final IControlConfigAudioProtocol controlConfigAudioProtocol; + private final IControlConfigVideoProtocol controlConfigVideoProtocol; private final IControlClientRecordProtocol controlClientRecordProtocol; private final IControlServerRecordProtocol controlServerRecordProtocol; @Operation(summary = "响铃", description = "响铃控制") @GetMapping("/bell/{clientId}") - public Message bell(@PathVariable String clientId, @NotNull(message = "没有指定操作状态") Boolean enabled) { + public Message bell( + @PathVariable String clientId, + @NotNull(message = "没有指定操作状态") Boolean enabled + ) { return this.controlBellProtocol.execute(clientId, enabled); } - @Operation(summary = "录像", description = "终端录像控制") - @GetMapping("/client/record/{clientId}") - public Message record(@PathVariable String clientId, @NotNull(message = "没有指定操作状态") Boolean enabled) { - return this.controlClientRecordProtocol.execute(clientId, enabled); - } - - @Operation(summary = "录像", description = "服务端录像控制") - @GetMapping("/server/record/{roomId}/{clientId}") - public Message record(@PathVariable String roomId, @PathVariable String clientId, @NotNull(message = "没有指定操作状态") Boolean enabled) { - return this.controlServerRecordProtocol.execute(roomId, clientId, enabled); - } - @Operation(summary = "拍照", description = "拍照控制") @GetMapping("/photograph/{clientId}") public Message photograph(@PathVariable String clientId) { @@ -67,14 +59,39 @@ public class ControlController { @Operation(summary = "配置音频", description = "配置音频") @GetMapping("/config/audio/{clientId}") - public Message configAudio(@PathVariable String clientId, @Valid MediaAudioProperties mediaAudioProperties) { + public Message configAudio( + @PathVariable String clientId, + @Valid @RequestBody MediaAudioProperties mediaAudioProperties + ) { return this.controlConfigAudioProtocol.execute(clientId, mediaAudioProperties); } @Operation(summary = "配置视频", description = "配置视频") @GetMapping("/config/video/{clientId}") - public Message configVideo(@PathVariable String clientId, @Valid MediaVideoProperties mediaVideoProperties) { + public Message configVideo( + @PathVariable String clientId, + @Valid @RequestBody MediaVideoProperties mediaVideoProperties + ) { return this.controlConfigVideoProtocol.execute(clientId, mediaVideoProperties); } + @Operation(summary = "录像", description = "终端录像控制") + @GetMapping("/client/record/{clientId}") + public Message record( + @PathVariable String clientId, + @NotNull(message = "没有指定操作状态") Boolean enabled + ) { + return this.controlClientRecordProtocol.execute(clientId, enabled); + } + + @Operation(summary = "录像", description = "服务端录像控制") + @GetMapping("/server/record/{roomId}/{clientId}") + public Message record( + @PathVariable String roomId, + @PathVariable String clientId, + @NotNull(message = "没有指定操作状态") Boolean enabled + ) { + return this.controlServerRecordProtocol.execute(roomId, clientId, enabled); + } + } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/PlatformController.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/PlatformController.java index 77cd0ee..b64a1e7 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/PlatformController.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/PlatformController.java @@ -25,14 +25,14 @@ import io.swagger.v3.oas.annotations.tags.Tag; @RequestMapping("/platform") public class PlatformController { - private final PlatformRebootProtocol platformRebootProtocol; + private final PlatformRebootProtocol platformRebootProtocol; private final PlatformShutdownProtocol platformShutdownProtocol; public PlatformController( - @Autowired(required = false) PlatformRebootProtocol platformRebootProtocol, + @Autowired(required = false) PlatformRebootProtocol platformRebootProtocol, @Autowired(required = false) PlatformShutdownProtocol platformShutdownProtocol ) { - this.platformRebootProtocol = platformRebootProtocol; + this.platformRebootProtocol = platformRebootProtocol; this.platformShutdownProtocol = platformShutdownProtocol; } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/SystemController.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/SystemController.java index 198be38..5e4b074 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/SystemController.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/controller/SystemController.java @@ -25,14 +25,14 @@ import io.swagger.v3.oas.annotations.tags.Tag; @RequestMapping("/system") public class SystemController { - private final SystemRebootProtocol systemRebootProtocol; + private final SystemRebootProtocol systemRebootProtocol; private final SystemShutdownProtocol systemShutdownProtocol; public SystemController( - @Autowired(required = false) SystemRebootProtocol systemRebootProtocol, + @Autowired(required = false) SystemRebootProtocol systemRebootProtocol, @Autowired(required = false) SystemShutdownProtocol systemShutdownProtocol ) { - this.systemRebootProtocol = systemRebootProtocol; + this.systemRebootProtocol = systemRebootProtocol; this.systemShutdownProtocol = systemShutdownProtocol; } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SecurityInterceptor.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SecurityInterceptor.java index 1b24e61..c6febb0 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SecurityInterceptor.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SecurityInterceptor.java @@ -24,96 +24,99 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class SecurityInterceptor extends InterceptorAdapter { - private final SecurityService securityService; - private final SecurityProperties securityProperties; - - /** - * 鉴权信息 - */ - private final String authenticate; - /** - * 地址匹配 - */ - private final AntPathMatcher matcher; - - public SecurityInterceptor(SecurityService securityService, SecurityProperties securityProperties) { + private final SecurityService securityService; + private final SecurityProperties securityProperties; + + /** + * 鉴权信息 + */ + private final String authenticate; + /** + * 地址匹配 + */ + private final AntPathMatcher matcher; + + public SecurityInterceptor( + SecurityService securityService, + SecurityProperties securityProperties + ) { this.securityService = securityService; this.securityProperties = securityProperties; this.authenticate = "Basic Realm=\"" + this.securityProperties.getRealm() + "\""; this.matcher = new AntPathMatcher(); log.info("安全拦截密码:{}", securityProperties.getPassword()); } - - @Override - public String name() { - return "安全拦截器"; - } - - @Override - public String[] pathPattern() { - return new String[] { "/**" }; - } + + @Override + public String name() { + return "安全拦截器"; + } + + @Override + public String[] pathPattern() { + return new String[] { "/**" }; + } - @Override - public int getOrder() { - return Integer.MIN_VALUE + 1; - } - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - if(this.permit(request) || this.authorization(request)) { - return true; - } - if(log.isDebugEnabled()) { - log.debug("授权失败:{}", request.getRequestURL()); - } - response.setStatus(HttpStatus.UNAUTHORIZED.value()); - response.setHeader(HttpHeaders.WWW_AUTHENTICATE, this.authenticate); - return false; - } - - /** - * @param request 请求 - * - * @return 是否许可请求 - */ - private boolean permit(HttpServletRequest request) { - final String uri = request.getRequestURI(); - final String[] permit = this.securityProperties.getPermit(); - if(ArrayUtils.isEmpty(permit)) { - return false; - } - for (String pattern : permit) { - if(this.matcher.match(pattern, uri)) { - return true; - } - } - return false; - } - - /** - * @param request 请求 - * - * @return 是否授权成功 - */ - private boolean authorization(HttpServletRequest request) { - String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); - if(StringUtils.isEmpty(authorization)) { - return false; - } - int index = authorization.indexOf(' '); - if(index < 0) { - return false; - } - authorization = authorization.substring(index + 1).strip(); - authorization = new String(Base64.getMimeDecoder().decode(authorization)); - index = authorization.indexOf(':'); - if(index < 0) { - return false; - } - final String username = authorization.substring(0, index); - final String password = authorization.substring(index + 1); - return this.securityService.authenticate(username, password); - } - + @Override + public int getOrder() { + return Integer.MIN_VALUE + 1; + } + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + if(this.permit(request) || this.authorization(request)) { + return true; + } + if(log.isDebugEnabled()) { + log.debug("授权失败:{}", request.getRequestURL()); + } + response.setStatus(HttpStatus.UNAUTHORIZED.value()); + response.setHeader(HttpHeaders.WWW_AUTHENTICATE, this.authenticate); + return false; + } + + /** + * @param request 请求 + * + * @return 是否许可请求 + */ + private boolean permit(HttpServletRequest request) { + final String uri = request.getRequestURI(); + final String[] permit = this.securityProperties.getPermit(); + if(ArrayUtils.isEmpty(permit)) { + return false; + } + for (String pattern : permit) { + if(this.matcher.match(pattern, uri)) { + return true; + } + } + return false; + } + + /** + * @param request 请求 + * + * @return 是否授权成功 + */ + private boolean authorization(HttpServletRequest request) { + String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); + if(StringUtils.isEmpty(authorization)) { + return false; + } + int index = authorization.indexOf(' '); + if(index < 0) { + return false; + } + authorization = authorization.substring(index + 1).strip(); + authorization = new String(Base64.getMimeDecoder().decode(authorization)); + index = authorization.indexOf(':'); + if(index < 0) { + return false; + } + final String username = authorization.substring(0, index); + final String password = authorization.substring(index + 1); + return this.securityService.authenticate(username, password); + } + } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SlowInterceptor.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SlowInterceptor.java index 6497e42..0766b6e 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SlowInterceptor.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/interceptor/SlowInterceptor.java @@ -14,48 +14,47 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j public class SlowInterceptor extends InterceptorAdapter { - - private final TaoyaoProperties taoyaoProperties; - - /** - * 请求开始时间 - */ - private final ThreadLocal local; - - public SlowInterceptor(TaoyaoProperties taoyaoProperties) { + + private final TaoyaoProperties taoyaoProperties; + + /** + * 请求开始时间 + */ + private final ThreadLocal local; + + public SlowInterceptor(TaoyaoProperties taoyaoProperties) { this.taoyaoProperties = taoyaoProperties; this.local = new ThreadLocal<>(); } - - @Override - public String name() { - return "过慢请求拦截器"; - } - - @Override - public String[] pathPattern() { - return new String[] { "/**" }; - } - - @Override - public int getOrder() { - return Integer.MIN_VALUE; - } - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - this.local.set(System.currentTimeMillis()); - return true; - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception { - final long duration; - final Long last = this.local.get(); - if(last != null && (duration = System.currentTimeMillis() - last) > this.taoyaoProperties.getTimeout()) { - log.info("请求执行时间过慢:{} - {}", request.getRequestURI(), duration); - } - this.local.remove(); - } - + + @Override + public String name() { + return "过慢请求拦截器"; + } + + @Override + public String[] pathPattern() { + return new String[] { "/**" }; + } + + @Override + public int getOrder() { + return Integer.MIN_VALUE; + } + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + this.local.set(System.currentTimeMillis()); + return true; + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception { + final long duration = System.currentTimeMillis() - this.local.get(); + if(duration > this.taoyaoProperties.getTimeout()) { + log.info("请求执行时间过慢:{} - {}", request.getRequestURI(), duration); + } + this.local.remove(); + } + } diff --git a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/main/TaoyaoApplication.java b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/main/TaoyaoApplication.java index 80f28f7..b4b1b6e 100644 --- a/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/main/TaoyaoApplication.java +++ b/taoyao-signal-server/taoyao-server/src/main/java/com/acgist/taoyao/main/TaoyaoApplication.java @@ -8,8 +8,8 @@ import org.springframework.context.annotation.ComponentScan; @SpringBootApplication public class TaoyaoApplication { - public static void main(String[] args) { - SpringApplication.run(TaoyaoApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(TaoyaoApplication.class, args); + } } diff --git a/taoyao-signal-server/taoyao-server/src/main/resources/static/index.html b/taoyao-signal-server/taoyao-server/src/main/resources/static/index.html index 415d78a..51195b5 100644 --- a/taoyao-signal-server/taoyao-server/src/main/resources/static/index.html +++ b/taoyao-signal-server/taoyao-server/src/main/resources/static/index.html @@ -1,15 +1,15 @@ - - 桃夭信令服务 - + + 桃夭信令服务 + -

taoyao-signal-server

-

acgist

+

taoyao-signal-server

+

acgist

\ No newline at end of file diff --git a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTest.java b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTest.java index a04a40d..fa239b6 100644 --- a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTest.java +++ b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTest.java @@ -19,29 +19,29 @@ import java.util.concurrent.TimeUnit; @Documented public @interface CostedTest { - /** - * @return 执行次数 - */ - int count() default 1; + /** + * @return 执行次数 + */ + int count() default 1; - /** - * @return 线程数量 - */ - int thread() default 1; - - /** - * @return 超时时间 - */ - long timeout() default 1000L; - - /** - * @return 等待资源释放时间 - */ - long waitRelease() default 0L; - - /** - * @return 超时时间单位 - */ - TimeUnit timeUnit() default TimeUnit.MILLISECONDS; - + /** + * @return 线程数量 + */ + int thread() default 1; + + /** + * @return 超时时间 + */ + long timeout() default 1000L; + + /** + * @return 等待资源释放时间 + */ + long waitRelease() default 0L; + + /** + * @return 超时时间单位 + */ + TimeUnit timeUnit() default TimeUnit.MILLISECONDS; + } diff --git a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTestTestExecutionListener.java b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTestTestExecutionListener.java index 7ca6c6e..7015935 100644 --- a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTestTestExecutionListener.java +++ b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/CostedTestTestExecutionListener.java @@ -18,46 +18,46 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j public class CostedTestTestExecutionListener implements TestExecutionListener { - - @Override - public void afterTestMethod(TestContext testContext) throws Exception { - final CostedTest costedTest = testContext.getTestMethod().getDeclaredAnnotation(CostedTest.class); - if(costedTest == null) { - return; - } - final int count = costedTest.count(); - final int thread = costedTest.thread(); - final long timeout = costedTest.timeout(); - final TimeUnit timeUnit = costedTest.timeUnit(); - final long aTime = System.currentTimeMillis(); - if(thread == 1) { - for (int index = 0; index < count; index++) { - testContext.getTestMethod().invoke(testContext.getTestInstance()); - } - } else { - final CountDownLatch countDownLatch = new CountDownLatch(count); - final ExecutorService executor = Executors.newFixedThreadPool(thread); - for (int index = 0; index < count; index++) { - executor.execute(() -> { - try { - testContext.getTestMethod().invoke(testContext.getTestInstance()); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - log.error("多线程测试异常", e); - } finally { - countDownLatch.countDown(); - } - }); - } - countDownLatch.await(timeout, timeUnit); - executor.shutdown(); - } - final long zTime = System.currentTimeMillis(); - final long costed = zTime - aTime; - log.info("多线程测试消耗时间:{}", costed); - final long waitRelease = costedTest.waitRelease(); - if(waitRelease > 0) { - Thread.sleep(waitRelease); - } - } - + + @Override + public void afterTestMethod(TestContext testContext) throws Exception { + final CostedTest costedTest = testContext.getTestMethod().getDeclaredAnnotation(CostedTest.class); + if(costedTest == null) { + return; + } + final int count = costedTest.count(); + final int thread = costedTest.thread(); + final long timeout = costedTest.timeout(); + final TimeUnit timeUnit = costedTest.timeUnit(); + final long aTime = System.currentTimeMillis(); + if(thread == 1) { + for (int index = 0; index < count; index++) { + testContext.getTestMethod().invoke(testContext.getTestInstance()); + } + } else { + final CountDownLatch countDownLatch = new CountDownLatch(count); + final ExecutorService executor = Executors.newFixedThreadPool(thread); + for (int index = 0; index < count; index++) { + executor.execute(() -> { + try { + testContext.getTestMethod().invoke(testContext.getTestInstance()); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + log.error("多线程测试异常", e); + } finally { + countDownLatch.countDown(); + } + }); + } + countDownLatch.await(timeout, timeUnit); + executor.shutdown(); + } + final long zTime = System.currentTimeMillis(); + final long costed = zTime - aTime; + log.info("多线程测试消耗时间:{}", costed); + final long waitRelease = costedTest.waitRelease(); + if(waitRelease > 0) { + Thread.sleep(waitRelease); + } + } + } diff --git a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/TaoyaoTest.java b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/TaoyaoTest.java index 02b8fda..58c728f 100644 --- a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/TaoyaoTest.java +++ b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/annotation/TaoyaoTest.java @@ -25,7 +25,7 @@ import org.springframework.test.context.TestExecutionListeners.MergeMode; @TestExecutionListeners(listeners = CostedTestTestExecutionListener.class, mergeMode = MergeMode.MERGE_WITH_DEFAULTS) public @interface TaoyaoTest { - @AliasFor(annotation = SpringBootTest.class) - Class[] classes() default {}; + @AliasFor(annotation = SpringBootTest.class) + Class[] classes() default {}; } diff --git a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/rtp/RtpTest.java b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/rtp/RtpTest.java index 3d1fb61..3824dab 100644 --- a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/rtp/RtpTest.java +++ b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/rtp/RtpTest.java @@ -21,99 +21,99 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class RtpTest { - @Test - void testSocket() throws Exception { - final Socket socket = new Socket(); - socket.connect(new InetSocketAddress("127.0.0.1", 9999)); - final InputStream inputStream = socket.getInputStream(); - final OutputStream outputStream = socket.getOutputStream(); - // 随机密码:https://localhost:8888/config/socket - final String secret = "TSFXzB7hcfE=".strip(); - final Cipher encrypt = CipherUtils.buildCipher(Cipher.ENCRYPT_MODE, Encrypt.DES, secret); - final Cipher decrypt = CipherUtils.buildCipher(Cipher.DECRYPT_MODE, Encrypt.DES, secret); - // 接收 - new Thread(() -> { - int length = 0; - short messageLength = 0; - final byte[] bytes = new byte[1024]; - final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); - try { - while((length = inputStream.read(bytes)) >= 0) { - buffer.put(bytes, 0, length); - while(buffer.position() > 0) { - if(messageLength <= 0) { - if(buffer.position() < Short.BYTES) { - // 不够消息长度 - break; - } else { - buffer.flip(); - messageLength = buffer.getShort(); - buffer.compact(); - if(messageLength > 16 * 1024) { - throw MessageCodeException.of("超过最大数据大小:" + messageLength); - } - } - } else { - if(buffer.position() < messageLength) { - // 不够消息长度 - break; - } else { - final byte[] message = new byte[messageLength]; - messageLength = 0; - buffer.flip(); - buffer.get(message); - buffer.compact(); - log.debug("收到消息:{}", new String(decrypt.doFinal(message))); - } - } - } - } - } catch (Exception e) { - log.error("读取异常", e); - } - }).start(); - // 发送 - String line = """ - { - "header":{"v":"1.0.0","id":1215293599999001,"signal":"client::register"}, - "body":{"clientId":"ffmpeg","name":"ffmpeg","clientType":"WEB","battery":100,"charging":true,"username":"taoyao","password":"taoyao"} - } - """; - // {"header":{"v":"1.0.0","id":1215310510002009,"signal":"room::enter"},"body":{"roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9"}} - // {"header":{"v":"1.0.0","id":1215310510002010,"signal":"media::transport::plain"},"body":{"roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9","rtcpMux":false,"comedia":true}} - // {"header":{"v":"1.0.0","id":1215375110006012,"signal":"media::produce"},"body":{"kind":"video","roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9","transportId":"14dc9307-bf9c-4442-a9ad-ce6a97623ef4","appData":{},"rtpParameters":{"codecs":[{"mimeType":"video/vp8","clockRate":90000,"payloadType":102,"rtcpFeedback":[]}],"encodings":[{"ssrc":123123}]}}} - // 音频转为PCM -// ffmpeg.exe -i .\a.m4a -f s16le a.pcm -// ffmpeg.exe -i .\a.m4a -f s16le -ac 2 -ar 8000 a.pcm -// ffplay.exe -ar 48000 -ac 2 -f s16le -i a.pcm - // ffmpeg不支持rtcpMux -// ffmpeg -re -i video.mp4 -c:v vp8 -map 0:0 -f tee "[select=v:f=rtp:ssrc=123123:payload_type=102]rtp://192.168.1.110:40793?rtcpport=47218" -// ffmpeg -re -i video.mp4 -c:v libvpx -map 0:0 -f tee "[select=v:f=rtp:ssrc=123123:payload_type=102]rtp://192.168.1.110:40793?rtcpport=47218" - // 音频视频同时传输 -// ffmpeg -re -i video.mp4 -c:a libopus -vn -f rtp rtp://192.168.1.110:8888 -c:v libx264 -an -f rtp rtp://192.168.1.110:9999 -sdp_file taoyao.sdp -// ffplay -protocol_whitelist "file,rtp,udp" -i taoyao.sdp -// ffmpeg -protocol_whitelist "file,rtp,udp" -i taoyao.sdp taoyao.mp4 - final Scanner scanner = new Scanner(System.in); - do { - if(StringUtils.isEmpty(line)) { - break; - } - try { - final byte[] bytes = line.getBytes(); - final byte[] encryptBytes = encrypt.doFinal(bytes); - final ByteBuffer buffer = ByteBuffer.allocateDirect(Short.BYTES + encryptBytes.length); - buffer.putShort((short) encryptBytes.length); - buffer.put(encryptBytes); - buffer.flip(); - final byte[] message = new byte[buffer.capacity()]; - buffer.get(message); - outputStream.write(message); - } catch (Exception e) { - log.error("发送异常", e); - } - } while((line = scanner.next()) != null); - socket.close(); - scanner.close(); - } - + @Test + void testSocket() throws Exception { + final Socket socket = new Socket(); + socket.connect(new InetSocketAddress("127.0.0.1", 9999)); + final InputStream inputStream = socket.getInputStream(); + final OutputStream outputStream = socket.getOutputStream(); + // 随机密码:https://localhost:8888/config/socket + final String secret = "TSFXzB7hcfE=".strip(); + final Cipher encrypt = CipherUtils.buildCipher(Cipher.ENCRYPT_MODE, Encrypt.DES, secret); + final Cipher decrypt = CipherUtils.buildCipher(Cipher.DECRYPT_MODE, Encrypt.DES, secret); + // 接收 + new Thread(() -> { + int length = 0; + short messageLength = 0; + final byte[] bytes = new byte[1024]; + final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); + try { + while((length = inputStream.read(bytes)) >= 0) { + buffer.put(bytes, 0, length); + while(buffer.position() > 0) { + if(messageLength <= 0) { + if(buffer.position() < Short.BYTES) { + // 不够消息长度 + break; + } else { + buffer.flip(); + messageLength = buffer.getShort(); + buffer.compact(); + if(messageLength > 16 * 1024) { + throw MessageCodeException.of("超过最大数据大小:" + messageLength); + } + } + } else { + if(buffer.position() < messageLength) { + // 不够消息长度 + break; + } else { + final byte[] message = new byte[messageLength]; + messageLength = 0; + buffer.flip(); + buffer.get(message); + buffer.compact(); + log.debug("收到消息:{}", new String(decrypt.doFinal(message))); + } + } + } + } + } catch (Exception e) { + log.error("读取异常", e); + } + }).start(); + // 发送 + String line = """ + { + "header":{"v":"1.0.0","id":1215293599999001,"signal":"client::register"}, + "body":{"clientId":"ffmpeg","name":"ffmpeg","clientType":"WEB","battery":100,"charging":true,"username":"taoyao","password":"taoyao"} + } + """; + // {"header":{"v":"1.0.0","id":1215310510002009,"signal":"room::enter"},"body":{"roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9"}} + // {"header":{"v":"1.0.0","id":1215310510002010,"signal":"media::transport::plain"},"body":{"roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9","rtcpMux":false,"comedia":true}} + // {"header":{"v":"1.0.0","id":1215375110006012,"signal":"media::produce"},"body":{"kind":"video","roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9","transportId":"14dc9307-bf9c-4442-a9ad-ce6a97623ef4","appData":{},"rtpParameters":{"codecs":[{"mimeType":"video/vp8","clockRate":90000,"payloadType":102,"rtcpFeedback":[]}],"encodings":[{"ssrc":123123}]}}} + // 音频转为PCM +// ffmpeg.exe -i .\a.m4a -f s16le a.pcm +// ffmpeg.exe -i .\a.m4a -f s16le -ac 2 -ar 8000 a.pcm +// ffplay.exe -ar 48000 -ac 2 -f s16le -i a.pcm + // ffmpeg不支持rtcpMux +// ffmpeg -re -i video.mp4 -c:v vp8 -map 0:0 -f tee "[select=v:f=rtp:ssrc=123123:payload_type=102]rtp://192.168.1.110:40793?rtcpport=47218" +// ffmpeg -re -i video.mp4 -c:v libvpx -map 0:0 -f tee "[select=v:f=rtp:ssrc=123123:payload_type=102]rtp://192.168.1.110:40793?rtcpport=47218" + // 音频视频同时传输 +// ffmpeg -re -i video.mp4 -c:a libopus -vn -f rtp rtp://192.168.1.110:8888 -c:v libx264 -an -f rtp rtp://192.168.1.110:9999 -sdp_file taoyao.sdp +// ffplay -protocol_whitelist "file,rtp,udp" -i taoyao.sdp +// ffmpeg -protocol_whitelist "file,rtp,udp" -i taoyao.sdp taoyao.mp4 + final Scanner scanner = new Scanner(System.in); + do { + if(StringUtils.isEmpty(line)) { + break; + } + try { + final byte[] bytes = line.getBytes(); + final byte[] encryptBytes = encrypt.doFinal(bytes); + final ByteBuffer buffer = ByteBuffer.allocateDirect(Short.BYTES + encryptBytes.length); + buffer.putShort((short) encryptBytes.length); + buffer.put(encryptBytes); + buffer.flip(); + final byte[] message = new byte[buffer.capacity()]; + buffer.get(message); + outputStream.write(message); + } catch (Exception e) { + log.error("发送异常", e); + } + } while((line = scanner.next()) != null); + socket.close(); + scanner.close(); + } + } diff --git a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/IdServiceTest.java b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/IdServiceTest.java index 952c8e3..2e44668 100644 --- a/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/IdServiceTest.java +++ b/taoyao-signal-server/taoyao-server/src/test/java/com/acgist/taoyao/service/IdServiceTest.java @@ -15,29 +15,29 @@ import lombok.extern.slf4j.Slf4j; //@SpringBootTest(classes = TaoyaoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) class IdServiceTest { - @Autowired - private IdService idService; - - @Test -// @Timeout(value = 1000, unit = TimeUnit.MILLISECONDS) -// @Rollback() -// @RepeatedTest(10) - void testId() { - final long id = this.idService.buildId(); - log.info("生成ID:{}", id); - log.info("生成ID:{}", String.valueOf(id).length()); - } - - @Test - @CostedTest(count = 100000, thread = 10) - void testIdCosted() { - this.idService.buildId(); - } - - @Test - @CostedTest(count = 100000, thread = 10) - void testUuidCosted() { - this.idService.buildUuid(); - } - + @Autowired + private IdService idService; + + @Test +// @Timeout(value = 1000, unit = TimeUnit.MILLISECONDS) +// @Rollback() +// @RepeatedTest(10) + void testId() { + final long id = this.idService.buildId(); + log.info("生成ID:{}", id); + log.info("生成ID:{}", String.valueOf(id).length()); + } + + @Test + @CostedTest(count = 100000, thread = 10) + void testIdCosted() { + this.idService.buildId(); + } + + @Test + @CostedTest(count = 100000, thread = 10) + void testUuidCosted() { + this.idService.buildUuid(); + } + }