mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 20:32:06 -08:00
server: database improves:
- fixed broken database in some use cases (example: AI and choose name dialog, related to #11285); - added docs and debug tools for sql queries, caches and memory analyse (see DebugUtil); - refactor code to use shared settings; - deleted outdated and un-used code (db logs, stats, etc);
This commit is contained in:
parent
c448612c97
commit
bf3f26ccc1
18 changed files with 376 additions and 394 deletions
|
|
@ -0,0 +1,62 @@
|
|||
package org.mage.test.serverside;
|
||||
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBaseWithAIHelps;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class DatabaseBigQueryPerformanceTest extends CardTestPlayerBaseWithAIHelps {
|
||||
|
||||
@Test
|
||||
public void test_GetLands_SQL() {
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Assert.assertTrue("must load getNames", CardRepository.instance.getNames().size() > 1000);
|
||||
Assert.assertTrue("must load getNonLandNames", CardRepository.instance.getNonLandNames().size() > 1000);
|
||||
Assert.assertTrue("must load getArtifactNames", CardRepository.instance.getArtifactNames().size() > 1000);
|
||||
Assert.assertTrue("must load getCreatureNames", CardRepository.instance.getCreatureNames().size() > 1000);
|
||||
Assert.assertTrue("must load getNonArtifactAndNonLandNames", CardRepository.instance.getNonArtifactAndNonLandNames().size() > 1000);
|
||||
Assert.assertTrue("must load getNonLandAndNonCreatureNames", CardRepository.instance.getNonLandAndNonCreatureNames().size() > 1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_GetLands_RealGame_Manual() {
|
||||
// Name a nonland card. Target player reveals their hand. That player discards a card with that name.
|
||||
// If they can't, you draw a card.
|
||||
addCard(Zone.HAND, playerA, "Brain Pry", 1); // {1}{B}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Brain Pry", playerA);
|
||||
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
||||
setChoice(playerA, "Balduvian Bears"); // name to choose
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_GetLands_RealGame_AI() {
|
||||
// possible bug: game simulations can call big queries multiple times and overflow database cache to crash it
|
||||
// how-to fix: increase CACHE_SIZE in DatabaseUtils (require 150 000 kb on 2024)
|
||||
int cardsAmount = 5;
|
||||
|
||||
// Name a nonland card. Target player reveals their hand. That player discards a card with that name.
|
||||
// If they can't, you draw a card.
|
||||
addCard(Zone.HAND, playerA, "Brain Pry", cardsAmount); // {1}{B}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2 * cardsAmount);
|
||||
|
||||
aiPlayPriority(1, PhaseStep.PRECOMBAT_MAIN, playerA);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
|
@ -19,8 +19,6 @@ import java.nio.file.Paths;
|
|||
*/
|
||||
public class DatabaseCompatibleTest {
|
||||
|
||||
private final String JDBC_URL = "jdbc:h2:file:%s;AUTO_SERVER=TRUE";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
|
|
@ -38,9 +36,8 @@ public class DatabaseCompatibleTest {
|
|||
);
|
||||
Assert.assertTrue(Files.exists(Paths.get(dbFullFileName)));
|
||||
|
||||
AuthorizedUserRepository dbUsers = new AuthorizedUserRepository(
|
||||
String.format(JDBC_URL, dbFullName)
|
||||
);
|
||||
String connectionString = String.format("jdbc:h2:file:%s;AUTO_SERVER=TRUE", dbFullName);
|
||||
AuthorizedUserRepository dbUsers = new AuthorizedUserRepository(connectionString);
|
||||
|
||||
// search
|
||||
Assert.assertNotNull(dbUsers.getByName("user1"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue