cache: fix tree storage test by sorting files prior to adding
Change archive.addFile(int) -> addFile(FSFile)
This commit is contained in:
@@ -306,8 +306,9 @@ public class CacheClient implements AutoCloseable
|
|||||||
archive.clearFiles();
|
archive.clearFiles();
|
||||||
for (FileData fd : ad.getFiles())
|
for (FileData fd : ad.getFiles())
|
||||||
{
|
{
|
||||||
FSFile file = archive.addFile(fd.getId());
|
FSFile file = new FSFile(fd.getId());
|
||||||
file.setNameHash(fd.getNameHash());
|
file.setNameHash(fd.getNameHash());
|
||||||
|
archive.addFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<FileResult> future = requestFile(index.getId(), ad.getId(), false);
|
CompletableFuture<FileResult> future = requestFile(index.getId(), ad.getId(), false);
|
||||||
|
|||||||
@@ -113,9 +113,8 @@ public class Archive
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FSFile addFile(int id)
|
public FSFile addFile(FSFile file)
|
||||||
{
|
{
|
||||||
FSFile file = new FSFile(id);
|
|
||||||
this.files.addFile(file);
|
this.files.addFile(file);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,8 +137,9 @@ public class DiskStorage implements Storage
|
|||||||
|
|
||||||
for (FileData fd : ad.getFiles())
|
for (FileData fd : ad.getFiles())
|
||||||
{
|
{
|
||||||
FSFile file = archive.addFile(fd.getId());
|
FSFile file = new FSFile(fd.getId());
|
||||||
file.setNameHash(fd.getNameHash());
|
file.setNameHash(fd.getNameHash());
|
||||||
|
archive.addFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.google.common.io.Files;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.cache.fs.Archive;
|
import net.runelite.cache.fs.Archive;
|
||||||
@@ -127,9 +128,10 @@ public class TreeStorage implements Storage
|
|||||||
|
|
||||||
byte[] data = Files.toByteArray(from);
|
byte[] data = Files.toByteArray(from);
|
||||||
|
|
||||||
FSFile file = archive.addFile(fileId);
|
FSFile file = new FSFile(fileId);
|
||||||
file.setNameHash(nameHash);
|
file.setNameHash(nameHash);
|
||||||
file.setContents(data);
|
file.setContents(data);
|
||||||
|
archive.addFile(file);
|
||||||
|
|
||||||
File archiveFile = new File(parent, archive.getArchiveId() + ".rev");
|
File archiveFile = new File(parent, archive.getArchiveId() + ".rev");
|
||||||
int rev = Integer.parseInt(Files.readFirstLine(archiveFile, Charset.defaultCharset()));
|
int rev = Integer.parseInt(Files.readFirstLine(archiveFile, Charset.defaultCharset()));
|
||||||
@@ -152,8 +154,9 @@ public class TreeStorage implements Storage
|
|||||||
|
|
||||||
assert archiveId == archive.getArchiveId();
|
assert archiveId == archive.getArchiveId();
|
||||||
|
|
||||||
FSFile file = archive.addFile(fileId);
|
FSFile file = new FSFile(fileId);
|
||||||
file.setNameHash(nameHash);
|
file.setNameHash(nameHash);
|
||||||
|
archive.addFile(file);
|
||||||
|
|
||||||
byte[] contents = Files.toByteArray(from);
|
byte[] contents = Files.toByteArray(from);
|
||||||
file.setContents(contents);
|
file.setContents(contents);
|
||||||
@@ -169,6 +172,8 @@ public class TreeStorage implements Storage
|
|||||||
|
|
||||||
public void loadTree(Archive archive, File parent, File from) throws IOException
|
public void loadTree(Archive archive, File parent, File from) throws IOException
|
||||||
{
|
{
|
||||||
|
List<FSFile> files = new ArrayList<>();
|
||||||
|
|
||||||
for (File file : from.listFiles())
|
for (File file : from.listFiles())
|
||||||
{
|
{
|
||||||
//fileId-fileName.dat
|
//fileId-fileName.dat
|
||||||
@@ -178,13 +183,18 @@ public class TreeStorage implements Storage
|
|||||||
int fileId = Integer.parseInt(split[0]);
|
int fileId = Integer.parseInt(split[0]);
|
||||||
int fileName = (int) Long.parseLong(split[1], 16);
|
int fileName = (int) Long.parseLong(split[1], 16);
|
||||||
|
|
||||||
FSFile f = archive.addFile(fileId);
|
FSFile f = new FSFile(fileId);
|
||||||
f.setNameHash(fileName);
|
f.setNameHash(fileName);
|
||||||
|
files.add(f);
|
||||||
|
|
||||||
byte[] contents = Files.toByteArray(file);
|
byte[] contents = Files.toByteArray(file);
|
||||||
f.setContents(contents);
|
f.setContents(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the filesystem may order these differently (eg, 1, 10, 2)
|
||||||
|
Collections.sort(files, (f1, f2) -> Integer.compare(f1.getFileId(), f2.getFileId()));
|
||||||
|
files.forEach(archive::addFile);
|
||||||
|
|
||||||
File archiveFile = new File(parent, archive.getArchiveId() + ".rev");
|
File archiveFile = new File(parent, archive.getArchiveId() + ".rev");
|
||||||
int rev = Integer.parseInt(Files.readFirstLine(archiveFile, Charset.defaultCharset()));
|
int rev = Integer.parseInt(Files.readFirstLine(archiveFile, Charset.defaultCharset()));
|
||||||
archive.setRevision(rev);
|
archive.setRevision(rev);
|
||||||
@@ -192,9 +202,6 @@ public class TreeStorage implements Storage
|
|||||||
archiveFile = new File(parent, archive.getArchiveId() + ".name");
|
archiveFile = new File(parent, archive.getArchiveId() + ".name");
|
||||||
int name = Integer.parseInt(Files.readFirstLine(archiveFile, Charset.defaultCharset()));
|
int name = Integer.parseInt(Files.readFirstLine(archiveFile, Charset.defaultCharset()));
|
||||||
archive.setNameHash(name);
|
archive.setNameHash(name);
|
||||||
|
|
||||||
// the filesystem may order these differently (eg, 1, 10, 2)
|
|
||||||
Collections.sort(archive.getFiles(), (f1, f2) -> Integer.compare(f1.getFileId(), f2.getFileId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ public class StoreTest
|
|||||||
{
|
{
|
||||||
Index index = store.addIndex(0);
|
Index index = store.addIndex(0);
|
||||||
Archive archive = index.addArchive(0);
|
Archive archive = index.addArchive(0);
|
||||||
FSFile file = archive.addFile(0);
|
FSFile file = new FSFile(0);
|
||||||
|
archive.addFile(file);
|
||||||
file.setNameHash(7);
|
file.setNameHash(7);
|
||||||
file.setContents("test".getBytes());
|
file.setContents("test".getBytes());
|
||||||
|
|
||||||
@@ -77,8 +78,9 @@ public class StoreTest
|
|||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
||||||
{
|
{
|
||||||
FSFile file = archive.addFile(i);
|
FSFile file = new FSFile(i);
|
||||||
file.setNameHash(random.nextInt());
|
file.setNameHash(random.nextInt());
|
||||||
|
archive.addFile(file);
|
||||||
byte[] data = new byte[random.nextInt(1024)];
|
byte[] data = new byte[random.nextInt(1024)];
|
||||||
random.nextBytes(data);
|
random.nextBytes(data);
|
||||||
file.setContents(data);
|
file.setContents(data);
|
||||||
@@ -115,8 +117,9 @@ public class StoreTest
|
|||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
||||||
{
|
{
|
||||||
FSFile file = archive.addFile(i);
|
FSFile file = new FSFile(i);
|
||||||
file.setNameHash(random.nextInt(Integer.MAX_VALUE));
|
file.setNameHash(random.nextInt(Integer.MAX_VALUE));
|
||||||
|
archive.addFile(file);
|
||||||
byte[] data = new byte[random.nextInt(1024)];
|
byte[] data = new byte[random.nextInt(1024)];
|
||||||
random.nextBytes(data);
|
random.nextBytes(data);
|
||||||
file.setContents(data);
|
file.setContents(data);
|
||||||
@@ -124,8 +127,9 @@ public class StoreTest
|
|||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
||||||
{
|
{
|
||||||
FSFile file = archive2.addFile(i);
|
FSFile file = new FSFile(i);
|
||||||
file.setNameHash(random.nextInt(Integer.MAX_VALUE));
|
file.setNameHash(random.nextInt(Integer.MAX_VALUE));
|
||||||
|
archive2.addFile(file);
|
||||||
byte[] data = new byte[random.nextInt(1024)];
|
byte[] data = new byte[random.nextInt(1024)];
|
||||||
random.nextBytes(data);
|
random.nextBytes(data);
|
||||||
file.setContents(data);
|
file.setContents(data);
|
||||||
@@ -133,8 +137,9 @@ public class StoreTest
|
|||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
for (int i = 0; i < NUMBER_OF_FILES; ++i)
|
||||||
{
|
{
|
||||||
FSFile file = archive3.addFile(i);
|
FSFile file = new FSFile(i);
|
||||||
file.setNameHash(random.nextInt(Integer.MAX_VALUE));
|
file.setNameHash(random.nextInt(Integer.MAX_VALUE));
|
||||||
|
archive3.addFile(file);
|
||||||
byte[] data = new byte[random.nextInt(1024)];
|
byte[] data = new byte[random.nextInt(1024)];
|
||||||
random.nextBytes(data);
|
random.nextBytes(data);
|
||||||
file.setContents(data);
|
file.setContents(data);
|
||||||
|
|||||||
@@ -115,9 +115,10 @@ public class CacheServerTest
|
|||||||
{
|
{
|
||||||
Index index = store.addIndex(0);
|
Index index = store.addIndex(0);
|
||||||
Archive archive = index.addArchive(0);
|
Archive archive = index.addArchive(0);
|
||||||
FSFile file = archive.addFile(0);
|
FSFile file = new FSFile(0);
|
||||||
file.setNameHash(7);
|
file.setNameHash(7);
|
||||||
file.setContents("test".getBytes());
|
file.setContents("test".getBytes());
|
||||||
|
archive.addFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user