• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DatastoreTimeoutException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.appengine.api.datastore.DatastoreTimeoutException的典型用法代码示例。如果您正苦于以下问题:Java DatastoreTimeoutException类的具体用法?Java DatastoreTimeoutException怎么用?Java DatastoreTimeoutException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DatastoreTimeoutException类属于com.google.appengine.api.datastore包,在下文中一共展示了DatastoreTimeoutException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRun_retryOnTransientFailure

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@Test
public void testRun_retryOnTransientFailure() throws Exception {
  persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4"));
  WhoisServer server = newWhoisServer("ns1.cat.lol");
  WhoisResponse expectedResponse =
      server.whoisReader.readCommand(server.input, clock.nowUtc()).executeQuery(clock.nowUtc());

  WhoisReader mockReader = mock(WhoisReader.class);
  WhoisCommand mockCommand = mock(WhoisCommand.class);
  when(mockReader.readCommand(any(Reader.class), any(DateTime.class))).thenReturn(mockCommand);
  when(mockCommand.executeQuery(any(DateTime.class)))
      .thenThrow(new DatastoreFailureException("Expected transient exception #1"))
      .thenThrow(new DatastoreTimeoutException("Expected transient exception #2"))
      .thenReturn(expectedResponse);

  server.whoisReader = mockReader;
  server.run();
  assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_nameserver.txt"));
}
 
开发者ID:google,项目名称:nomulus,代码行数:20,代码来源:WhoisServerTest.java


示例2: testTransact_datastoreTimeoutException_noManifest_retries

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@Test
public void testTransact_datastoreTimeoutException_noManifest_retries() {
  assertThat(ofy().transact(new Work<Integer>() {

    int count = 0;

    @Override
    public Integer run() {
      // We don't write anything in this transaction, so there is no commit log manifest.
      // Therefore it's always safe to retry since nothing got written.
      count++;
      if (count == 3) {
        return count;
      }
      throw new DatastoreTimeoutException("");
    }})).isEqualTo(3);
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:OfyTest.java


示例3: testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@Test
public void testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries() {
  assertThat(ofy().transact(new Work<Integer>() {

    int count = 0;

    @Override
    public Integer run() {
      // There will be something in the manifest now, but it won't be committed if we throw.
      ofy().save().entity(someObject);
      count++;
      if (count == 3) {
        return count;
      }
      throw new DatastoreTimeoutException("");
    }})).isEqualTo(3);
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:OfyTest.java


示例4: beginTransaction

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
private CheckedTransaction beginTransaction(final TransactionOptions options)
    throws PermanentFailure, RetryableFailure {
  return safeRun(new Evaluater<CheckedTransaction>() {
    @Override public CheckedTransaction run() {
      Transaction rawTransaction = datastore.beginTransaction(options);
      // NOTE(ohler): Calling rawTransaction.getId() forces TransactionImpl to
      // wait for the result of the beginTransaction RPC.  We do this here to
      // get the DatastoreTimeoutException (in the case of a timeout) right
      // away rather than at some surprising time later in
      // TransactionImpl.toString() or similar.
      //
      // Hopefully, TransactionImpl will be fixed to eliminate the need for
      // this.
      try {
        rawTransaction.getId();
      } catch (DatastoreTimeoutException e) {
        // We don't log transaction itself because I'm worried its toString()
        // might fail.  TODO(ohler): confirm this.
        log.log(Level.WARNING, "Failed to begin transaction", e);
        // Now we need to roll back the transaction (even though it doesn't
        // actually exist), otherwise TransactionCleanupFilter will try to
        // roll it back, which is bad because it's not prepared for the crash
        // that we catch below.
        try {
          rawTransaction.rollback();
          throw new Error("Rollback of nonexistent transaction did not fail");
        } catch (DatastoreTimeoutException e2) {
          log.log(Level.INFO, "Rollback of nonexistent transaction failed as expected", e2);
        }
        throw e;
      }
      CheckedTransaction checkedTransaction = new CheckedTransactionImpl(rawTransaction);
      log.info("Begun transaction " + checkedTransaction);
      return checkedTransaction;
    }
  });
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:38,代码来源:CheckedDatastore.java


示例5: transactCommitLoggedWork

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
/**
 * Transact with commit logs and retry with exponential backoff.
 *
 * <p>This method is broken out from {@link #transactNew(Work)} for testing purposes.
 */
@VisibleForTesting
<R> R transactCommitLoggedWork(CommitLoggedWork<R> work) {
  long baseRetryMillis = getBaseOfyRetryDuration().getMillis();
  for (long attempt = 0, sleepMillis = baseRetryMillis;
      true;
      attempt++, sleepMillis *= 2) {
    try {
      ofy().transactNew(work);
      return work.getResult();
    } catch (TransientFailureException
        | TimestampInversionException
        | DatastoreTimeoutException
        | DatastoreFailureException e) {
      // TransientFailureExceptions come from task queues and always mean nothing committed.
      // TimestampInversionExceptions are thrown by our code and are always retryable as well.
      // However, Datastore exceptions might get thrown even if the transaction succeeded.
      if ((e instanceof DatastoreTimeoutException || e instanceof DatastoreFailureException)
          && checkIfAlreadySucceeded(work)) {
        return work.getResult();
      }
      if (attempt == NUM_RETRIES) {
        throw e;  // Give up.
      }
      sleeper.sleepUninterruptibly(Duration.millis(sleepMillis));
      logger.infofmt(e, "Retrying %s, attempt %s", e.getClass().getSimpleName(), attempt);
    }
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:34,代码来源:Ofy.java


示例6: testTransact_datastoreTimeoutException_manifestWrittenToDatastore_returnsSuccess

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@Test
public void testTransact_datastoreTimeoutException_manifestWrittenToDatastore_returnsSuccess() {
  // A work unit that throws if it is ever retried.
  VoidWork work = new VoidWork() {
    boolean firstCallToVrun = true;

    @Override
    public void vrun() {
      if (firstCallToVrun) {
        firstCallToVrun = false;
        ofy().save().entity(someObject);
        return;
      }
      fail("Shouldn't have retried.");
    }};
  // A commit logged work that throws on the first attempt to get its result.
  CommitLoggedWork<Void> commitLoggedWork = new CommitLoggedWork<Void>(work, new SystemClock()) {
    boolean firstCallToGetResult = true;

    @Override
    public Void getResult() {
      if (firstCallToGetResult) {
        firstCallToGetResult = false;
        throw new DatastoreTimeoutException("");
      }
      return null;
    }};
  // Despite the DatastoreTimeoutException in the first call to getResult(), this should succeed
  // without retrying. If a retry is triggered, the test should fail due to the call to fail().
  ofy().transactCommitLoggedWork(commitLoggedWork);
}
 
开发者ID:google,项目名称:nomulus,代码行数:32,代码来源:OfyTest.java


示例7: saveSession

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@Override
public void saveSession(String key, SessionData data) throws Retryable {
  try {
    datastore.put(createEntityForSession(key, data));
  } catch (DatastoreTimeoutException e) {
    throw new Retryable(e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:9,代码来源:DatastoreSessionStore.java


示例8: makeSyncCall

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public byte[] makeSyncCall(
    ApiProxy.Environment environment, String packageName, String methodName, byte[] request)
    throws ApiProxyException {
  if (packageName.equals("datastore_v3") && timeoutCount > 0) {
    timeoutCount--;
    throw new DatastoreTimeoutException("Timeout");
  }
  return delegate.makeSyncCall(environment, packageName, methodName, request);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:11,代码来源:SessionManagerTest.java


示例9: makeAsyncCall

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
public Future<byte[]> makeAsyncCall(
    ApiProxy.Environment environment,
    String packageName,
    String methodName,
    byte[] request,
    ApiProxy.ApiConfig apiConfig) {
  if (packageName.equals("datastore_v3") && timeoutCount > 0) {
    timeoutCount--;
    throw new DatastoreTimeoutException("Timeout");
  }
  return delegate.makeAsyncCall(environment, packageName, methodName, request, apiConfig);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:13,代码来源:SessionManagerTest.java


示例10: beginTransaction

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
private CheckedTransaction beginTransaction(final TransactionOptions options)
    throws PermanentFailure, RetryableFailure {
  return safeRun(new Evaluater<CheckedTransaction>() {
    @Override
    public CheckedTransaction run() {
      Transaction rawTransaction = datastore.beginTransaction(options);
      // NOTE(ohler): Calling rawTransaction.getId() forces TransactionImpl to
      // wait for the result of the beginTransaction RPC. We do this here to
      // get the DatastoreTimeoutException (in the case of a timeout) right
      // away rather than at some surprising time later in
      // TransactionImpl.toString() or similar.
      //
      // Hopefully, TransactionImpl will be fixed to eliminate the need for
      // this.
      try {
        rawTransaction.getId();
      } catch (DatastoreTimeoutException e) {
        // We don't log transaction itself because I'm worried its toString()
        // might fail. TODO(ohler): confirm this.
        log.log(Level.WARNING, "Failed to begin transaction", e);
        // Now we need to roll back the transaction (even though it doesn't
        // actually exist), otherwise TransactionCleanupFilter will try to
        // roll it back, which is bad because it's not prepared for the crash
        // that we catch below.
        try {
          rawTransaction.rollback();
          throw new Error("Rollback of nonexistent transaction did not fail");
        } catch (DatastoreTimeoutException e2) {
          log.log(Level.INFO, "Rollback of nonexistent transaction failed as expected", e2);
        }
        throw e;
      }
      CheckedTransaction checkedTransaction = new CheckedTransactionImpl(rawTransaction);
      log.info("Begun transaction " + checkedTransaction);
      return checkedTransaction;
    }
  });
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:39,代码来源:CheckedDatastore.java


示例11: testTransactNewReadOnly_datastoreTimeoutException_retries

import com.google.appengine.api.datastore.DatastoreTimeoutException; //导入依赖的package包/类
@Test
public void testTransactNewReadOnly_datastoreTimeoutException_retries() {
  doReadOnlyRetryTest(new DatastoreTimeoutException(""));
}
 
开发者ID:google,项目名称:nomulus,代码行数:5,代码来源:OfyTest.java



注:本文中的com.google.appengine.api.datastore.DatastoreTimeoutException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SerializerException类代码示例发布时间:2022-05-23
下一篇:
Java ClusterEventListener类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap