Search in sources :

Example 1 with Patch

use of com.djrapitops.plan.storage.database.transactions.patches.Patch in project Plan by plan-player-analytics.

the class DBPatchRegressionTest method assertPatchesHaveBeenApplied.

void assertPatchesHaveBeenApplied(Patch[] patches) {
    List<String> failed = new ArrayList<>();
    for (Patch patch : patches) {
        if (!patch.isApplied()) {
            System.out.println("! NOT APPLIED: " + patch.getClass().getSimpleName());
            failed.add(patch.getClass().getSimpleName());
        } else {
            System.out.println("  WAS APPLIED: " + patch.getClass().getSimpleName());
        }
    }
    assertTrue(failed.isEmpty(), "Patches " + failed + " were not applied properly.");
}
Also used : ArrayList(java.util.ArrayList) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch)

Example 2 with Patch

use of com.djrapitops.plan.storage.database.transactions.patches.Patch in project Plan by plan-player-analytics.

the class MySQLTest method setUp.

@BeforeEach
void setUp() {
    TestErrorLogger.throwErrors(true);
    db().executeTransaction(new Patch() {

        @Override
        public boolean hasBeenApplied() {
            return false;
        }

        @Override
        public void applyPatch() {
            dropTable("plan_world_times");
            dropTable("plan_kills");
            dropTable("plan_sessions");
            dropTable("plan_worlds");
            dropTable("plan_users");
        }
    });
    db().executeTransaction(new CreateTablesTransaction());
    db().executeTransaction(new RemoveEverythingTransaction());
    db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), TestConstants.SERVER_NAME, "")));
    assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}
Also used : Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Patch

use of com.djrapitops.plan.storage.database.transactions.patches.Patch in project Plan by plan-player-analytics.

the class SQLiteTest method setUp.

@BeforeEach
void setUp() {
    TestErrorLogger.throwErrors(true);
    db().executeTransaction(new Patch() {

        @Override
        public boolean hasBeenApplied() {
            return false;
        }

        @Override
        public void applyPatch() {
            dropTable("plan_world_times");
            dropTable("plan_kills");
            dropTable("plan_sessions");
            dropTable("plan_worlds");
            dropTable("plan_users");
        }
    });
    db().executeTransaction(new CreateTablesTransaction());
    db().executeTransaction(new RemoveEverythingTransaction());
    db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), "ServerName", "")));
    assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}
Also used : Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Patch

use of com.djrapitops.plan.storage.database.transactions.patches.Patch in project Plan by plan-player-analytics.

the class DBPatchMySQLRegressionTest method mysqlPatchesAreApplied.

@Test
void mysqlPatchesAreApplied() {
    Patch[] patches = underTest.patches();
    for (Patch patch : patches) {
        underTest.executeTransaction(patch);
    }
    assertPatchesHaveBeenApplied(patches);
    // Make sure that a fetch works.
    PlayerContainer player = underTest.query(ContainerFetchQueries.fetchPlayerContainer(TestConstants.PLAYER_ONE_UUID));
    OptionalAssert.equals(1, player.getValue(PlayerKeys.PLAYER_KILL_COUNT));
    // Make sure no foreign key checks fail on removal
    underTest.executeTransaction(new RemoveEverythingTransaction());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) KillsOptimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.KillsOptimizationPatch)

Example 5 with Patch

use of com.djrapitops.plan.storage.database.transactions.patches.Patch in project Plan by plan-player-analytics.

the class DBPatchSQLiteRegressionTest method sqlitePatchesAreApplied.

@Test
void sqlitePatchesAreApplied() {
    Patch[] patches = underTest.patches();
    for (Patch patch : patches) {
        underTest.executeTransaction(patch);
    }
    assertPatchesHaveBeenApplied(patches);
    // Make sure that a fetch works.
    PlayerContainer player = underTest.query(ContainerFetchQueries.fetchPlayerContainer(TestConstants.PLAYER_ONE_UUID));
    OptionalAssert.equals(1, player.getValue(PlayerKeys.PLAYER_KILL_COUNT));
    // Make sure no foreign key checks fail on removal
    underTest.executeTransaction(new RemoveEverythingTransaction());
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) Test(org.junit.jupiter.api.Test)

Aggregations

Patch (com.djrapitops.plan.storage.database.transactions.patches.Patch)5 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)4 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)2 Server (com.djrapitops.plan.identification.Server)2 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)2 CreateTablesTransaction (com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 KillsOptimizationPatch (com.djrapitops.plan.storage.database.transactions.patches.KillsOptimizationPatch)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1