mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-07 12:28:25 +02:00
Fixed some tests not closing resources properly
This commit is contained in:
parent
a14c97002c
commit
040c2c4f4b
@ -38,9 +38,9 @@ import utilities.mocks.objects.TestLogger;
|
||||
import utilities.mocks.objects.TestRunnableFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
@ -90,11 +90,10 @@ public class PlanBukkitMocker extends Mocker {
|
||||
}
|
||||
|
||||
PlanBukkitMocker withPluginDescription() {
|
||||
try {
|
||||
File pluginYml = getFile("/plugin.yml");
|
||||
PluginDescriptionFile description = new PluginDescriptionFile(new FileInputStream(pluginYml));
|
||||
try (InputStream in = Files.newInputStream(getFile("/plugin.yml").toPath())) {
|
||||
PluginDescriptionFile description = new PluginDescriptionFile(in);
|
||||
doReturn(description).when(planMock).getDescription();
|
||||
} catch (FileNotFoundException | InvalidDescriptionException e) {
|
||||
} catch (IOException | InvalidDescriptionException e) {
|
||||
System.out.println("Error while setting plugin description");
|
||||
}
|
||||
return this;
|
||||
|
@ -694,27 +694,59 @@ public interface DatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
default void testBackupAndRestore() throws Exception {
|
||||
default void testBackupAndRestoreSQLite() throws Exception {
|
||||
File tempFile = Files.createTempFile(system().getPlanFiles().getDataFolder().toPath(), "backup-", ".db").toFile();
|
||||
tempFile.deleteOnExit();
|
||||
SQLiteDB backup = system().getDatabaseSystem().getSqLiteFactory().usingFile(tempFile);
|
||||
backup.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
|
||||
try {
|
||||
backup.init();
|
||||
|
||||
saveAllData();
|
||||
|
||||
backup.executeTransaction(new BackupCopyTransaction(db(), backup));
|
||||
|
||||
assertQueryResultIsEqual(db(), backup, BaseUserQueries.fetchAllBaseUsers());
|
||||
assertQueryResultIsEqual(db(), backup, UserInfoQueries.fetchAllUserInformation());
|
||||
assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData());
|
||||
assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation());
|
||||
assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllCommandUsageData());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData());
|
||||
assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation());
|
||||
assertQueryResultIsEqual(db(), backup, WebUserQueries.fetchAllPlanWebUsers());
|
||||
} finally {
|
||||
backup.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
default void testBackupAndRestoreH2() throws Exception {
|
||||
File tempFile = Files.createTempFile(system().getPlanFiles().getDataFolder().toPath(), "backup-", ".db").toFile();
|
||||
tempFile.deleteOnExit();
|
||||
H2DB backup = system().getDatabaseSystem().getH2Factory().usingFile(tempFile);
|
||||
backup.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
|
||||
backup.init();
|
||||
try {
|
||||
backup.init();
|
||||
|
||||
saveAllData();
|
||||
saveAllData();
|
||||
|
||||
backup.executeTransaction(new BackupCopyTransaction(db(), backup));
|
||||
backup.executeTransaction(new BackupCopyTransaction(db(), backup));
|
||||
|
||||
assertQueryResultIsEqual(db(), backup, BaseUserQueries.fetchAllBaseUsers());
|
||||
assertQueryResultIsEqual(db(), backup, UserInfoQueries.fetchAllUserInformation());
|
||||
assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData());
|
||||
assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation());
|
||||
assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllCommandUsageData());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData());
|
||||
assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation());
|
||||
assertQueryResultIsEqual(db(), backup, WebUserQueries.fetchAllPlanWebUsers());
|
||||
assertQueryResultIsEqual(db(), backup, BaseUserQueries.fetchAllBaseUsers());
|
||||
assertQueryResultIsEqual(db(), backup, UserInfoQueries.fetchAllUserInformation());
|
||||
assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData());
|
||||
assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation());
|
||||
assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllCommandUsageData());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames());
|
||||
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData());
|
||||
assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation());
|
||||
assertQueryResultIsEqual(db(), backup, WebUserQueries.fetchAllPlanWebUsers());
|
||||
} finally {
|
||||
backup.close();
|
||||
}
|
||||
}
|
||||
|
||||
default <T> void assertQueryResultIsEqual(Database one, Database two, Query<T> query) {
|
||||
|
@ -25,9 +25,6 @@ import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import extension.SeleniumExtension;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@ -44,7 +41,6 @@ import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -124,17 +120,6 @@ class JSErrorRegressionTest {
|
||||
@Test
|
||||
void serverPageDoesNotHaveJavascriptErrors(WebDriver driver) {
|
||||
System.out.println("Testing Server Page");
|
||||
// Open the page that has refreshing info
|
||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
||||
assertNo500Error(driver);
|
||||
|
||||
// Wait until Plan caches analysis results
|
||||
Awaitility.await()
|
||||
.atMost(10, TimeUnit.SECONDS)
|
||||
.until(() -> ResponseCache.loadResponse(PageId.SERVER.of(serverUUID)) != null);
|
||||
|
||||
// Open the page with analysis stuff
|
||||
SeleniumExtension.newTab(driver);
|
||||
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server");
|
||||
assertNo500Error(driver);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user