From ec1ea81f93dc7c701c81270328f01e0c93a8d8d7 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Feb 2018 11:15:37 +0200 Subject: [PATCH] Analysis DB Closed Exception on reload no longer logged. --- .../info/request/GenerateAnalysisPageRequest.java | 8 +++++++- .../plan/system/processing/ProcessingQueue.java | 6 +++++- .../test/java/utilities/mocks/BukkitMockUtil.java | 13 ++++++++++--- Plan/src/test/java/utilities/mocks/MockUtil.java | 4 ++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java index cc2240a35..8790c3a18 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java @@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info.request; import com.djrapitops.plan.api.exceptions.connection.BadRequestException; import com.djrapitops.plan.api.exceptions.connection.InternalErrorException; import com.djrapitops.plan.api.exceptions.connection.WebException; +import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.data.calculation.AnalysisData; import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.database.databases.Database; @@ -83,8 +84,13 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem AnalysisData analysisData = Analysis.runAnalysisFor(serverUUID, db, dataCache); return new AnalysisPage(analysisData).toHtml(); + } catch (DBException e) { + if (!e.getCause().getMessage().contains("Connection is closed")) { + Log.toLog(this.getClass(), e); + } + throw new InternalErrorException("Analysis failed due to exception", e); } catch (Exception e) { - Log.toLog(Analysis.class, e); + Log.toLog(this.getClass(), e); throw new InternalErrorException("Analysis failed due to exception", e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java index f36bedbbd..f46b32f12 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/ProcessingQueue.java @@ -43,7 +43,11 @@ public class ProcessingQueue extends Queue implements SubSystem { List processors = stopAndReturnLeftovers(); Log.info("Processing unprocessed processors. (" + processors.size() + ")"); for (Processor processor : processors) { - processor.process(); + try { + processor.process(); + } catch (Exception e) { + Log.toLog(this.getClass(), e); + } } } diff --git a/Plan/src/test/java/utilities/mocks/BukkitMockUtil.java b/Plan/src/test/java/utilities/mocks/BukkitMockUtil.java index 021f91825..3c447181f 100644 --- a/Plan/src/test/java/utilities/mocks/BukkitMockUtil.java +++ b/Plan/src/test/java/utilities/mocks/BukkitMockUtil.java @@ -8,9 +8,11 @@ import com.djrapitops.plan.Plan; import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.task.ThreadRunnable; +import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.scheduler.BukkitScheduler; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import utilities.Teardown; @@ -22,8 +24,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import static org.mockito.Mockito.doCallRealMethod; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; /** * Mocking Utility for Bukkit version of Plan. @@ -54,6 +55,7 @@ public class BukkitMockUtil extends MockUtil { doCallRealMethod().when(planMock).getVersion(); doCallRealMethod().when(planMock).getColorScheme(); + return this; } @@ -65,7 +67,7 @@ public class BukkitMockUtil extends MockUtil { public BukkitMockUtil withLogging() { doCallRealMethod().when(planMock).log(Mockito.anyString(), Mockito.anyString()); TestLogger testLogger = new TestLogger(); - when(planMock.getLogger()).thenReturn(testLogger); + doReturn(testLogger).when(planMock).getLogger(); return this; } @@ -98,6 +100,11 @@ public class BukkitMockUtil extends MockUtil { FakeConsoleCmdSender sender = new FakeConsoleCmdSender(); when(serverMock.getConsoleSender()).thenReturn(sender); + BukkitScheduler bukkitScheduler = Mockito.mock(BukkitScheduler.class); + doReturn(bukkitScheduler).when(serverMock).getScheduler(); + + Bukkit.setServer(serverMock); + when(planMock.getServer()).thenReturn(serverMock); return this; } diff --git a/Plan/src/test/java/utilities/mocks/MockUtil.java b/Plan/src/test/java/utilities/mocks/MockUtil.java index 0994a5cd9..964b6c85b 100644 --- a/Plan/src/test/java/utilities/mocks/MockUtil.java +++ b/Plan/src/test/java/utilities/mocks/MockUtil.java @@ -9,7 +9,7 @@ import com.djrapitops.plan.PlanPlugin; import java.io.File; import java.io.FileInputStream; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.doReturn; /** * Abstract MockUtil for methods that can be used for both Bungee and Bukkit. @@ -30,7 +30,7 @@ abstract class MockUtil { } try { File file = getFile("/" + fileName); - when(planMock.getResource(fileName)).thenReturn(new FileInputStream(file)); + doReturn(new FileInputStream(file)).when(planMock).getResource(fileName); } catch (NullPointerException e) { System.out.println("File is missing! " + fileName); }