|
|
@ -3,7 +3,6 @@ package org.openrs2.cache |
|
|
|
import com.google.common.jimfs.Configuration |
|
|
|
import com.google.common.jimfs.Configuration |
|
|
|
import com.google.common.jimfs.Jimfs |
|
|
|
import com.google.common.jimfs.Jimfs |
|
|
|
import io.netty.buffer.Unpooled |
|
|
|
import io.netty.buffer.Unpooled |
|
|
|
import org.junit.jupiter.api.assertThrows |
|
|
|
|
|
|
|
import org.openrs2.buffer.copiedBuffer |
|
|
|
import org.openrs2.buffer.copiedBuffer |
|
|
|
import org.openrs2.buffer.use |
|
|
|
import org.openrs2.buffer.use |
|
|
|
import org.openrs2.util.io.recursiveCopy |
|
|
|
import org.openrs2.util.io.recursiveCopy |
|
|
@ -12,6 +11,7 @@ import java.io.FileNotFoundException |
|
|
|
import java.nio.file.Paths |
|
|
|
import java.nio.file.Paths |
|
|
|
import kotlin.test.Test |
|
|
|
import kotlin.test.Test |
|
|
|
import kotlin.test.assertEquals |
|
|
|
import kotlin.test.assertEquals |
|
|
|
|
|
|
|
import kotlin.test.assertFailsWith |
|
|
|
import kotlin.test.assertFalse |
|
|
|
import kotlin.test.assertFalse |
|
|
|
import kotlin.test.assertTrue |
|
|
|
import kotlin.test.assertTrue |
|
|
|
|
|
|
|
|
|
|
@ -21,85 +21,85 @@ object DiskStoreTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testBounds() { |
|
|
|
fun testBounds() { |
|
|
|
readTest("empty") { store -> |
|
|
|
readTest("empty") { store -> |
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.exists(-1) |
|
|
|
store.exists(-1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.exists(256) |
|
|
|
store.exists(256) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.list(-1) |
|
|
|
store.list(-1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.list(256) |
|
|
|
store.list(256) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.exists(-1, 0) |
|
|
|
store.exists(-1, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.exists(256, 0) |
|
|
|
store.exists(256, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.exists(0, -1) |
|
|
|
store.exists(0, -1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.read(-1, 0).release() |
|
|
|
store.read(-1, 0).release() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.read(256, 0).release() |
|
|
|
store.read(256, 0).release() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.read(0, -1).release() |
|
|
|
store.read(0, -1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
writeTest("empty") { store -> |
|
|
|
writeTest("empty") { store -> |
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.create(-1) |
|
|
|
store.create(-1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.create(256) |
|
|
|
store.create(256) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.write(-1, 0, Unpooled.EMPTY_BUFFER) |
|
|
|
store.write(-1, 0, Unpooled.EMPTY_BUFFER) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.write(256, 0, Unpooled.EMPTY_BUFFER) |
|
|
|
store.write(256, 0, Unpooled.EMPTY_BUFFER) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.write(0, -1, Unpooled.EMPTY_BUFFER) |
|
|
|
store.write(0, -1, Unpooled.EMPTY_BUFFER) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.remove(-1) |
|
|
|
store.remove(-1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.remove(256) |
|
|
|
store.remove(256) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.remove(-1, 0) |
|
|
|
store.remove(-1, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.remove(256, 0) |
|
|
|
store.remove(256, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<IllegalArgumentException> { |
|
|
|
assertFailsWith<IllegalArgumentException> { |
|
|
|
store.remove(0, -1) |
|
|
|
store.remove(0, -1) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -200,7 +200,7 @@ object DiskStoreTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testListNonExistent() { |
|
|
|
fun testListNonExistent() { |
|
|
|
readTest("empty") { store -> |
|
|
|
readTest("empty") { store -> |
|
|
|
assertThrows<FileNotFoundException> { |
|
|
|
assertFailsWith<FileNotFoundException> { |
|
|
|
store.list(0) |
|
|
|
store.list(0) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -275,15 +275,15 @@ object DiskStoreTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testReadNonExistent() { |
|
|
|
fun testReadNonExistent() { |
|
|
|
readTest("single-block") { store -> |
|
|
|
readTest("single-block") { store -> |
|
|
|
assertThrows<FileNotFoundException> { |
|
|
|
assertFailsWith<FileNotFoundException> { |
|
|
|
store.read(0, 0) |
|
|
|
store.read(0, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<FileNotFoundException> { |
|
|
|
assertFailsWith<FileNotFoundException> { |
|
|
|
store.read(255, 0) |
|
|
|
store.read(255, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertThrows<FileNotFoundException> { |
|
|
|
assertFailsWith<FileNotFoundException> { |
|
|
|
store.read(255, 2) |
|
|
|
store.read(255, 2) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -498,67 +498,67 @@ object DiskStoreTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testReadCorrupt() { |
|
|
|
fun testReadCorrupt() { |
|
|
|
readTest("corrupt-eof-late") { store -> |
|
|
|
readTest("corrupt-eof-late") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-eof-early") { store -> |
|
|
|
readTest("corrupt-first-eof-early") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-archive") { store -> |
|
|
|
readTest("corrupt-first-invalid-archive") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-block-number") { store -> |
|
|
|
readTest("corrupt-first-invalid-block-number") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-invalid-group") { store -> |
|
|
|
readTest("corrupt-first-invalid-group") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-first-outside-data-file") { store -> |
|
|
|
readTest("corrupt-first-outside-data-file") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-eof-early") { store -> |
|
|
|
readTest("corrupt-second-eof-early") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-archive") { store -> |
|
|
|
readTest("corrupt-second-invalid-archive") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-block-number") { store -> |
|
|
|
readTest("corrupt-second-invalid-block-number") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-invalid-group") { store -> |
|
|
|
readTest("corrupt-second-invalid-group") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readTest("corrupt-second-outside-data-file") { store -> |
|
|
|
readTest("corrupt-second-outside-data-file") { store -> |
|
|
|
assertThrows<StoreCorruptException> { |
|
|
|
assertFailsWith<StoreCorruptException> { |
|
|
|
store.read(255, 1).release() |
|
|
|
store.read(255, 1).release() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|