Skip to content

Commit 75ffe5d

Browse files
committed
modify: remove unnecessary test
modify: remove Section.java
1 parent a6644e2 commit 75ffe5d

File tree

9 files changed

+58
-331
lines changed

9 files changed

+58
-331
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<kotlin.native>native-mt</kotlin.native>
3434
<command.version>1.3.2</command.version>
3535
<util.version>1.1.18</util.version>
36-
<scheduler.version>1.2.3</scheduler.version>
36+
<scheduler.version>1.2.4</scheduler.version>
3737
<sysout.version>1.0.2</sysout.version>
3838
<socket.version>1.1.0</socket.version>
3939
</properties>

src/main/java/top/focess/qq/api/event/EventManager.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import org.jetbrains.annotations.NotNull;
55
import top.focess.qq.FocessQQ;
66
import top.focess.qq.api.scheduler.Schedulers;
7-
import top.focess.qq.core.debug.Section;
87
import top.focess.qq.core.permission.Permission;
98
import top.focess.qq.core.permission.PermissionEnv;
109
import top.focess.scheduler.Scheduler;
1110
import top.focess.scheduler.Task;
1211

1312
import java.lang.reflect.Field;
1413
import java.lang.reflect.Modifier;
15-
import java.time.Duration;
1614
import java.util.Map;
1715
import java.util.concurrent.CancellationException;
1816
import java.util.concurrent.ExecutionException;
17+
import java.util.concurrent.TimeUnit;
18+
import java.util.concurrent.TimeoutException;
1919

2020
/**
2121
* This class is used to submit Event for developers.
@@ -47,16 +47,13 @@ public static <T extends Event> void submit(final T event) throws EventSubmitExc
4747
throw new EventSubmitRuntimeException(e);
4848
}
4949
}, "submit-" + event.getClass().getName());
50-
final Section section = Section.startSection("event-submit", task, Duration.ofSeconds(10));
5150
try {
52-
task.join();
53-
} catch (final ExecutionException | InterruptedException | CancellationException e) {
54-
section.stop();
51+
task.join(10, TimeUnit.SECONDS);
52+
} catch (final ExecutionException | InterruptedException | CancellationException | TimeoutException e) {
5553
if (e.getCause() instanceof EventSubmitRuntimeException)
5654
throw (EventSubmitException) e.getCause().getCause();
57-
else FocessQQ.getLogger().debugLang("section-exception", section.getName(), e.getMessage());
55+
else FocessQQ.getLogger().thrLang("exception-submit-event",e);
5856
}
59-
section.stop();
6057
}
6158

6259
private static <T extends Event> void submit(@NotNull final Class<T> cls, final T event) throws EventSubmitException {

src/main/java/top/focess/qq/core/debug/Section.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/main/java/top/focess/qq/core/listeners/ChatListener.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
import top.focess.qq.api.event.message.StrangerMessageEvent;
2121
import top.focess.qq.api.scheduler.Schedulers;
2222
import top.focess.qq.api.util.IOHandler;
23-
import top.focess.qq.core.debug.Section;
2423
import top.focess.scheduler.Scheduler;
2524
import top.focess.scheduler.Task;
2625
import top.focess.util.Pair;
2726

28-
import java.time.Duration;
2927
import java.util.List;
3028
import java.util.Map;
3129
import java.util.Queue;
3230
import java.util.concurrent.Future;
31+
import java.util.concurrent.TimeUnit;
3332
import java.util.concurrent.atomic.AtomicBoolean;
3433

3534
public class ChatListener implements Listener {
@@ -98,21 +97,19 @@ public void onGroupChat(@NotNull final GroupChatEvent event) {
9897
try {
9998
final Future<CommandResult> ret = CommandLine.exec(sender, event.getMessage().toString());
10099
EXECUTOR.run(() -> {
101-
final Section section = Section.startSection("command-group-exec", ret, Duration.ofMinutes(10));
102-
try {
103-
if (ret.get() == CommandResult.NONE) {
104-
final GroupMessageEvent groupMessageEvent = new GroupMessageEvent(event.getBot(), event.getMember(), event.getMessage(), event.getSource());
105-
try {
106-
EventManager.submit(groupMessageEvent);
107-
} catch (final Exception e) {
108-
FocessQQ.getLogger().thrLang("exception-submit-group-message-event", e);
109-
}
100+
try {
101+
if (ret.get(10, TimeUnit.MINUTES) == CommandResult.NONE) {
102+
final GroupMessageEvent groupMessageEvent = new GroupMessageEvent(event.getBot(), event.getMember(), event.getMessage(), event.getSource());
103+
try {
104+
EventManager.submit(groupMessageEvent);
105+
} catch (final Exception e) {
106+
FocessQQ.getLogger().thrLang("exception-submit-group-message-event", e);
110107
}
111-
} catch (final Exception e) {
112-
if (!(e.getCause() instanceof InputTimeoutException))
113-
FocessQQ.getLogger().thrLang("exception-exec-group-command", e);
114108
}
115-
section.stop();
109+
} catch (final Exception e) {
110+
if (!(e.getCause() instanceof InputTimeoutException))
111+
FocessQQ.getLogger().thrLang("exception-exec-group-command", e);
112+
}
116113
},"command-group-exec");
117114
} catch (final Exception e) {
118115
FocessQQ.getLogger().thrLang("exception-exec-group-command", e);
@@ -133,21 +130,19 @@ public void onFriendChat(@NotNull final FriendChatEvent event) {
133130
try {
134131
final Future<CommandResult> ret = CommandLine.exec(sender, event.getMessage().toString());
135132
EXECUTOR.run(() -> {
136-
final Section section = Section.startSection("command-friend-exec", ret, Duration.ofMinutes(10));
137-
try {
138-
if (ret.get() == CommandResult.NONE) {
139-
final FriendMessageEvent friendMessageEvent = new FriendMessageEvent(event.getBot(), event.getFriend(), event.getMessage(), event.getSource());
140-
try {
141-
EventManager.submit(friendMessageEvent);
142-
} catch (final Exception e) {
143-
FocessQQ.getLogger().thrLang("exception-submit-friend-message-event", e);
144-
}
133+
try {
134+
if (ret.get(10, TimeUnit.MINUTES) == CommandResult.NONE) {
135+
final FriendMessageEvent friendMessageEvent = new FriendMessageEvent(event.getBot(), event.getFriend(), event.getMessage(), event.getSource());
136+
try {
137+
EventManager.submit(friendMessageEvent);
138+
} catch (final Exception e) {
139+
FocessQQ.getLogger().thrLang("exception-submit-friend-message-event", e);
145140
}
146-
} catch (final Exception e) {
147-
if (!(e.getCause() instanceof InputTimeoutException))
148-
FocessQQ.getLogger().thrLang("exception-exec-friend-command", e);
149141
}
150-
section.stop();
142+
} catch (final Exception e) {
143+
if (!(e.getCause() instanceof InputTimeoutException))
144+
FocessQQ.getLogger().thrLang("exception-exec-friend-command", e);
145+
}
151146
}, "command-friend-exec");
152147
} catch (final Exception e) {
153148
FocessQQ.getLogger().thrLang("exception-exec-friend-command", e);

src/main/java/top/focess/qq/core/listeners/ConsoleListener.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
import top.focess.qq.api.event.message.ConsoleMessageEvent;
1515
import top.focess.qq.api.scheduler.Schedulers;
1616
import top.focess.qq.api.util.IOHandler;
17-
import top.focess.qq.core.debug.Section;
1817
import top.focess.scheduler.Scheduler;
1918
import top.focess.scheduler.Task;
2019
import top.focess.util.Pair;
2120

22-
import java.time.Duration;
2321
import java.util.Queue;
2422
import java.util.concurrent.Future;
23+
import java.util.concurrent.TimeUnit;
2524

2625
public class ConsoleListener implements Listener {
2726

@@ -49,21 +48,19 @@ public void onConsoleChat(final ConsoleChatEvent event) {
4948
try {
5049
final Future<CommandResult> ret = CommandLine.exec(event.getMessage().toString());
5150
EXECUTOR.run(() -> {
52-
final Section section = Section.startSection("command-console-exec", ret, Duration.ofMinutes(10));
53-
try {
54-
if (ret.get() == CommandResult.NONE) {
55-
final ConsoleMessageEvent consoleMessageEvent = new ConsoleMessageEvent(event.getMessage());
56-
try {
57-
EventManager.submit(consoleMessageEvent);
58-
} catch (final Exception e) {
59-
FocessQQ.getLogger().thrLang("exception-submit-console-message-event", e);
60-
}
51+
try {
52+
if (ret.get(10, TimeUnit.MINUTES) == CommandResult.NONE) {
53+
final ConsoleMessageEvent consoleMessageEvent = new ConsoleMessageEvent(event.getMessage());
54+
try {
55+
EventManager.submit(consoleMessageEvent);
56+
} catch (final Exception e) {
57+
FocessQQ.getLogger().thrLang("exception-submit-console-message-event", e);
6158
}
62-
} catch (final Exception e) {
63-
if (!(e.getCause() instanceof InputTimeoutException))
64-
FocessQQ.getLogger().thrLang("exception-exec-console-command", e);
6559
}
66-
section.stop();
60+
} catch (final Exception e) {
61+
if (!(e.getCause() instanceof InputTimeoutException))
62+
FocessQQ.getLogger().thrLang("exception-exec-console-command", e);
63+
}
6764
},"command-console-exec");
6865
} catch (final Exception e) {
6966
FocessQQ.getLogger().thrLang("exception-exec-console-command", e);

src/main/java/top/focess/qq/core/plugin/PluginClassLoader.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import top.focess.qq.api.plugin.*;
2121
import top.focess.qq.api.scheduler.Schedulers;
2222
import top.focess.qq.core.bot.BotManagerFactory;
23-
import top.focess.qq.core.debug.Section;
2423
import top.focess.qq.core.permission.Permission;
2524
import top.focess.qq.core.permission.PermissionEnv;
2625
import top.focess.scheduler.Callback;
@@ -42,6 +41,8 @@
4241
import java.util.*;
4342
import java.util.concurrent.CancellationException;
4443
import java.util.concurrent.ExecutionException;
44+
import java.util.concurrent.TimeUnit;
45+
import java.util.concurrent.TimeoutException;
4546
import java.util.jar.JarEntry;
4647
import java.util.jar.JarFile;
4748

@@ -245,11 +246,9 @@ public static void enablePlugin(@NotNull final Plugin plugin) {
245246
Permission.checkPermission(Permission.ENABLE_PLUGIN);
246247
if (plugin != FocessQQ.getMainPlugin()) {
247248
final Task task = SCHEDULER.run(() -> enablePlugin0(plugin), "enable-plugin-" + plugin.getName());
248-
final Section section = Section.startSection("plugin-enable", task, Duration.ofSeconds(15));
249249
try {
250-
task.join();
251-
} catch (final ExecutionException | InterruptedException | CancellationException e) {
252-
section.stop();
250+
task.join(15, TimeUnit.SECONDS);
251+
} catch (final ExecutionException | InterruptedException | CancellationException | TimeoutException e) {
253252
if (e instanceof ExecutionException)
254253
if (e.getCause() instanceof PluginLoadException)
255254
throw (PluginLoadException) e.getCause();
@@ -258,13 +257,12 @@ else if (e.getCause() instanceof PluginDuplicateException)
258257
else if (e.getCause() instanceof PluginUnloadException)
259258
throw (PluginUnloadException) e.getCause();
260259
else {
261-
FocessQQ.getLogger().debugLang("section-exception", section.getName(), e.getCause().getMessage());
260+
FocessQQ.getLogger().thrLang("exception-enable-plugin", e);
262261
throw new PluginLoadException(plugin.getClass(), e.getCause());
263262
}
264-
else if (!(e instanceof CancellationException))
265-
FocessQQ.getLogger().debugLang("section-exception", section.getName(), e.getMessage());
263+
else if (!(e instanceof TimeoutException))
264+
FocessQQ.getLogger().thrLang("exception-enable-plugin", e);
266265
}
267-
section.stop();
268266
} else
269267
enablePlugin0(plugin);
270268
}
@@ -289,17 +287,15 @@ public static File disablePlugin(final Plugin plugin) {
289287
Permission.checkPermission(Permission.DISABLE_PLUGIN);
290288
if (plugin != FocessQQ.getMainPlugin()) {
291289
final Callback<File> callback = SCHEDULER.submit(() -> disablePlugin0(plugin), "disable-plugin-" + plugin.getName());
292-
final Section section = Section.startSection("plugin-disable", (Task) callback, Duration.ofSeconds(5));
293290
File file = null;
294291
try {
295-
file = callback.waitCall();
296-
} catch (final InterruptedException | ExecutionException | CancellationException e) {
292+
file = callback.get(5, TimeUnit.SECONDS);
293+
} catch (final InterruptedException | ExecutionException | CancellationException | TimeoutException e) {
297294
if (e instanceof ExecutionException && e.getCause() instanceof IncompatibleClassChangeError)
298-
FocessQQ.getLogger().thrLang("exception-section", e, section.getName(), e.getCause().getMessage());
299-
else if (!(e instanceof CancellationException))
300-
FocessQQ.getLogger().debugLang("section-exception", section.getName(), e.getMessage());
295+
FocessQQ.getLogger().thrLang("exception-disable-plugin", e);
296+
else if (!(e instanceof TimeoutException))
297+
FocessQQ.getLogger().thrLang("exception-disable-plugin", e);
301298
}
302-
section.stop();
303299
final String name = plugin.getName();
304300
GC_SCHEDULER.run(System::gc, Duration.ofSeconds(1), name);
305301
return file;

src/main/resources/lang.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fatal-create-cache-dir-failed: Failed to create cache directory %s.
88
fatal-reload-plugin: Failed to reload plugin %s.
99
fatal-read-permissions-config: Failed to read permissions config. Force shutdown!
1010
exception-uncaught-exception: Uncaught exception
11+
exception-submit-event: Submit event exception
1112
exception-submit-console-chat-event: Submit console input event exception
1213
exception-submit-plugin-unload-event: Submit plugin unload event exception
1314
exception-submit-plugin-load-event: Submit plugin load event exception
@@ -78,6 +79,8 @@ exception-load-soft-depend-plugin: Load soft-dependent plugin file %s exception
7879
exception-section: Section %s exception, %s
7980
exception-get-null-caller-class: Get null caller class exception
8081
exception-load-plugin-unexpected-exception: Load plugin with unexpected exception
82+
exception-enable-plugin: Enable plugin exception
83+
exception-disable-plugin: Disable plugin exception
8184
setup-uncaught-exception-handler: Setup uncaught exception handler
8285
setup-shutdown-hook: Setup shutdown hook
8386
start-console-input-thread: Start console input thread
@@ -201,7 +204,6 @@ unregister-all-special-argument-handlers: Unregister all special arguments
201204
register-default-special-argument-handlers: Register default special argument handlers
202205
exec-command-empty-command: The command is empty
203206
exec-command-error-command: Exec cannot execute command named itself
204-
section-exception: Section %s exception, %s
205207
clear-command-sender-session: Clear command sender session with plugin %s
206208
command-line-exec: "CommandLine#exec: %s exec: [%s], ID: %d"
207209
command-pre-exec: "CommandLine#exec0: %s exec: Command: \"%s\", Args: %s, ID: %d"

src/test/java/top/focess/qq/test/TestFramework.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ void testExit() {
236236
}
237237
Field finalField = field;
238238
ListenerHandler listenerHandler = (ListenerHandler) assertDoesNotThrow(()-> finalField.get(null));
239-
assertNotEquals(0,listenerHandler.size());
240-
assertNotEquals(1,AScheduler.getSchedulers().size());
239+
assertNotEquals(0, listenerHandler.size());
240+
assertNotEquals(1, AScheduler.getSchedulers().size());
241241
assertNotEquals(0, Command.getCommands().size());
242242
assertNotEquals(0, Plugin.getPlugins().size());
243243
FocessQQ.exit();

0 commit comments

Comments
 (0)