mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-16 07:15:16 +01:00
#1874 Output number of loggers in /authme debug stats
This commit is contained in:
parent
363e85e363
commit
e2f2ff0763
@ -8,6 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.HasCleanup;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.permission.DebugSectionPermissions;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -54,6 +55,7 @@ class DataStatistics implements DebugSection {
|
||||
|
||||
outputDatabaseStats(sender);
|
||||
outputInjectorStats(sender);
|
||||
sender.sendMessage("Total logger instances: " + ConsoleLoggerFactory.getTotalLoggers());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,6 +41,10 @@ public final class ConsoleLoggerFactory {
|
||||
.forEach(logger -> logger.initializeSettings(settings));
|
||||
}
|
||||
|
||||
public static int getTotalLoggers() {
|
||||
return consoleLoggers.size();
|
||||
}
|
||||
|
||||
private static ConsoleLogger createLogger(String name) {
|
||||
ConsoleLogger logger = new ConsoleLogger(name);
|
||||
if (settings != null) {
|
||||
|
@ -12,6 +12,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.HasCleanup;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Before;
|
||||
@ -22,7 +23,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -73,6 +73,11 @@ public class DataStatisticsTest {
|
||||
given(dataSource.getAccountsRegistered()).willReturn(219);
|
||||
given(playerCache.getLogged()).willReturn(12);
|
||||
|
||||
// Clear any loggers that might exist and trigger the generation of two loggers
|
||||
Map loggers = ReflectionTestUtils.getFieldValue(ConsoleLoggerFactory.class, null, "consoleLoggers");
|
||||
loggers.clear();
|
||||
ConsoleLoggerFactory.get(String.class);
|
||||
ConsoleLoggerFactory.get(Integer.class);
|
||||
|
||||
// when
|
||||
dataStatistics.execute(sender, Collections.emptyList());
|
||||
@ -86,7 +91,8 @@ public class DataStatisticsTest {
|
||||
"(Reloadable: 4 / SettingsDependent: 3 / HasCleanup: 2)",
|
||||
"LimboPlayers in memory: 1",
|
||||
"Total players in DB: 219",
|
||||
"PlayerCache size: 12 (= logged in players)"));
|
||||
"PlayerCache size: 12 (= logged in players)",
|
||||
"Total logger instances: 2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -110,10 +116,6 @@ public class DataStatisticsTest {
|
||||
|
||||
private static <T> List<T> mockListOfSize(Class<T> mockClass, int size) {
|
||||
T mock = mock(mockClass);
|
||||
List<T> mocks = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
mocks.add(mock);
|
||||
}
|
||||
return mocks;
|
||||
return Collections.nCopies(size, mock);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.junit.Test;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
@ -62,7 +61,7 @@ public class ConsoleLoggerFactoryTest {
|
||||
ConsoleLogger logger3 = ConsoleLoggerFactory.get(String.class);
|
||||
|
||||
// then
|
||||
assertThat(getConsoleLoggerMap().keySet(), containsInAnyOrder("java.lang.String", "java.lang.Number"));
|
||||
assertThat(ConsoleLoggerFactory.getTotalLoggers(), equalTo(2));
|
||||
assertThat(logger3, sameInstance(logger1));
|
||||
assertThat(logger2, not(sameInstance(logger1)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user