mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
Fix JObjectResolver scope (so it's resolved eagerly)
This commit is contained in:
@@ -320,9 +320,9 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
var first = chunksAll.floorEntry(offset);
|
||||
var last = chunksAll.floorEntry((offset + data.length) - 1);
|
||||
|
||||
var newChunks = new TreeMap<Long, String>();
|
||||
for (var c : chunksAll.entrySet()) {
|
||||
if (c.getKey() < offset) newChunks.put(c.getKey(), c.getValue());
|
||||
if (!chunksAll.isEmpty()) {
|
||||
var between = chunksAll.subMap(first.getKey(), true, last.getKey(), true);
|
||||
between.clear();
|
||||
}
|
||||
|
||||
if (first != null && first.getKey() < offset) {
|
||||
@@ -340,7 +340,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
jObjectManager.put(newChunkData);
|
||||
jObjectManager.put(newChunkInfo);
|
||||
|
||||
newChunks.put(first.getKey(), newChunkData.getHash());
|
||||
chunksAll.put(first.getKey(), newChunkData.getHash());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -349,7 +349,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
jObjectManager.put(newChunkData);
|
||||
jObjectManager.put(newChunkInfo);
|
||||
|
||||
newChunks.put(offset, newChunkData.getHash());
|
||||
chunksAll.put(offset, newChunkData.getHash());
|
||||
}
|
||||
if (last != null) {
|
||||
var lchunkUuid = last.getValue();
|
||||
@@ -370,7 +370,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
jObjectManager.put(newChunkData);
|
||||
jObjectManager.put(newChunkInfo);
|
||||
|
||||
newChunks.put(startInFile, newChunkData.getHash());
|
||||
chunksAll.put(startInFile, newChunkData.getHash());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
file.runWriteLocked((m, fileData, bump) -> {
|
||||
bump.apply();
|
||||
fileData.getChunks().clear();
|
||||
fileData.getChunks().putAll(newChunks);
|
||||
fileData.getChunks().putAll(chunksAll);
|
||||
fileData.setMtime(System.currentTimeMillis());
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -7,11 +7,11 @@ import com.usatiuk.dhfs.storage.objects.repository.persistence.ObjectPersistentS
|
||||
import io.grpc.Status;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
import io.quarkus.logging.Log;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
|
||||
@ApplicationScoped
|
||||
@Singleton
|
||||
public class JObjectResolver {
|
||||
@Inject
|
||||
ObjectPersistentStore objectPersistentStore;
|
||||
|
||||
@@ -4,8 +4,7 @@ import com.usatiuk.dhfs.storage.files.objects.ChunkData;
|
||||
import com.usatiuk.dhfs.storage.files.objects.ChunkInfo;
|
||||
import com.usatiuk.dhfs.storage.files.objects.File;
|
||||
import com.usatiuk.dhfs.storage.files.service.DhfsFileService;
|
||||
import com.usatiuk.dhfs.storage.objects.jrepository.JObjectRepository;
|
||||
import com.usatiuk.dhfs.storage.objects.repository.ObjectRepository;
|
||||
import com.usatiuk.dhfs.storage.objects.jrepository.JObjectManager;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
@@ -27,9 +26,7 @@ public class DhfsFileServiceSimpleTest {
|
||||
@Inject
|
||||
DhfsFileService fileService;
|
||||
@Inject
|
||||
ObjectRepository objectRepository;
|
||||
@Inject
|
||||
JObjectRepository jObjectRepository;
|
||||
JObjectManager jObjectManager;
|
||||
|
||||
@Test
|
||||
void readTest() {
|
||||
@@ -42,22 +39,19 @@ public class DhfsFileServiceSimpleTest {
|
||||
ChunkData c3 = new ChunkData("91011".getBytes());
|
||||
ChunkInfo c3i = new ChunkInfo(c3.getHash(), c3.getBytes().length);
|
||||
File f = new File(fuuid);
|
||||
Assertions.assertDoesNotThrow(() -> f.runWriteLocked((fsNodeData, fileData) -> {
|
||||
fileData.getChunks().put(0L, c1.getHash());
|
||||
fileData.getChunks().put((long) c1.getBytes().length, c2.getHash());
|
||||
fileData.getChunks().put((long) c1.getBytes().length + c2.getBytes().length, c3.getHash());
|
||||
return null;
|
||||
}));
|
||||
f.getChunks().put(0L, c1.getHash());
|
||||
f.getChunks().put((long) c1.getBytes().length, c2.getHash());
|
||||
f.getChunks().put((long) c1.getBytes().length + c2.getBytes().length, c3.getHash());
|
||||
|
||||
// FIXME: dhfs_files
|
||||
|
||||
jObjectRepository.writeJObject(c1);
|
||||
jObjectRepository.writeJObject(c2);
|
||||
jObjectRepository.writeJObject(c3);
|
||||
jObjectRepository.writeJObject(c1i);
|
||||
jObjectRepository.writeJObject(c2i);
|
||||
jObjectRepository.writeJObject(c3i);
|
||||
jObjectRepository.writeJObject(f);
|
||||
jObjectManager.put(c1);
|
||||
jObjectManager.put(c2);
|
||||
jObjectManager.put(c3);
|
||||
jObjectManager.put(c1i);
|
||||
jObjectManager.put(c2i);
|
||||
jObjectManager.put(c3i);
|
||||
jObjectManager.put(f);
|
||||
}
|
||||
|
||||
String all = "1234567891011";
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.usatiuk.dhfs.storage;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.usatiuk.dhfs.storage.objects.api.*;
|
||||
import io.quarkus.grpc.GrpcClient;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
class Profiles {
|
||||
public static class DhfsObjectGrpcServiceTestProfile implements QuarkusTestProfile {
|
||||
}
|
||||
}
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(Profiles.DhfsObjectGrpcServiceTestProfile.class)
|
||||
class DhfsObjectGrpcServiceTest {
|
||||
@GrpcClient
|
||||
DhfsObjectGrpc dhfsObjectGrpc;
|
||||
|
||||
@Test
|
||||
void writeReadTest() {
|
||||
dhfsObjectGrpc.writeObject(
|
||||
WriteObjectRequest.newBuilder().setName("cool_file")
|
||||
.setData(ByteString.copyFrom("Hello world".getBytes())).build())
|
||||
.await().atMost(Duration.ofSeconds(5));
|
||||
var read = dhfsObjectGrpc.readObject(
|
||||
ReadObjectRequest.newBuilder().setName("cool_file").build())
|
||||
.await().atMost(Duration.ofSeconds(5));
|
||||
Assertions.assertArrayEquals(read.getData().toByteArray(), "Hello world".getBytes());
|
||||
// var found = dhfsObjectGrpc.findObjects(FindObjectsRequest.newBuilder().setNamespace("testns").build())
|
||||
// .await().atMost(Duration.ofSeconds(5));
|
||||
// Assertions.assertIterableEquals(found.getFoundList().stream().map(l -> l.getName()).toList(), List.of("cool_file"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user