-
-
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 the problem that deletable extensions created by plugins cannot b…
…e recycled (#4526) #### What type of PR is this? /kind bug /area core /milestone 2.9.x #### What this PR does / why we need it: As I mentioned in <#4519>, some extensions which are deletable cannot be recycled by GC. This PR provides an ability to watch scheme changes and recycles deletable extensions. #### Which issue(s) this PR fixes: Fixes #4519 #### Does this PR introduce a user-facing change? ```release-note 修复因重启后部分可被回收的资源一直处于删除中的状态 ```
- Loading branch information
Showing
3 changed files
with
78 additions
and
8 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
52 changes: 52 additions & 0 deletions
52
application/src/test/java/run/halo/app/extension/gc/GcSynchronizerTest.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,52 @@ | ||
package run.halo.app.extension.gc; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.isA; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import run.halo.app.extension.ExtensionClient; | ||
import run.halo.app.extension.SchemeManager; | ||
import run.halo.app.extension.SchemeWatcherManager; | ||
import run.halo.app.extension.SchemeWatcherManager.SchemeWatcher; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class GcSynchronizerTest { | ||
|
||
@Mock | ||
ExtensionClient client; | ||
|
||
@Mock | ||
SchemeManager schemeManager; | ||
|
||
@Mock | ||
SchemeWatcherManager schemeWatcherManager; | ||
|
||
@InjectMocks | ||
GcSynchronizer synchronizer; | ||
|
||
@Test | ||
void shouldStartNormally() { | ||
synchronizer.start(); | ||
|
||
assertFalse(synchronizer.isDisposed()); | ||
verify(schemeWatcherManager).register(any(SchemeWatcher.class)); | ||
verify(client).watch(isA(GcWatcher.class)); | ||
verify(schemeManager).schemes(); | ||
} | ||
|
||
@Test | ||
void shouldDisposeSuccessfully() { | ||
assertFalse(synchronizer.isDisposed()); | ||
|
||
synchronizer.dispose(); | ||
|
||
assertTrue(synchronizer.isDisposed()); | ||
} | ||
} |