little fixie 2

This commit is contained in:
2024-07-12 15:35:00 +02:00
parent ff2348209c
commit 9acf85c7cb
2 changed files with 19 additions and 0 deletions

View File

@@ -494,6 +494,9 @@ public class DhfsFileServiceImpl implements DhfsFileService {
if (!(fDataU instanceof File fData))
throw new StatusRuntimeException(Status.INVALID_ARGUMENT);
if (size(fileUuid) < offset)
truncate(fileUuid, offset);
var chunksAll = fData.getChunks();
var first = chunksAll.floorEntry(offset);
var last = chunksAll.lowerEntry(offset + data.length);

View File

@@ -197,6 +197,22 @@ public class DhfsFileServiceSimpleTestImpl {
Assertions.assertArrayEquals(new byte[]{}, fileService.read(uuid, 20, 10).get().toByteArray());
}
@Test
void writeOverSizeTest() {
var ret = fileService.create("/writeOverSizeTest", 777);
Assertions.assertTrue(ret.isPresent());
var uuid = ret.get();
fileService.write(uuid, 0, new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
Assertions.assertArrayEquals(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, fileService.read(uuid, 0, 10).get().toByteArray());
fileService.write(uuid, 20, new byte[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19});
Assertions.assertArrayEquals(new byte[]{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
}, fileService.read(uuid, 0, 30).get().toByteArray());
}
@Test
void moveTest2() throws InterruptedException {
var ret = fileService.create("/moveTest", 777);