|
|
@ -9,8 +9,18 @@ import kotlin.test.assertEquals |
|
|
|
|
|
|
|
|
|
|
|
object Js5MasterIndexTest { |
|
|
|
object Js5MasterIndexTest { |
|
|
|
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI()) |
|
|
|
private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI()) |
|
|
|
private val encoded = byteArrayOf(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4) |
|
|
|
|
|
|
|
private val decoded = Js5MasterIndex( |
|
|
|
private val encodedOriginal = byteArrayOf(0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 5) |
|
|
|
|
|
|
|
private val decodedOriginal = Js5MasterIndex( |
|
|
|
|
|
|
|
mutableListOf( |
|
|
|
|
|
|
|
Js5MasterIndex.Entry(0, 1), |
|
|
|
|
|
|
|
Js5MasterIndex.Entry(0, 3), |
|
|
|
|
|
|
|
Js5MasterIndex.Entry(0, 5) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val encodedVersioned = byteArrayOf(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4) |
|
|
|
|
|
|
|
private val decodedVersioned = Js5MasterIndex( |
|
|
|
mutableListOf( |
|
|
|
mutableListOf( |
|
|
|
Js5MasterIndex.Entry(0, 1), |
|
|
|
Js5MasterIndex.Entry(0, 1), |
|
|
|
Js5MasterIndex.Entry(2, 3), |
|
|
|
Js5MasterIndex.Entry(2, 3), |
|
|
@ -18,6 +28,12 @@ object Js5MasterIndexTest { |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testMinimumFormat() { |
|
|
|
|
|
|
|
assertEquals(MasterIndexFormat.ORIGINAL, decodedOriginal.minimumFormat) |
|
|
|
|
|
|
|
assertEquals(MasterIndexFormat.VERSIONED, decodedVersioned.minimumFormat) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testCreate() { |
|
|
|
fun testCreate() { |
|
|
|
val index = Store.open(ROOT).use { store -> |
|
|
|
val index = Store.open(ROOT).use { store -> |
|
|
@ -40,19 +56,38 @@ object Js5MasterIndexTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testRead() { |
|
|
|
fun testReadOriginal() { |
|
|
|
Unpooled.wrappedBuffer(encoded).use { buf -> |
|
|
|
Unpooled.wrappedBuffer(encodedOriginal).use { buf -> |
|
|
|
val index = Js5MasterIndex.read(buf) |
|
|
|
val index = Js5MasterIndex.read(buf, MasterIndexFormat.ORIGINAL) |
|
|
|
assertEquals(decoded, index) |
|
|
|
assertEquals(decodedOriginal, index) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testWriteOriginal() { |
|
|
|
|
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
|
|
|
|
decodedOriginal.write(actual, MasterIndexFormat.ORIGINAL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(encodedOriginal).use { expected -> |
|
|
|
|
|
|
|
assertEquals(expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testReadVersioned() { |
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(encodedVersioned).use { buf -> |
|
|
|
|
|
|
|
val index = Js5MasterIndex.read(buf, MasterIndexFormat.VERSIONED) |
|
|
|
|
|
|
|
assertEquals(decodedVersioned, index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testWrite() { |
|
|
|
fun testWriteVersioned() { |
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
ByteBufAllocator.DEFAULT.buffer().use { actual -> |
|
|
|
decoded.write(actual) |
|
|
|
decodedVersioned.write(actual, MasterIndexFormat.VERSIONED) |
|
|
|
|
|
|
|
|
|
|
|
Unpooled.wrappedBuffer(encoded).use { expected -> |
|
|
|
Unpooled.wrappedBuffer(encodedVersioned).use { expected -> |
|
|
|
assertEquals(expected, actual) |
|
|
|
assertEquals(expected, actual) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|