use of com.ixale.starparse.domain.RaidBoss in project StarParse by Ixale.
the class RankTest method testFull.
@Test
public void testFull() {
Raid raid = new WorldBoss();
RaidBoss boss = raid.getBosses().get(4);
assertEquals(boss.getRaidBossName(), RaidBossName.ColossalMonolith);
assertEquals(boss.getMode(), Mode.SM);
assertEquals(boss.getSize(), Size.Eight);
service.initialize(Config.DEFAULT_SERVER_HOST);
service.getRank(boss, RankType.DPS, CharacterDiscipline.Darkness, 360001, 2485, (rc) -> {
assertNotNull(rc);
assertNull(rc.getReason());
assertTrue(rc.getPercent() >= 0 && rc.getPercent() <= 100);
assertEquals(RankType.DPS, rc.getType());
});
try {
service.getRank(boss, RankType.DTPS, CharacterDiscipline.CombatMedic, 360001, 2485, (rc) -> fail("Healer should not have DTPS"));
} catch (Exception e) {
// OK, healer should not have DTPS (yet)
}
service.getRank(boss, RankType.DTPS, CharacterDiscipline.Defense, 360001, 2485, (rc) -> {
assertNotNull(rc);
assertNull(rc.getReason());
assertTrue(rc.getPercent() > 0 && rc.getPercent() < 100);
assertEquals(RankType.DTPS, rc.getType());
});
service.getRank(boss, RankType.EHPS, CharacterDiscipline.CombatMedic, 360001, 2485, (rc) -> {
assertNotNull(rc);
assertNull(rc.getReason());
assertTrue(rc.getPercent() >= 0 && rc.getPercent() <= 100);
assertEquals(RankType.EHPS, rc.getType());
});
}
use of com.ixale.starparse.domain.RaidBoss in project StarParse by Ixale.
the class RankServiceImpl method getRanking.
private void getRanking(final RaidBoss boss, final RankType type, final CharacterDiscipline discipline, final Consumer<Ranking> callback) {
final String key = buildKey(boss, type, discipline);
if (!rankings.containsKey(key)) {
if (rankingExecutor == null) {
rankingExecutor = Executors.newSingleThreadExecutor(r -> {
final Thread worker = new Thread(r, "Ranking Worker");
worker.setDaemon(true);
return worker;
});
}
rankingExecutor.execute(() -> {
try {
// build remote URL
final URL url = buildUrl(boss, host, key);
// fetch from remote
final String content = FileDownloader.fetchFile(url);
// parse
final Ranking ranking = readRanking(content);
// cache
rankings.put(key, ranking);
Platform.runLater(() -> {
callback.accept(rankings.get(key));
});
if (logger.isDebugEnabled()) {
logger.debug("Ranking fetched from remote (" + boss + ", " + type + ", " + discipline + "): " + ranking);
}
} catch (Exception e) {
if (e.getMessage().equals("Read timed out") || e.getMessage().startsWith("Server returned non-OK status: 404")) {
// local issue, silently ignore
return;
}
logger.error("Failed to rank " + key + ": " + e.getMessage(), e);
}
});
return;
}
callback.accept(rankings.get(key));
}
use of com.ixale.starparse.domain.RaidBoss in project StarParse by Ixale.
the class RankTest method testDownload.
@Test
public void testDownload() throws Exception {
Raid raid = new WorldBoss();
RaidBoss boss = raid.getBosses().get(1);
assertEquals(boss.getRaidBossName(), RaidBossName.ColossalMonolith);
assertEquals(boss.getMode(), Mode.HM);
assertEquals(boss.getSize(), Size.Sixteen);
final String key = service.buildKey(boss, RankType.DPS, CharacterDiscipline.InnovativeOrdnance);
assertEquals("dps_ColossalMonolith_HM_16m_Commando", key);
final URL url = service.buildUrl(boss, Config.DEFAULT_SERVER_HOST, key);
final String content = FileDownloader.fetchFile(url);
assertNotNull(content);
assertTrue(content.contains("<boss>ColossalMonolith HM 16m</boss>"));
assertTrue(content.contains("<className>Commando</className>"));
assertTrue(content.contains("<type>dps</type>"));
final Ranking r = service.readRanking(content);
assertNotNull(r);
assertTrue(r.getMinTick() > 120000);
final RankClass rc = service.getRank(r, r.getMinTick() + 1, 2485);
assertNotNull(rc);
assertNull(rc.getReason());
assertTrue(rc.getPercent() >= 0 && rc.getPercent() <= 100);
}
Aggregations