Search in sources :

Example 1 with ADPPlugin

use of com.alessiodp.core.common.ADPPlugin in project ADP-Core by AlessioDP.

the class StorageTest method setUp.

@BeforeAll
public static void setUp() {
    ADPPlugin mockPlugin = mock(ADPPlugin.class);
    LoggerManager mockLoggerManager = mock(LoggerManager.class);
    when(mockPlugin.getLoggerManager()).thenReturn(mockLoggerManager);
    when(mockPlugin.getFolder()).thenReturn(Paths.get("./"));
}
Also used : LoggerManager(com.alessiodp.core.common.logging.LoggerManager) ADPPlugin(com.alessiodp.core.common.ADPPlugin) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ADPPlugin

use of com.alessiodp.core.common.ADPPlugin in project Parties by AlessioDP.

the class SQLDispatcherTest method testMultipleOperations.

@Test
public void testMultipleOperations() {
    PartiesSQLDispatcher dispatcher = getSQLDispatcherH2();
    PartiesDao dao = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PartiesDao.class);
    ArrayList<CompletableFuture<?>> lst = new ArrayList<>();
    final int concurrentOperations = 20;
    PartyImpl mockParty = mock(PartyImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockParty).updateParty();
    PartyPlayerImpl mockPlayer = mock(PartyPlayerImpl.class);
    doReturn(CompletableFuture.completedFuture(null)).when(mockPlayer).updatePlayer();
    PartyManager mockPartyManager = mock(PartyManager.class);
    when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
    when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mockPlugin, mock.getArgument(0)));
    PlayerManager mockPlayerManager = mock(PlayerManager.class);
    when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
    when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mockPlugin, mock.getArgument(0)));
    for (int c = 0; c < concurrentOperations; c++) {
        int finalC = c;
        lst.add(CompletableFuture.runAsync(() -> {
            PartyImpl party = initializeParty(mockPlugin, UUID.randomUUID());
            PartyPlayerImpl player = initializePlayer(mockPlugin, UUID.randomUUID());
            party.setAccessible(true);
            party.setup("test-" + finalC, player.getPlayerUUID().toString());
            party.setDescription("description");
            party.setKills(10);
            party.setMembers(Collections.singleton(player.getPlayerUUID()));
            party.setAccessible(false);
            player.setAccessible(true);
            player.setPartyId(party.getId());
            player.setAccessible(false);
            dispatcher.updatePlayer(player);
            dispatcher.updateParty(party);
            try (MockedStatic<ADPPlugin> staticPlugin = mockStatic(ADPPlugin.class)) {
                // Make a try with resource mock static for the completable future
                when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
                Party sameParty = dispatcher.getParty(party.getId());
                assertEquals(sameParty, party);
            }
        }));
    }
    lst.forEach(CompletableFuture::join);
    assertEquals(concurrentOperations, dao.countAll());
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) PlayerManager(com.alessiodp.parties.common.players.PlayerManager) MockedStatic(org.mockito.MockedStatic) PartiesSQLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher) ArrayList(java.util.ArrayList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) CompletableFuture(java.util.concurrent.CompletableFuture) Party(com.alessiodp.parties.api.interfaces.Party) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) Test(org.junit.jupiter.api.Test)

Aggregations

ADPPlugin (com.alessiodp.core.common.ADPPlugin)2 LoggerManager (com.alessiodp.core.common.logging.LoggerManager)1 Party (com.alessiodp.parties.api.interfaces.Party)1 PartyManager (com.alessiodp.parties.common.parties.PartyManager)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PlayerManager (com.alessiodp.parties.common.players.PlayerManager)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 PartiesSQLDispatcher (com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher)1 H2PartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao)1 PartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao)1 PostgreSQLPartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao)1 SQLitePartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1 MockedStatic (org.mockito.MockedStatic)1