升级到 SDK 1.9.17 后 JUnit 测试失败

JUnit Tests Failing After Upgrading to SDK 1.9.17

我们最近更新到 AppEngine SDK 1.9.17。当我尝试 运行 我的 JUnit 测试时,我每次尝试使用 JDO 访问数据存储时都会出错。具体来说,我得到的错误是:

java.lang.NoSuchMethodError: com.google.appengine.repackaged.com.google.io.protocol.ProtocolMessage.storeStringsOnlyAsBytes()Z
at com.google.storage.onestore.v3.OnestoreEntity$Reference.setApp(OnestoreEntity.java:6598)
at com.google.appengine.api.datastore.KeyTranslator.convertToPb(KeyTranslator.java:50)
at com.google.appengine.api.datastore.EntityTranslator.convertToPb(EntityTranslator.java:48)
at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.toPb(AsyncDatastoreServiceImpl.java:178)
at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.toPb(AsyncDatastoreServiceImpl.java:155)
at com.google.appengine.api.datastore.Batcher$BatchIterator.<init>(Batcher.java:180)
at com.google.appengine.api.datastore.Batcher.<init>(Batcher.java:317)
at com.google.appengine.api.datastore.Batcher.getBatches(Batcher.java:317)
at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.doBatchPut(AsyncDatastoreServiceImpl.java:365)
at com.google.appengine.api.datastore.BaseAsyncDatastoreServiceImpl.put(BaseAsyncDatastoreServiceImpl.java:293)
at com.google.appengine.api.datastore.BaseAsyncDatastoreServiceImpl.runInternal(BaseAsyncDatastoreServiceImpl.java:261)
at com.google.appengine.api.datastore.TransactionRunner.runWriteInTransaction(TransactionRunner.java:53)
at com.google.appengine.api.datastore.BaseAsyncDatastoreServiceImpl.put(BaseAsyncDatastoreServiceImpl.java:258)
at com.google.appengine.api.datastore.BaseAsyncDatastoreServiceImpl.put(BaseAsyncDatastoreServiceImpl.java:234)
at com.google.appengine.api.datastore.DatastoreServiceImpl.put(DatastoreServiceImpl.java:56)
at com.google.appengine.datanucleus.WrappedDatastoreService.put(WrappedDatastoreService.java:100)
at com.google.appengine.datanucleus.EntityUtils.putEntitiesIntoDatastore(EntityUtils.java:759)
at com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:314)
at com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:218)
at org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2381)
at org.datanucleus.state.JDOStateManager.makePersistent(JDOStateManager.java:2357)
at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1896)
at org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1745)
at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1602)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:731)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:756)
...

打开几个一般依赖的jar,重新打包的com.google.io包完全不见了

我尝试过的事情:

  1. 将 JUnit 测试的类路径从 1.9.14 更新到 1.9.17
  2. 尝试在 lib/impl 目录中添加额外的 google_sql.jar
  3. 删除所有 lib/impl 个罐子,然后一次一个地添加回来

还有其他人运行参与其中吗?

啊哈!作为 JUnit 和 AppEngine 的 documentation 的一部分,您必须将两个文件复制到项目的 WEB-INF/lib 目录。

appengine-api-labs.jar
appengine-testing.jar

升级时,不仅要更新Eclipse中的JUnit Debug Configuration,还要更新(copy/overwrite)后面SDK中的这两个文件