Search in sources :

Example 1 with CacheClient

use of net.runelite.cache.client.CacheClient in project runelite by runelite.

the class CacheServerTest method testDownload.

@Test
@Ignore
public void testDownload() throws Exception {
    try (Store store = new Store(StoreLocation.LOCATION);
        CacheServer server = new CacheServer(store, REVISION)) {
        store.load();
        server.start();
        try (CacheClient client = new CacheClient(new Store(folder.newFolder()), HOST, REVISION)) {
            client.connect();
            client.handshake().get();
            client.download();
        }
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Store(net.runelite.cache.fs.Store) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with CacheClient

use of net.runelite.cache.client.CacheClient in project runelite by runelite.

the class CacheUpdater method update.

public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException {
    int rsVersion = RuneLiteAPI.getRsVersion();
    try (Connection con = sql2o.beginTransaction()) {
        CacheDAO cacheDao = new CacheDAO();
        CacheEntry cache = cacheDao.findMostRecent(con);
        boolean created = false;
        if (cache == null) {
            created = true;
            cache = cacheDao.createCache(con, rsVersion, Instant.now());
        }
        CacheStorage storage = new CacheStorage(cache, cacheDao, con);
        Store store = new Store(storage);
        store.load();
        ExecutorService executor = Executors.newSingleThreadExecutor();
        CacheClient client = new CacheClient(store, rsVersion, (Archive archive, byte[] data) -> executor.submit(new CacheUploader(minioClient, minioBucket, archive, data)));
        client.connect();
        HandshakeResponseType result = client.handshake().join();
        if (result != HandshakeResponseType.RESPONSE_OK) {
            logger.warn("Out of date!");
            return;
        }
        List<IndexInfo> indexes = client.requestIndexes();
        List<IndexEntry> entries = cacheDao.findIndexesForCache(con, cache);
        if (!checkOutOfDate(indexes, entries)) {
            logger.info("All up to date.");
            return;
        }
        client.download();
        CacheEntry newCache = created ? cache : cacheDao.createCache(con, rsVersion, Instant.now());
        storage.setCacheEntry(newCache);
        store.save();
        // ensure objects are added to the store before they become
        // visible in the database
        executor.shutdown();
        while (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
            logger.debug("Waiting for termination of executor...");
        }
        // commit database
        con.commit();
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Archive(net.runelite.cache.fs.Archive) HandshakeResponseType(net.runelite.protocol.api.login.HandshakeResponseType) Connection(org.sql2o.Connection) Store(net.runelite.cache.fs.Store) IndexEntry(net.runelite.cache.updater.beans.IndexEntry) IndexInfo(net.runelite.cache.client.IndexInfo) CacheEntry(net.runelite.cache.updater.beans.CacheEntry) ExecutorService(java.util.concurrent.ExecutorService)

Example 3 with CacheClient

use of net.runelite.cache.client.CacheClient in project runelite by runelite.

the class CacheServerTest method testServer.

@Test
public void testServer() throws Exception {
    try (Store store = new Store(folder.newFolder());
        CacheServer server = new CacheServer(store, REVISION)) {
        addInitialFilesToStore(store);
        store.save();
        server.start();
        try (Store store2 = new Store(folder.newFolder());
            CacheClient client = new CacheClient(store2, HOST, REVISION)) {
            client.connect();
            client.handshake().get();
            client.download();
            Index index = store2.findIndex(0);
            Archive archive = index.getArchive(0);
            FileData[] files = archive.getFileData();
            FileData file = files[0];
            assertEquals(7, file.getNameHash());
            Storage storage = store2.getStorage();
            byte[] data = storage.loadArchive(archive);
            data = archive.decompress(data);
            assertArrayEquals("test".getBytes(), data);
            assertEquals(store.getIndexes().get(0).getArchive(0).getCrc(), archive.getCrc());
        }
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Archive(net.runelite.cache.fs.Archive) Storage(net.runelite.cache.fs.Storage) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) FileData(net.runelite.cache.index.FileData) Test(org.junit.Test)

Aggregations

CacheClient (net.runelite.cache.client.CacheClient)3 Store (net.runelite.cache.fs.Store)3 Archive (net.runelite.cache.fs.Archive)2 Test (org.junit.Test)2 ExecutorService (java.util.concurrent.ExecutorService)1 IndexInfo (net.runelite.cache.client.IndexInfo)1 Index (net.runelite.cache.fs.Index)1 Storage (net.runelite.cache.fs.Storage)1 FileData (net.runelite.cache.index.FileData)1 CacheEntry (net.runelite.cache.updater.beans.CacheEntry)1 IndexEntry (net.runelite.cache.updater.beans.IndexEntry)1 HandshakeResponseType (net.runelite.protocol.api.login.HandshakeResponseType)1 Ignore (org.junit.Ignore)1 Connection (org.sql2o.Connection)1