package it.cavallium.dbengine.tests; import static java.util.Map.entry; import it.cavallium.dbengine.database.disk.KeyMayExistGetter; import it.cavallium.dbengine.database.disk.rocksdb.LLReadOptions; import it.unimi.dsi.fastutil.bytes.ByteList; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Map; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.Test; import org.rocksdb.Holder; import org.rocksdb.KeyMayExist; import org.rocksdb.KeyMayExist.KeyMayExistEnum; import org.rocksdb.ReadOptions; import org.rocksdb.RocksDBException; //todo: public class TestGetter { private static Map db = Map.ofEntries( entry(bytes("cached-partially"), bytes("123456789")), entry(bytes("cached-totally"), bytes("ciaov")), entry(bytes("cached-without-value"), bytes("ciaov")), entry(bytes("ciao3"), bytes("ciaov")) ); record KeyMayExistResult(KeyMayExist.KeyMayExistEnum keyMayExistEnum, int size, ByteList cachedValue) {} private static Map cache = Map.ofEntries( entry(bytes("cached-partially"), new KeyMayExistResult(KeyMayExistEnum.kExistsWithoutValue, 9, bytes("12345678"))), entry(bytes("cached-totally"), new KeyMayExistResult(KeyMayExistEnum.kExistsWithValue, 5, bytes("ciaov"))), entry(bytes("cached-without-value"), new KeyMayExistResult(KeyMayExistEnum.kExistsWithoutValue, 0, bytes("ciaov"))) ); private static ByteList bytes(String text) { return ByteList.of(text.getBytes(StandardCharsets.UTF_8)); } private static String text(ByteList bytes) { return new String(bytes.toByteArray(), StandardCharsets.UTF_8); } public KeyMayExistGetter getter = new KeyMayExistGetter() { @Override protected KeyMayExist keyMayExist(LLReadOptions readOptions, ByteBuffer key, ByteBuffer value) { return null; } @Override protected boolean keyMayExist(LLReadOptions readOptions, byte[] key, @Nullable Holder valueHolder) { throw new UnsupportedOperationException(); } @Override protected int get(LLReadOptions opt, ByteBuffer key, ByteBuffer value) throws RocksDBException { return 0; } @Override protected byte[] get(LLReadOptions opt, byte[] key) throws RocksDBException, IllegalArgumentException { throw new UnsupportedOperationException(); } @Override protected void recordReadValueNotFoundWithMayExistBloomBufferSize(int value) { } @Override protected void recordReadValueFoundWithBloomUncachedBufferSize(int value) { } @Override protected void recordReadValueFoundWithBloomCacheBufferSize(int value) { } @Override protected void recordReadAttempts(int value) { } @Override protected void recordReadValueNotFoundWithBloomBufferSize(int value) { } @Override protected void recordKeyBufferSize(int value) { } }; @Test public void testSimpleGet() { } }