use of com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao in project Parties by AlessioDP.
the class SQLDispatcherTest method testListParties.
@Test
public void testListParties(@TempDir Path tempDir) {
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)));
PartiesSQLDispatcher dispatcher = getSQLDispatcherH2();
PartiesDao daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PartiesDao.class);
PlayersDao daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
dispatcher = getSQLDispatcherSQLite(tempDir);
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(SQLitePartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(SQLitePlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
dispatcher = getSQLDispatcherMySQL(mockPlugin);
if (dispatcher != null) {
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
dispatcher = getSQLDispatcherMariaDB(mockPlugin);
if (dispatcher != null) {
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
dispatcher = getSQLDispatcherPostgreSQL(mockPlugin);
if (dispatcher != null) {
daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PostgreSQLPartiesDao.class);
daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PostgreSQLPlayersDao.class);
populateWithParties(dispatcher, daoParties, daoPlayers);
listPartiesNumber(dispatcher);
listPartiesByName(dispatcher);
listPartiesByMembers(dispatcher);
listPartiesByKills(dispatcher);
listPartiesByExperience(dispatcher);
dispatcher.stop();
}
}
use of com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao in project Parties by AlessioDP.
the class PartiesSQLDispatcher method getPartyByName.
@Override
public PartyImpl getPartyByName(String name) {
PartyImpl ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getByName(name)).orElse(null);
if (ret != null) {
ret.setAccessible(true);
ret.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(ret.getId().toString())));
ret.setAccessible(false);
}
return ret;
}
use of com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao in project Parties by AlessioDP.
the class PartiesSQLDispatcher method getListFixed.
@Override
public Set<PartyImpl> getListFixed() {
Set<PartyImpl> ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListFixed());
// Load members
for (PartyImpl party : ret) {
party.setAccessible(true);
party.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(party.getId().toString())));
party.setAccessible(false);
}
return ret;
}
use of com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao in project Parties by AlessioDP.
the class PartiesSQLDispatcher method getParty.
@Override
public PartyImpl getParty(UUID id) {
PartyImpl ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).get(id.toString())).orElse(null);
if (ret != null) {
ret.setAccessible(true);
ret.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(id.toString())));
ret.setAccessible(false);
}
return ret;
}
use of com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao 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());
}
Aggregations