简体   繁体   English

Java单元测试Google AppEngine内存缓存独立

[英]Java Unit testing Google AppEngine memcache standalone

I'm attempting to write unit tests for my Java AppEngine application around my caching service. 我试图围绕我的缓存服务为Java AppEngine应用程序编写单元测试。 Any time I make a get or put I get the following exception: 任何时候我获得或获得我都会得到以下异常:

Can't make API call memcache.Get in a thread that is neither the original request thread nor a thread created by ThreadManager 无法使API调用memcache。进入既不是 原始请求线程也不是ThreadManager创建的线程的线程

My implementation is simple enough: 我的实现很简单:

MemcacheServiceFactory.getAsyncMemcacheService(NAMESPACE).get("key")
MemcacheServiceFactory.getAsyncMemcacheService(NAMESPACE).put("key", "value")

I have also tried: 我也尝试过:

MemcacheServiceFactory.getMemcacheService(NAMESPACE).get("key")
MemcacheServiceFactory.getMemcacheService(NAMESPACE).put("key", "value")

This works just fine when I'm running it as a "local deployment" as part of my web service as a whole, but the standalone test on this section of code will not work. 当我将其作为整个Web服务的一部分作为“本地部署”运行时,此方法很好用,但是对本节代码的独立测试将无法正常工作。

Is there any way to test the memcache service stand alone - outside of the gae envirnment? 有什么方法可以在gae环境之外单独测试memcache服务?

Have you initialized LocalServiceTestHelper like that? 您是否像这样初始化了LocalServiceTestHelper?

private final LocalServiceTestHelper helper =
  new LocalServiceTestHelper(new LocalMemcacheServiceTestConfig());

Here you can find an example: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java 在这里您可以找到一个示例: https : //github.com/GoogleCloudPlatform/java-docs-samples/blob/master/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM