cache: try-with-resources the rest of the Stores in tests

This commit is contained in:
Adam
2017-03-26 12:35:27 -04:00
parent 7146d4da93
commit cdbbe9f5d4
5 changed files with 85 additions and 72 deletions

View File

@@ -46,17 +46,19 @@ public class NpcDumperTest
File dumpDir = folder.newFolder(),
javaDir = folder.newFolder();
Store store = new Store(StoreLocation.LOCATION);
store.load();
try (Store store = new Store(StoreLocation.LOCATION))
{
store.load();
NpcDumper dumper = new NpcDumper(
store,
dumpDir,
javaDir
);
dumper.load();
dumper.dump();
dumper.java();
NpcDumper dumper = new NpcDumper(
store,
dumpDir,
javaDir
);
dumper.load();
dumper.dump();
dumper.java();
}
logger.info("Dumped to {}, java {}", dumpDir, javaDir);
}

View File

@@ -46,17 +46,19 @@ public class ObjectDumperTest
File dumpDir = folder.newFolder(),
javaDir = folder.newFolder();
Store store = new Store(StoreLocation.LOCATION);
store.load();
try (Store store = new Store(StoreLocation.LOCATION))
{
store.load();
ObjectDumper dumper = new ObjectDumper(
store,
dumpDir,
javaDir
);
dumper.load();
dumper.dump();
dumper.java();
ObjectDumper dumper = new ObjectDumper(
store,
dumpDir,
javaDir
);
dumper.load();
dumper.dump();
dumper.java();
}
logger.info("Dumped to {}, java {}", dumpDir, javaDir);
}

View File

@@ -49,45 +49,49 @@ public class CacheClientTest
@Ignore
public void test() throws Exception
{
Store store = new Store(new File("d:/temp"));
store.load();
try (Store store = new Store(new File("d:/temp")))
{
store.load();
CacheClient c = new CacheClient(store);
c.connect();
CompletableFuture<Integer> handshake = c.handshake();
CacheClient c = new CacheClient(store);
c.connect();
CompletableFuture<Integer> handshake = c.handshake();
Integer result = handshake.get();
logger.info("Handshake result: {}", result);
Integer result = handshake.get();
logger.info("Handshake result: {}", result);
Assert.assertEquals(0, (int) result);
c.download();
Assert.assertEquals(0, (int) result);
c.download();
c.close();
store.save();
c.close();
store.save();
}
}
@Test
@Ignore
public void testTree() throws Exception
{
Store store = new Store(new File("C:\\rs\\temp"));
store.loadTree(new File("C:\\rs\\runescape-data\\cache"));
try (Store store = new Store(new File("C:\\rs\\temp")))
{
store.loadTree(new File("C:\\rs\\runescape-data\\cache"));
CacheClient c = new CacheClient(store);
c.connect();
CompletableFuture<Integer> handshake = c.handshake();
CacheClient c = new CacheClient(store);
c.connect();
CompletableFuture<Integer> handshake = c.handshake();
Integer result = handshake.get();
logger.info("Handshake result: {}", result);
Integer result = handshake.get();
logger.info("Handshake result: {}", result);
Assert.assertEquals(0, (int) result);
c.download();
Assert.assertEquals(0, (int) result);
c.download();
c.close();
store.saveTree(new File("C:\\rs\\temp\\t"));
c.close();
store.saveTree(new File("C:\\rs\\temp\\t"));
}
}
}

View File

@@ -29,7 +29,6 @@ import java.io.File;
import java.io.IOException;
import net.runelite.cache.StoreLocation;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -40,14 +39,16 @@ public class IndexFileTest
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
@Test
public void test1() throws IOException
public void test() throws IOException
{
File file = folder.newFile();
Store store = new Store(folder.getRoot());
IndexFile index = new IndexFile(store, 5, file);
IndexEntry entry = new IndexEntry(index, 7, 8, 9);
index.write(entry);
IndexEntry entry2 = index.read(7);
Assert.assertEquals(entry, entry2);
try (Store store = new Store(folder.getRoot()))
{
IndexFile index = new IndexFile(store, 5, file);
IndexEntry entry = new IndexEntry(index, 7, 8, 9);
index.write(entry);
IndexEntry entry2 = index.read(7);
Assert.assertEquals(entry, entry2);
}
}
}

View File

@@ -52,24 +52,28 @@ public class StoreLoadTest
@Test
public void testSave() throws IOException
{
Store store = new Store(StoreLocation.LOCATION);
store.load();
java.io.File testStoreFile = folder.newFolder();
for (java.io.File f : StoreLocation.LOCATION.listFiles())
try (Store store = new Store(StoreLocation.LOCATION))
{
Files.copy(f, new java.io.File(testStoreFile, f.getName()));
store.load();
java.io.File testStoreFile = folder.newFolder();
for (java.io.File f : StoreLocation.LOCATION.listFiles())
{
Files.copy(f, new java.io.File(testStoreFile, f.getName()));
}
try (Store testStore = new Store(testStoreFile))
{
testStore.load();
Assert.assertTrue(store.equals(testStore));
testStore.save();
testStore.load();
Assert.assertTrue(store.equals(testStore));
}
}
Store testStore = new Store(testStoreFile);
testStore.load();
Assert.assertTrue(store.equals(testStore));
testStore.save();
testStore.load();
Assert.assertTrue(store.equals(testStore));
}
@Test