Search in sources :

Example 6 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class CacheTest method doCacheStuff.

private void doCacheStuff() throws InterruptedException {
    // DataCall.getCacheProvider().clear(URLEndpoint.V3_MATCH);
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.getLogger("no.stelar7.api.r4j.basic.calling.DataCallBuilder").setLevel(Level.INFO);
    loggerContext.getLogger("no.stelar7.api.r4j.basic.ratelimiting.BurstRateLimiter").setLevel(Level.OFF);
    loggerContext.getLogger("no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider").setLevel(Level.OFF);
    System.out.println("Fetching a random summoner and their match list");
    String id = new SpectatorBuilder().withPlatform(LeagueShard.EUW1).getFeaturedGames().get(0).getParticipants().get(0).getSummonerName();
    Summoner s = new SummonerBuilder().withPlatform(LeagueShard.EUW1).withName(id).get();
    List<String> recents = new MatchListBuilder().withPlatform(LeagueShard.EUW1).withPuuid(s.getPUUID()).get();
    if (recents.isEmpty()) {
        return;
    }
    String ref = recents.get(0);
    System.out.println("Starting timer");
    long start = System.currentTimeMillis();
    LOLMatch url = LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x url fetch time: %dns%n", System.currentTimeMillis() - start);
    start = System.currentTimeMillis();
    LOLMatch cached = LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x cache fetch time: %dns%n", System.currentTimeMillis() - start);
    if (!url.equals(cached)) {
        throw new RuntimeException("CACHE IS BROKEN!!!!");
    }
    start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        LOLMatch.get(LeagueShard.EUW1, ref);
    }
    System.out.printf("10x cache fetch time: %dns%n", System.currentTimeMillis() - start);
    System.out.println();
    start = System.currentTimeMillis();
    LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x cache fetch time: %dns%n", System.currentTimeMillis() - start);
    System.out.println();
    System.out.println("clearing cache");
    System.out.println();
    DataCall.getCacheProvider().clear(URLEndpoint.V5_MATCH, Collections.emptyMap());
    start = System.currentTimeMillis();
    LOLMatch.get(LeagueShard.EUW1, ref);
    System.out.printf("1x url fetch time: %dns%n", System.currentTimeMillis() - start);
    start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        LOLMatch.get(LeagueShard.EUW1, ref);
    }
    System.out.printf("10x cache fetch same item time: %dns%n", System.currentTimeMillis() - start);
    System.out.println();
    System.out.println("Fetching 3 aditional matches");
    LOLMatch.get(LeagueShard.EUW1, recents.get(1));
    LOLMatch.get(LeagueShard.EUW1, recents.get(2));
    LOLMatch.get(LeagueShard.EUW1, recents.get(3));
    System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V5_MATCH, Collections.emptyMap()));
    System.out.println("Waiting for cache timeout");
    TimeUnit.SECONDS.sleep(6);
    System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V5_MATCH, Collections.emptyMap()));
    System.out.println("Re-fetching cached items");
    start = System.currentTimeMillis();
    LOLMatch.get(LeagueShard.EUW1, recents.get(0));
    LOLMatch.get(LeagueShard.EUW1, recents.get(1));
    LOLMatch.get(LeagueShard.EUW1, recents.get(2));
    LOLMatch.get(LeagueShard.EUW1, recents.get(3));
    System.out.printf("4x fetches took: %dns%n", System.currentTimeMillis() - start);
    System.out.printf("Cache size: %d%n", DataCall.getCacheProvider().getSize(URLEndpoint.V5_MATCH, Collections.emptyMap()));
    System.out.println();
}
Also used : Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) MatchListBuilder(no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder) LOLMatch(no.stelar7.api.r4j.pojo.lol.match.v5.LOLMatch) SpectatorBuilder(no.stelar7.api.r4j.impl.lol.builders.spectator.SpectatorBuilder) CacheLifetimeHint(no.stelar7.api.r4j.basic.cache.CacheLifetimeHint) URLEndpoint(no.stelar7.api.r4j.basic.constants.api.URLEndpoint)

Example 7 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class StaticTest method testItemSingle.

@Test
public void testItemSingle() {
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    Item list = api.getItem(1001);
    Assertions.assertEquals(1001, list.getId());
}
Also used : Item(no.stelar7.api.r4j.pojo.lol.staticdata.item.Item) FileSystemCacheProvider(no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)

Example 8 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class StaticTest method testItemList.

@Test
public void testItemList() {
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    Map<Integer, Item> list = api.getItems();
    Assertions.assertTrue(list.size() > 100);
}
Also used : Item(no.stelar7.api.r4j.pojo.lol.staticdata.item.Item) FileSystemCacheProvider(no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)

Aggregations

java.awt (java.awt)4 AffineTransform (java.awt.geom.AffineTransform)4 java.awt.image (java.awt.image)4 java.io (java.io)4 URL (java.net.URL)4 java.util (java.util)4 List (java.util.List)4 Predicate (java.util.function.Predicate)4 IntStream (java.util.stream.IntStream)4 ImageIO (javax.imageio.ImageIO)4 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)4 Item (no.stelar7.api.r4j.pojo.lol.staticdata.item.Item)4 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)3 MatchListBuilder (no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder)3 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)3 Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)3 DataCall (no.stelar7.api.l4j8.basic.calling.DataCall)2 Platform (no.stelar7.api.l4j8.basic.constants.api.Platform)2 no.stelar7.api.l4j8.basic.constants.types (no.stelar7.api.l4j8.basic.constants.types)2 no.stelar7.api.l4j8.basic.utils (no.stelar7.api.l4j8.basic.utils)2