use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class TestingResolverFactory method beforeEach.
@Override
public void beforeEach(@Nonnull final ExtensionContext context) throws Exception {
resolvers.clear();
knownBadEntries.clear();
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(100);
database = factory.getDatabase();
// clear all state in the db
database.close();
// resets the lock cache
database.setResolverStateRefreshTimeMillis(30000);
wipeFDB();
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class ResolverCreateHooksTest method setup.
@BeforeEach
public void setup() {
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
database = factory.getDatabase();
database.clearCaches();
keySpace = new KeySpace(new KeySpaceDirectory("test-root", KeySpaceDirectory.KeyType.STRING, "test-" + random.nextLong()).addSubdirectory(new KeySpaceDirectory("resolvers", KeySpaceDirectory.KeyType.STRING, "resolvers").addSubdirectory(new KeySpaceDirectory("resolverNode", KeySpaceDirectory.KeyType.STRING))).addSubdirectory(new KeySpaceDirectory("should-use-A", KeySpaceDirectory.KeyType.STRING, "should-use-A")));
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class LocatableResolverTest method testResolveUseCacheCommits.
@Test
public void testResolveUseCacheCommits() {
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(10);
FDBStoreTimer timer = new FDBStoreTimer();
String key = "hello " + UUID.randomUUID();
FDBDatabase fdb = factory.getDatabase();
assertEquals(0, timer.getCount(FDBStoreTimer.Events.COMMIT));
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
}
// initial resolve may commit twice, once for the key and once to initialize the reverse directory cache
assertThat(timer.getCount(FDBStoreTimer.Events.COMMIT), is(greaterThanOrEqualTo(1)));
timer.reset();
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), "a-new-key"));
}
assertEquals(1, timer.getCount(FDBStoreTimer.Events.COMMIT));
timer.reset();
assertEquals(0, timer.getCount(FDBStoreTimer.Events.COMMIT));
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
}
assertEquals(0, timer.getCount(FDBStoreTimer.Events.COMMIT));
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class LocatableResolverTest method testDirectoryCache.
@Test
public void testDirectoryCache() {
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(10);
FDBStoreTimer timer = new FDBStoreTimer();
FDBDatabase fdb = factory.getDatabase();
// Make sure cache is fresh.
fdb.close();
String key = "world";
Long value;
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
value = context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
}
int initialReads = timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
assertThat(initialReads, is(greaterThanOrEqualTo(1)));
for (int i = 0; i < 10; i++) {
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
assertThat("we continue to resolve the same value", context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key)), is(value));
}
}
assertEquals(timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ), initialReads);
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class LocatableResolverTest method testVersionIncrementInvalidatesCache.
@Test
public void testVersionIncrementInvalidatesCache() {
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(10);
FDBStoreTimer timer = new FDBStoreTimer();
FDBDatabase fdb = factory.getDatabase();
// Make sure cache is fresh, and resets version
fdb.close();
fdb.setResolverStateRefreshTimeMillis(100);
String key = "some-key";
Long value;
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
value = context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
}
assertThat(timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ), is(greaterThanOrEqualTo(1)));
timer.reset();
consistently("we hit the cached value", () -> {
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
assertThat("the resolved value is still the same", globalScope.resolve(context.getTimer(), key).join(), is(value));
}
return timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
}, is(0), 200, 10);
globalScope.incrementVersion().join();
timer.reset();
eventually("we see the version change and invalidate the cache", () -> {
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
assertThat("the resolved value is still the same", globalScope.resolve(context.getTimer(), key).join(), is(value));
}
return timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
}, is(1), 120, 10);
timer.reset();
consistently("the value is cached while the version is not changed", () -> {
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
assertThat("the resolved value is still the same", globalScope.resolve(context.getTimer(), key).join(), is(value));
}
return timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
}, is(0), 200, 10);
}
Aggregations