|
|
@ -507,6 +507,12 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-archive-legacy") { store -> |
|
|
|
|
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
|
|
|
|
store.read(0, 1).release() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-block-number") { store -> |
|
|
|
readTest("corrupt-first-invalid-block-number") { store -> |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
@ -537,6 +543,12 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-archive-legacy") { store -> |
|
|
|
|
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
|
|
|
|
store.read(0, 1).release() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-block-number") { store -> |
|
|
|
readTest("corrupt-second-invalid-block-number") { store -> |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
@ -587,6 +599,15 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overwriteTest( |
|
|
|
|
|
|
|
"corrupt-first-invalid-archive-legacy", |
|
|
|
|
|
|
|
"corrupt-first-invalid-archive-overwritten-legacy" |
|
|
|
|
|
|
|
) { store -> |
|
|
|
|
|
|
|
copiedBuffer("Hello".repeat(300)).use { buf -> |
|
|
|
|
|
|
|
store.write(0, 1, buf) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
overwriteTest("corrupt-first-invalid-block-number", "corrupt-first-invalid-block-number-overwritten") { store -> |
|
|
|
overwriteTest("corrupt-first-invalid-block-number", "corrupt-first-invalid-block-number-overwritten") { store -> |
|
|
|
copiedBuffer("Hello".repeat(300)).use { buf -> |
|
|
|
copiedBuffer("Hello".repeat(300)).use { buf -> |
|
|
|
store.write(255, 1, buf) |
|
|
|
store.write(255, 1, buf) |
|
|
@ -617,6 +638,15 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overwriteTest( |
|
|
|
|
|
|
|
"corrupt-second-invalid-archive-legacy", |
|
|
|
|
|
|
|
"corrupt-second-invalid-archive-overwritten-legacy" |
|
|
|
|
|
|
|
) { store -> |
|
|
|
|
|
|
|
copiedBuffer("Hello".repeat(300)).use { buf -> |
|
|
|
|
|
|
|
store.write(0, 1, buf) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
overwriteTest( |
|
|
|
overwriteTest( |
|
|
|
"corrupt-second-invalid-block-number", |
|
|
|
"corrupt-second-invalid-block-number", |
|
|
|
"corrupt-second-invalid-block-number-overwritten" |
|
|
|
"corrupt-second-invalid-block-number-overwritten" |
|
|
@ -665,6 +695,14 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-archive-overwritten-legacy") { store -> |
|
|
|
|
|
|
|
store.read(0, 1).use { actual -> |
|
|
|
|
|
|
|
copiedBuffer("Hello".repeat(300)).use { expected -> |
|
|
|
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-block-number-overwritten") { store -> |
|
|
|
readTest("corrupt-first-invalid-block-number-overwritten") { store -> |
|
|
|
store.read(255, 1).use { actual -> |
|
|
|
store.read(255, 1).use { actual -> |
|
|
|
copiedBuffer("Hello".repeat(300)).use { expected -> |
|
|
|
copiedBuffer("Hello".repeat(300)).use { expected -> |
|
|
@ -705,6 +743,14 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-archive-overwritten-legacy") { store -> |
|
|
|
|
|
|
|
store.read(0, 1).use { actual -> |
|
|
|
|
|
|
|
copiedBuffer("Hello".repeat(300)).use { expected -> |
|
|
|
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-block-number-overwritten") { store -> |
|
|
|
readTest("corrupt-second-invalid-block-number-overwritten") { store -> |
|
|
|
store.read(255, 1).use { actual -> |
|
|
|
store.read(255, 1).use { actual -> |
|
|
|
copiedBuffer("Hello".repeat(300)).use { expected -> |
|
|
|
copiedBuffer("Hello".repeat(300)).use { expected -> |
|
|
@ -762,9 +808,9 @@ class DiskStoreTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testCreateLegacyDataFile() { |
|
|
|
fun testCreateLegacyDataFile() { |
|
|
|
writeTest("single-block-legacy", legacyDataPath = true) { store -> |
|
|
|
writeTest("single-block-legacy", legacyDataFile = true) { store -> |
|
|
|
copiedBuffer("OpenRS2").use { buf -> |
|
|
|
copiedBuffer("OpenRS2").use { buf -> |
|
|
|
store.write(255, 1, buf) |
|
|
|
store.write(0, 1, buf) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -773,7 +819,7 @@ class DiskStoreTest { |
|
|
|
fun testOpenLegacyDataFile() { |
|
|
|
fun testOpenLegacyDataFile() { |
|
|
|
readTest("single-block-legacy") { store -> |
|
|
|
readTest("single-block-legacy") { store -> |
|
|
|
copiedBuffer("OpenRS2").use { expected -> |
|
|
|
copiedBuffer("OpenRS2").use { expected -> |
|
|
|
store.read(255, 1).use { actual -> |
|
|
|
store.read(0, 1).use { actual -> |
|
|
|
assertEquals(expected, actual) |
|
|
|
assertEquals(expected, actual) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -786,10 +832,10 @@ class DiskStoreTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun writeTest(name: String, legacyDataPath: Boolean = false, f: (Store) -> Unit) { |
|
|
|
private fun writeTest(name: String, legacyDataFile: Boolean = false, f: (Store) -> Unit) { |
|
|
|
Jimfs.newFileSystem(Configuration.forCurrentPlatform()).use { fs -> |
|
|
|
Jimfs.newFileSystem(Configuration.forCurrentPlatform()).use { fs -> |
|
|
|
val actual = fs.rootDirectories.first().resolve("cache") |
|
|
|
val actual = fs.rootDirectories.first().resolve("cache") |
|
|
|
DiskStore.create(actual, legacyDataPath = legacyDataPath).use { store -> |
|
|
|
DiskStore.create(actual, legacyDataFile = legacyDataFile).use { store -> |
|
|
|
f(store) |
|
|
|
f(store) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|