Search in sources :

Example 1 with ForwardingKeyValueService

use of com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService in project atlasdb by palantir.

the class SchemaMetadataServiceImplTest method canInitializeAsynchronously.

@Test
public void canInitializeAsynchronously() {
    ForwardingKeyValueService forwardingKeyValueService = new ForwardingKeyValueService() {

        private KeyValueService realKeyValueService = new InMemoryKeyValueService(true);

        private boolean fail = true;

        @Override
        protected KeyValueService delegate() {
            if (fail) {
                fail = false;
                return mock(KeyValueService.class, (Answer) invocation -> {
                    throw new RuntimeException("I am unhappy");
                });
            }
            return realKeyValueService;
        }
    };
    SchemaMetadataService metadataService = SchemaMetadataServiceImpl.create(forwardingKeyValueService, true);
    assertThatThrownBy(() -> metadataService.putSchemaMetadata(SCHEMA_NAME_ONE, SCHEMA_METADATA_ONE)).isInstanceOf(NotInitializedException.class);
    Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(metadataService::isInitialized);
    metadataService.putSchemaMetadata(SCHEMA_NAME_ONE, SCHEMA_METADATA_ONE);
    assertThat(metadataService.loadSchemaMetadata(SCHEMA_NAME_ONE)).contains(SCHEMA_METADATA_ONE);
}
Also used : IntStream(java.util.stream.IntStream) NotInitializedException(com.palantir.exception.NotInitializedException) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) ImmutableMap(com.google.common.collect.ImmutableMap) SchemaMetadataService(com.palantir.atlasdb.schema.metadata.SchemaMetadataService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) TimeUnit(java.util.concurrent.TimeUnit) Answer(org.mockito.stubbing.Answer) ImmutableSchemaDependentTableMetadata(com.palantir.atlasdb.schema.ImmutableSchemaDependentTableMetadata) ImmutableStreamStoreCleanupMetadata(com.palantir.atlasdb.schema.cleanup.ImmutableStreamStoreCleanupMetadata) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ValueType(com.palantir.atlasdb.table.description.ValueType) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ImmutableSchemaMetadata(com.palantir.atlasdb.schema.ImmutableSchemaMetadata) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) SchemaMetadataServiceImpl(com.palantir.atlasdb.schema.metadata.SchemaMetadataServiceImpl) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) SchemaMetadata(com.palantir.atlasdb.schema.SchemaMetadata) NullCleanupMetadata(com.palantir.atlasdb.schema.cleanup.NullCleanupMetadata) SchemaMetadataService(com.palantir.atlasdb.schema.metadata.SchemaMetadataService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)1 Namespace (com.palantir.atlasdb.keyvalue.api.Namespace)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 ForwardingKeyValueService (com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService)1 InMemoryKeyValueService (com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService)1 ImmutableSchemaDependentTableMetadata (com.palantir.atlasdb.schema.ImmutableSchemaDependentTableMetadata)1 ImmutableSchemaMetadata (com.palantir.atlasdb.schema.ImmutableSchemaMetadata)1 SchemaMetadata (com.palantir.atlasdb.schema.SchemaMetadata)1 ImmutableStreamStoreCleanupMetadata (com.palantir.atlasdb.schema.cleanup.ImmutableStreamStoreCleanupMetadata)1 NullCleanupMetadata (com.palantir.atlasdb.schema.cleanup.NullCleanupMetadata)1 SchemaMetadataService (com.palantir.atlasdb.schema.metadata.SchemaMetadataService)1 SchemaMetadataServiceImpl (com.palantir.atlasdb.schema.metadata.SchemaMetadataServiceImpl)1 ValueType (com.palantir.atlasdb.table.description.ValueType)1 NotInitializedException (com.palantir.exception.NotInitializedException)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1