-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cannot stop thread when system is interrupted (#2639)
#### What type of PR is this? /kind bug /kind improvement /area core /milestone 2.0 #### What this PR does / why we need it: 修复 Halo 异常停止时日志服务线程无法中断的问题 #### Special notes for your reviewer: how to test it? 使用 mysql 启动 halo 但不启动 mysql,此时 halo 会无法链接 mysql 期望现象:Halo 服务终止,异常现象:Halo 抛异常但 Netty 服务器不会停止 /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note 修复 Halo 异常停止时日志服务线程无法中断的问题 ```
- Loading branch information
Showing
3 changed files
with
136 additions
and
66 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
53 changes: 53 additions & 0 deletions
53
src/test/java/run/halo/app/metrics/VisitLogWriterTest.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,53 @@ | ||
package run.halo.app.metrics; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.util.FileSystemUtils; | ||
import run.halo.app.infra.properties.HaloProperties; | ||
|
||
/** | ||
* Tests for {@link VisitLogWriter}. | ||
* | ||
* @author guqing | ||
* @since 2.0.0 | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class VisitLogWriterTest { | ||
|
||
@Mock | ||
private HaloProperties haloProperties; | ||
|
||
private VisitLogWriter visitLogWriter; | ||
|
||
private Path workDir; | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
workDir = Files.createTempDirectory("halo-visitlog"); | ||
when(haloProperties.getWorkDir()).thenReturn(workDir); | ||
visitLogWriter = new VisitLogWriter(haloProperties); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws Exception { | ||
visitLogWriter.destroy(); | ||
FileSystemUtils.deleteRecursively(workDir); | ||
} | ||
|
||
@Test | ||
void start() { | ||
assertThat(visitLogWriter.isStarted()).isFalse(); | ||
visitLogWriter.start(); | ||
assertThat(visitLogWriter.isStarted()).isTrue(); | ||
} | ||
} |