com.palantir.atlasdb.transaction.api.TransactionManager.isInitialized()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.palantir.atlasdb.transaction.api.TransactionManager.isInitialized()方法的一些代码示例,展示了TransactionManager.isInitialized()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager.isInitialized()方法的具体详情如下:
包路径:com.palantir.atlasdb.transaction.api.TransactionManager
类名称:TransactionManager
方法名:isInitialized

TransactionManager.isInitialized介绍

[英]Whether this transaction manager has established a connection to the backing store and timestamp/lock services, and is ready to service transactions. If an attempt is made to execute a transaction when this method returns false, a NotInitializedException will be thrown. This method is used for TransactionManagers that can be initialized asynchronously (i.e. those extending com.palantir.async.initializer.AsyncInitializer; other TransactionManagers can keep the default implementation, and return true (they're trivially fully initialized).
[中]此事务管理器是否已建立到备份存储和时间戳/锁服务的连接,并准备好为事务提供服务。如果在该方法返回false时尝试执行事务,则会抛出NotInitializedException。此方法用于可以异步初始化的TransactionManager(即那些扩展com.palantir.async.initializer.AsyncInitializer的TransactionManager;其他TransactionManager可以保留默认实现,并返回true(它们通常完全初始化)。

代码示例

代码示例来源:origin: palantir/atlasdb

private void waitUntilTransactionManagerIsReady() throws InterruptedException {
  while (!transactionManager.isInitialized()) {
    log.info("Waiting for transaction manager to be initialized; going to sleep for {} ms while waiting",
        SafeArg.of("sleepTimeMillis", SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS));
    sleepForMillis(SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS);
  }
}

代码示例来源:origin: palantir/atlasdb

@Test
public void transactionManagerCannotInitializeWhilePrerequisitesAreFalse() {
  assertFalse(manager.isInitialized());
  tickInitializingThread();
  assertFalse(manager.isInitialized());
  tickInitializingThread();
  assertFalse(manager.isInitialized());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void callbackRunsOnlyOnceAsInitializationStatusChanges() {
  everythingInitialized();
  tickInitializingThread();
  assertTrue(manager.isInitialized());
  nothingInitialized();
  assertFalse(manager.isInitialized());
  everythingInitialized();
  assertTrue(manager.isInitialized());
  verify(mockCallback, times(1)).runWithRetry(any(SerializableTransactionManager.class));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void isInitializedAndCallbackHasRunWhenPrerequisitesAreInitialized() {
  everythingInitialized();
  tickInitializingThread();
  assertTrue(manager.isInitialized());
  verify(mockCallback, times(1)).runWithRetry(any(SerializableTransactionManager.class));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void switchBackToUninitializedImmediatelyWhenPrerequisitesBecomeFalse() {
  everythingInitialized();
  tickInitializingThread();
  assertTrue(manager.isInitialized());
  nothingInitialized();
  assertFalse(manager.isInitialized());
  assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(NotInitializedException.class);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void isNotInitializedWhenCleanerIsNotInitialized() {
  setInitializationStatus(true, true, false, true);
  tickInitializingThread();
  assertFalse(manager.isInitialized());
  verify(mockCallback, never()).runWithRetry(any(SerializableTransactionManager.class));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void isNotInitializedWhenInitializerIsNotInitialized() {
  setInitializationStatus(true, true, true, false);
  tickInitializingThread();
  assertFalse(manager.isInitialized());
  verify(mockCallback, never()).runWithRetry(any(SerializableTransactionManager.class));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void isNotInitializedWhenKvsIsNotInitialized() {
  setInitializationStatus(false, true, true, true);
  tickInitializingThread();
  assertFalse(manager.isInitialized());
  verify(mockCallback, never()).runWithRetry(any(SerializableTransactionManager.class));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void isNotInitializedWhenTimelockIsNotInitialized() {
  setInitializationStatus(true, false, true, true);
  tickInitializingThread();
  assertFalse(manager.isInitialized());
  verify(mockCallback, never()).runWithRetry(any(SerializableTransactionManager.class));
}

代码示例来源:origin: palantir/atlasdb

@Test
public void synchronouslyInitializedManagerIsInitializedEvenIfNothingElseIs() {
  manager = getManagerWithCallback(false, mockCallback, executorService);
  assertTrue(manager.isInitialized());
  verify(mockCallback).runWithRetry(manager);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void initializingExecutorShutsDownWhenInitialized() {
  everythingInitialized();
  tickInitializingThread();
  assertTrue(manager.isInitialized());
  assertTrue(executorService.isShutdown());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void callbackBlocksInitializationUntilDone() {
  everythingInitialized();
  ClusterAvailabilityStatusBlockingCallback blockingCallback = new ClusterAvailabilityStatusBlockingCallback();
  manager = getManagerWithCallback(true, blockingCallback, executorService);
  ExecutorService tickerThread = PTExecutors.newSingleThreadExecutor(true);
  tickerThread.submit(() -> executorService.tick(1000, TimeUnit.MILLISECONDS));
  Awaitility.waitAtMost(THREE, TimeUnit.SECONDS).until(blockingCallback::wasInvoked);
  assertFalse(manager.isInitialized());
  blockingCallback.stopBlocking();
  Awaitility.waitAtMost(THREE, TimeUnit.SECONDS).until(manager::isInitialized);
  tickerThread.shutdown();
}

代码示例来源:origin: palantir/atlasdb

@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);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void callbackRunsAfterPreconditionsAreMet() {
  ClusterAvailabilityStatusBlockingCallback blockingCallback = new ClusterAvailabilityStatusBlockingCallback();
  blockingCallback.stopBlocking();
  manager = getManagerWithCallback(true, blockingCallback, executorService);
  tickInitializingThread();
  assertFalse(manager.isInitialized());
  assertFalse(blockingCallback.wasInvoked());
  everythingInitialized();
  tickInitializingThread();
  assertTrue(blockingCallback.wasInvoked());
}

代码示例来源:origin: com.palantir.atlasdb/atlasdb-impl-shared

private void waitUntilTransactionManagerIsReady() throws InterruptedException {
  while (!transactionManager.isInitialized()) {
    log.info("Waiting for transaction manager to be initialized; going to sleep for {} ms while waiting",
        SafeArg.of("sleepTimeMillis", SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS));
    sleepForMillis(SLEEP_TIME_WHEN_NOTHING_TO_COMPACT_MIN_MILLIS);
  }
}

代码示例来源:origin: palantir/atlasdb

@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);
}

相关文章