@Test public void runsClosingCallbackOnShutdown() throws Exception { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .defaultLockTimeoutSeconds(120) .build(); Runnable callback = mock(Runnable.class); TransactionManager manager = TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .build() .serializable(); manager.registerClosingCallback(callback); manager.close(); verify(callback, times(1)).run(); }
public BenchmarksResource(AtlasDbConfig config) { this.txnManager = TransactionManagers.builder() .config(config) .userAgent(UserAgents.DEFAULT_USER_AGENT) .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(new DefaultTaggedMetricRegistry()) .addSchemas(BenchmarksSchema.SCHEMA) .allowHiddenTableAccess(true) .runtimeConfigSupplier(Optional::empty) .build().serializable(); }
@Test public void keyValueServiceMetricsDoNotContainUserAgent() { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .build(); MetricRegistry metrics = new MetricRegistry(); TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(metrics) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .build() .serializable(); assertThat(metrics.getNames().stream() .anyMatch(metricName -> metricName.contains(USER_AGENT_NAME)), is(false)); }
/** * Create a {@link TransactionManager} backed by an * {@link com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService}. This should be used for testing * purposes only. */ public static TransactionManager createInMemory(Set<Schema> schemas) { AtlasDbConfig config = ImmutableAtlasDbConfig.builder().keyValueService(new InMemoryAtlasDbConfig()).build(); return builder() .config(config) .userAgent(UserAgents.DEFAULT_USER_AGENT) .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .addAllSchemas(schemas) .build() .serializable(); }
@Test public void setsGlobalDefaultLockTimeout() { TimeDuration expectedTimeout = SimpleTimeDuration.of(47, TimeUnit.SECONDS); AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .defaultLockTimeoutSeconds((int) expectedTimeout.getTime()) .build(); TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .build() .serializable(); assertEquals(expectedTimeout, LockRequest.getDefaultLockTimeout()); LockRequest lockRequest = LockRequest .builder(ImmutableSortedMap.of(StringLockDescriptor.of("foo"), LockMode.WRITE)).build(); assertEquals(expectedTimeout, lockRequest.getLockTimeout()); }
@Test public void asyncInitializationEventuallySucceeds() { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAsyncAtlasDbConfig()) .initializeAsync(true) .build(); TransactionManager manager = TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .addSchemas(GenericTestSchema.getSchema()) .build() .serializable(); assertFalse(manager.isInitialized()); assertThatThrownBy(() -> manager.runTaskWithRetry(unused -> null)).isInstanceOf(NotInitializedException.class); Awaitility.await().atMost(12, TimeUnit.SECONDS).until(manager::isInitialized); performTransaction(manager); }
@Test public void asyncInitializationIsSynchronousIfKvsIsReady() { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .initializeAsync(true) .build(); TransactionManager manager = TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .addSchemas(GenericTestSchema.getSchema()) .build() .serializable(); assertTrue(manager.isInitialized()); performTransaction(manager); }
/** * Create a {@link TransactionManager} backed by an * {@link com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService}. This should be used for testing * purposes only. */ public static TransactionManager createInMemory(Set<Schema> schemas) { AtlasDbConfig config = ImmutableAtlasDbConfig.builder().keyValueService(new InMemoryAtlasDbConfig()).build(); return builder() .config(config) .userAgent(UserAgents.DEFAULT_USER_AGENT) .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .addAllSchemas(schemas) .build() .serializable(); }
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") private TransactionManager createTransactionManager(AtlasDbConfig config, Optional<AtlasDbRuntimeConfig> atlasDbRuntimeConfigOptional, Environment environment, TaggedMetricRegistry taggedMetricRegistry) { return TransactionManagers.builder() .config(config) .userAgent("ete test") .globalMetricsRegistry(environment.metrics()) .globalTaggedMetricRegistry(taggedMetricRegistry) .registrar(environment.jersey()::register) .addAllSchemas(ETE_SCHEMAS) .runtimeConfigSupplier(() -> atlasDbRuntimeConfigOptional) .build() .serializable(); }