Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需要java版的MiraiConsole.cancel #1764

Closed
hundun000 opened this issue Dec 27, 2021 · 2 comments
Closed

需要java版的MiraiConsole.cancel #1764

hundun000 opened this issue Dec 27, 2021 · 2 comments
Labels
M 优先级: 主要 s:console 子系统: mirai-console t:problem 类型: 不容易归类为特性或 bug 的综合问题
Milestone

Comments

@hundun000
Copy link
Contributor

hundun000 commented Dec 27, 2021

问题描述

当gradle test运行多个Test时,要求每个Test结束时执行MiraiConsole.cancel,否则会报错Mirai Console is already initialized and is currently running. Run MiraiConsole.cancel to kill old instance before starting another instance.

java编写时,没有找到对应MiraiConsole.cancel的方法。

复现

Test基类:

public abstract class AbstractJConsoleTest {

    MiraiConsoleImplementationTerminal consoleInstance;

    @Before
    public void initializeConsole() {
        consoleInstance = new MiraiConsoleImplementationTerminal();
        MiraiConsoleTerminalLoader.INSTANCE.startAsDaemon(consoleInstance);
    }

    @After
    public void cancelConsole() {
        // need something likes MiraiConsole.cancel in java :
        // consoleInstance.cancel() or MiraiConsoleTerminalLoader.INSTANCE.cancelConsole()
    }

}

具体Test类:

public class JConsoleTestA extends AbstractJConsoleTest {
    @Test
    public void test() {
        // ……
    }
}
public class JConsoleTestB extends AbstractJConsoleTest {
    @Test
    public void test() {
        // ……
    }
}

执行gradle test。JConsoleTestA ,JConsoleTestB 其中一个报错:Mirai Console is already initialized and is currently running. Run MiraiConsole.cancel to kill old instance before starting another instance.

mirai-core 版本

2.8.0

bot-protocol

ANDROID_PHONE

其他组件版本

No response

系统日志

Mirai Console is already initialized and is currently running. Run MiraiConsole.cancel to kill old instance before starting another instance.
java.lang.IllegalStateException: Mirai Console is already initialized and is currently running. Run MiraiConsole.cancel to kill old instance before starting another instance.
	at net.mamoe.mirai.console.MiraiConsoleImplementation$Companion.start(MiraiConsoleImplementation.kt:269)
	at net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader.startAsDaemon(MiraiConsoleTerminalLoader.kt:152)

网络日志

补充信息

No response

@hundun000 hundun000 added the x:question 标签: 需要更多信息 label Dec 27, 2021
@Karlatemp Karlatemp added s:console 子系统: mirai-console t:enhancement 类型: 现有功能上的优化 N 优先级: 一般 labels Dec 27, 2021
@Him188
Copy link
Member

Him188 commented Dec 27, 2021

#1761

@Him188 Him188 added M 优先级: 主要 t:problem 类型: 不容易归类为特性或 bug 的综合问题 and removed t:enhancement 类型: 现有功能上的优化 x:question 标签: 需要更多信息 N 优先级: 一般 labels Dec 27, 2021
@Him188 Him188 added this to the 2.10.0-RC milestone Dec 27, 2021
@Him188
Copy link
Member

Him188 commented Jan 14, 2022

自 2.10 起, Mirai Console 不再是静态. 静态的 PluginManager.INSTANCE 等属性返回一个代理对象, 将调用转发到从 MiraiConsole 实例中的 pluginManager 等属性获取到的真实实例.

Java 可以调用 CoroutineScopeKt.cancel(consoleInstance, null) 来关闭 MiraiConsole.

@Him188 Him188 closed this as completed Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M 优先级: 主要 s:console 子系统: mirai-console t:problem 类型: 不容易归类为特性或 bug 的综合问题
Projects
None yet
Development

No branches or pull requests

3 participants