Search in sources :

Example 6 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class LocatableResolverTest method testParallelDbAndScopeGetVersion.

@Test
public void testParallelDbAndScopeGetVersion() {
    // version is cached for 30 seconds by default
    database.setResolverStateRefreshTimeMillis(100);
    // sets the timeout for all the db instances we create
    final FDBDatabaseFactory parallelFactory = new FDBDatabaseFactoryImpl();
    parallelFactory.setStateRefreshTimeMillis(100);
    Supplier<FDBDatabase> databaseSupplier = () -> new FDBDatabase(parallelFactory, null);
    consistently("uninitialized version is 0", () -> {
        try (FDBRecordContext context = database.openContext()) {
            return globalScope.getVersion(context.getTimer()).join();
        }
    }, is(0), 200, 10);
    List<Pair<FDBDatabase, LocatableResolver>> simulatedInstances = IntStream.range(0, 20).mapToObj(i -> {
        FDBDatabase db = databaseSupplier.get();
        return Pair.of(db, resolverFactory.getGlobalScope(db));
    }).collect(Collectors.toList());
    Supplier<CompletableFuture<Set<Integer>>> supplier = () -> {
        List<CompletableFuture<Integer>> parallelOperations = simulatedInstances.stream().map(pair -> {
            FDBDatabase db = pair.getKey();
            LocatableResolver resolver = pair.getValue();
            FDBRecordContext context = db.openContext();
            return resolver.getVersion(context.getTimer()).whenComplete((ignore, e) -> context.close());
        }).collect(Collectors.toList());
        return AsyncUtil.getAll(parallelOperations).thenApply(HashSet::new);
    };
    consistently("all instances report the version as 0", () -> supplier.get().join(), is(Collections.singleton(0)), 200, 10);
    globalScope.incrementVersion().join();
    eventually("all instances report the new version once the caches have refreshed", () -> supplier.get().join(), is(Collections.singleton(1)), 120, 10);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) BiFunction(java.util.function.BiFunction) Matchers.not(org.hamcrest.Matchers.not) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Random(java.util.Random) LocatableResolverLockedException(com.apple.foundationdb.record.provider.foundationdb.keyspace.LocatableResolver.LocatableResolverLockedException) TestHelpers.consistently(com.apple.foundationdb.record.TestHelpers.consistently) Matchers.hasKey(org.hamcrest.Matchers.hasKey) ExceptionMessageMatcher.hasMessageContaining(com.apple.foundationdb.record.TestHelpers.ExceptionMessageMatcher.hasMessageContaining) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Tuple(com.apple.foundationdb.tuple.Tuple) Pair(org.apache.commons.lang3.tuple.Pair) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Tag(org.junit.jupiter.api.Tag) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FDBRecordContextConfig(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) CacheBuilder(com.google.common.cache.CacheBuilder) DEFAULT_CHECK(com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolverCreateHooks.DEFAULT_CHECK) CacheStats(com.google.common.cache.CacheStats) FDBDatabaseFactoryImpl(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactoryImpl) IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MetadataHook(com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolverCreateHooks.MetadataHook) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) Supplier(java.util.function.Supplier) FDBTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBTestBase) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) TestHelpers.eventually(com.apple.foundationdb.record.TestHelpers.eventually) KeyType(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType) ImmutableList(com.google.common.collect.ImmutableList) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ScanProperties(com.apple.foundationdb.record.ScanProperties) BooleanSource(com.apple.test.BooleanSource) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) MoreAsyncUtil(com.apple.foundationdb.async.MoreAsyncUtil) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Tags(com.apple.test.Tags) TimeUnit(java.util.concurrent.TimeUnit) DEFAULT_HOOK(com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolverCreateHooks.DEFAULT_HOOK) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) PreWriteCheck(com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolverCreateHooks.PreWriteCheck) FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableFuture(java.util.concurrent.CompletableFuture) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) FDBDatabaseFactoryImpl(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactoryImpl) FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class ResolverMappingDigestTest method setup.

@BeforeEach
public void setup() {
    keySpace = new KeySpace(new KeySpaceDirectory("test-path", KeyType.STRING, "test-path-" + random.nextLong()).addSubdirectory(new KeySpaceDirectory("to", KeyType.STRING, "to").addSubdirectory(new KeySpaceDirectory("primary", KeyType.STRING, "primary")).addSubdirectory(new KeySpaceDirectory("replica", KeyType.STRING, "replica"))));
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setDirectoryCacheSize(100);
    database = factory.getDatabase();
    // wipe test keyspace
    KeySpacePath basePath = keySpace.path("test-path");
    database.run(context -> {
        basePath.deleteAllData(context);
        return null;
    });
}
Also used : FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class ResolverMappingReplicatorTest method setupBase.

@BeforeEach
public void setupBase() {
    keySpace = new KeySpace(new KeySpaceDirectory("test-path", KeyType.STRING, "test-path-" + random.nextLong()).addSubdirectory(new KeySpaceDirectory("to", KeyType.STRING, "to").addSubdirectory(new KeySpaceDirectory("primary", KeyType.STRING, "primary")).addSubdirectory(new KeySpaceDirectory("replica", KeyType.STRING, "replica"))));
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setDirectoryCacheSize(100);
    database = factory.getDatabase();
    database.clearCaches();
    KeySpacePath basePath = keySpace.path("test-path");
    // wipe test keyspace
    database.run(context -> {
        context.ensureActive().clear(Range.startsWith(basePath.toTuple(context).pack()));
        return null;
    });
}
Also used : FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

FDBDatabaseFactory (com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory)8 FDBDatabase (com.apple.foundationdb.record.provider.foundationdb.FDBDatabase)4 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)4 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)1 MoreAsyncUtil (com.apple.foundationdb.async.MoreAsyncUtil)1 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)1 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 ScanProperties (com.apple.foundationdb.record.ScanProperties)1 ExceptionMessageMatcher.hasMessageContaining (com.apple.foundationdb.record.TestHelpers.ExceptionMessageMatcher.hasMessageContaining)1 TestHelpers.consistently (com.apple.foundationdb.record.TestHelpers.consistently)1 TestHelpers.eventually (com.apple.foundationdb.record.TestHelpers.eventually)1 FDBDatabaseFactoryImpl (com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactoryImpl)1 FDBRecordContextConfig (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig)1 FDBTestBase (com.apple.foundationdb.record.provider.foundationdb.FDBTestBase)1 KeyType (com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType)1 LocatableResolverLockedException (com.apple.foundationdb.record.provider.foundationdb.keyspace.LocatableResolver.LocatableResolverLockedException)1