2016-08-29 33 views
0

我试图运行Google pubsub java示例 - appengine在本地开发服务器上通过参考this指南推送。Github - Google pubsub java示例 - Maven测试运行失败

$ gcloud config set project <provided-my-application-id> 
$ mvn gcloud:run 

Maven构建成功,但测试运行失败。以下是执行。如何解决这个问题?

E:\java\cloud-pubsub-samples-java-master\appengine-push>mvn gcloud:run 
[INFO] Scanning for projects... 
[WARNING] The POM for com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 is missing, no dependency information available 
[WARNING] Failed to retrieve plugin descriptor for com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815: Plugin com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815 or one of its dependencies could not be resolved: Failure to find com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Example for the Google Cloud Pub/Sub on Google App Engine. 1 
[INFO] ------------------------------------------------------------------------ 
[WARNING] The POM for com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 is missing, no dependency information available 
[WARNING] Failed to retrieve plugin descriptor for com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815: Plugin com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815 or one of its dependencies could not be resolved: Failure to find com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced 
[INFO] 
[INFO] >>> gcloud-maven-plugin:2.0.9.90.v20151210:run (default-cli) > package @ pubsub-appengine-sample >>> 
[INFO] 
[INFO] --- maven-checkstyle-plugin:2.15:check (validate) @ pubsub-appengine-sample --- 
[INFO] Starting audit... 
Audit done. 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pubsub-appengine-sample --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory E:\java\cloud-pubsub-samples-java-master\appengine-push\src\main\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ pubsub-appengine-sample --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 10 source files to E:\java\cloud-pubsub-samples-java-master\appengine-push\target\war\WEB-INF\classes 
[INFO] 
[INFO] --- versions-maven-plugin:2.2:display-dependency-updates (default) @ pubsub-appengine-sample --- 
[INFO] artifact com.google.api-client:google-api-client-appengine: checking for updates from central 
[INFO] artifact com.google.appengine:appengine-api-1.0-sdk: checking for updates from central 
[INFO] artifact junit:junit: checking for updates from central 
[INFO] artifact org.codehaus.jackson:jackson-mapper-asl: checking for updates from central 
[INFO] artifact com.google.apis:google-api-services-pubsub: checking for updates from central 
[INFO] artifact org.mockito:mockito-all: checking for updates from central 
[INFO] The following dependencies in Dependencies have newer versions: 
[INFO] com.google.api-client:google-api-client-appengine ... 1.21.0 -> 1.22.0 
[INFO] com.google.apis:google-api-services-pubsub ... 
[INFO]          v1-rev8-1.21.0 -> v1-rev11-1.22.0 
[INFO] com.google.appengine:appengine-api-1.0-sdk .......... 1.9.31 -> 1.9.42 
[INFO] org.mockito:mockito-all ........................ 1.10.19 -> 2.0.2-beta 
[INFO] 
[INFO] 
[INFO] --- versions-maven-plugin:2.2:display-plugin-updates (default) @ pubsub-appengine-sample --- 
[INFO] 
[INFO] The following plugin updates are available: 
[INFO] com.google.appengine:gcloud-maven-plugin 2.0.9.90.v20151210 -> 2.0.9.121.v20160815 
[INFO] maven-checkstyle-plugin ................................ 2.15 -> 2.17 
[INFO] maven-compiler-plugin .................................. 3.3 -> 3.5.1 
[INFO] org.codehaus.mojo:findbugs-maven-plugin .............. 3.0.3 -> 3.0.4 
[INFO] org.codehaus.mojo:versions-maven-plugin .................. 2.2 -> 2.3 
[INFO] 
[WARNING] The following plugins do not have their version specified: 
[WARNING] maven-clean-plugin ........................ (from super-pom) 3.0.0 
[WARNING] maven-deploy-plugin ....................... (from super-pom) 2.8.2 
[WARNING] maven-install-plugin ...................... (from super-pom) 2.5.2 
[WARNING] maven-resources-plugin .................... (from super-pom) 3.0.1 
[WARNING] maven-site-plugin ......................... (from super-pom) 3.5.1 
[WARNING] maven-surefire-plugin .................... (from super-pom) 2.19.1 
[INFO] 
[INFO] Project defines minimum Maven version as: 3.1.0 
[INFO] Plugins require minimum Maven version of: 3.1.0 
[INFO] Note: the super-pom from Maven 3.3.9 defines some of the plugin 
[INFO]  versions and may be influencing the plugins required minimum Maven 
[INFO]  version. 
[INFO] 
[INFO] No plugins require a newer version of Maven than specified by the pom. 
[INFO] 
[INFO] 
[INFO] --- maven-war-plugin:2.6:exploded (default) @ pubsub-appengine-sample --- 
[INFO] Exploding webapp 
[INFO] Assembling webapp [pubsub-appengine-sample] in [E:\java\cloud-pubsub-samples-java-master\appengine-push\target\war] 
[INFO] Processing war project 
[INFO] Copying webapp resources [E:\java\cloud-pubsub-samples-java-master\appengine-push\src\main\webapp] 
[INFO] Webapp assembled in [859 msecs] 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pubsub-appengine-sample --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory E:\java\cloud-pubsub-samples-java-master\appengine-push\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ pubsub-appengine-sample --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ pubsub-appengine-sample --- 
[INFO] Surefire report directory: E:\java\cloud-pubsub-samples-java-master\appengine-push\target\surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.google.cloud.pubsub.client.demos.appengine.IntegrationTest 
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 2.351 sec <<< FAILURE! 
testTopPage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest)    Time elapsed: 1.442 sec <<< FAILURE! 
java.lang.AssertionError: expected:<200> but was:<404> 
    at org.junit.Assert.fail(Assert.java:88) 
    at org.junit.Assert.failNotEquals(Assert.java:834) 
    at org.junit.Assert.assertEquals(Assert.java:645) 
    at org.junit.Assert.assertEquals(Assert.java:631) 
    at com.google.cloud.pubsub.client.demos.appengine.IntegrationTest.testTopPage(IntegrationTest.java:72) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) 
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) 

    testSendMessage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest)  Time elapsed: 0.369 sec <<< FAILURE! 
java.lang.AssertionError: expected:<204> but was:<404> 
    at org.junit.Assert.fail(Assert.java:88) 
    at org.junit.Assert.failNotEquals(Assert.java:834) 
    at org.junit.Assert.assertEquals(Assert.java:645) 
    at org.junit.Assert.assertEquals(Assert.java:631) 
    at com.google.cloud.pubsub.client.demos.appengine.IntegrationTest.testSendMessage(IntegrationTest.java:151) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) 
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) 

testPushHandlerIsProtected(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest) Time elapsed: 0.336 sec <<< FAILURE! 
java.lang.AssertionError: expected:<302> but was:<404> 
    at org.junit.Assert.fail(Assert.java:88) 
    at org.junit.Assert.failNotEquals(Assert.java:834) 
    at org.junit.Assert.assertEquals(Assert.java:645) 
    at org.junit.Assert.assertEquals(Assert.java:631) 
    at com.google.cloud.pubsub.client.demos.appengine.IntegrationTest.testPushHandlerIsProtected(IntegrationTest.java:128) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) 
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) 


Results : 

Failed tests:  testTopPage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest): expected:<200> but was:<404> 
    testSendMessage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest): expected:<204> but was:<404> 
    testPushHandlerIsProtected(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest): expected:<302> but was:<404> 

Tests run: 3, Failures: 3, Errors: 0, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 23.681 s 
[INFO] Finished at: 2016-08-29T08:28:48+05:30 
[INFO] Final Memory: 31M/333M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire- plugin:2.12.4:test (default-test) on project pubsub-appengine-sample: There are test failures. 
[ERROR] 
[ERROR] Please refer to E:\java\cloud-pubsub-samples-java-master\appengine-push\target\surefire-reports for the individual test results. 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1]  http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

更新 - 试运行失败意见: 我的意见是, 对于testTopPage() - 72号线通过的响应是200元。但在线路84失败,因为内容没有我的项目_id。对于testSendMessage() - 在第133行失败并出现404错误,url = getAppBaseURL()+“send_message”;因为没有这样的资源。

同样,testPushHandlerIsProtected() - 由于没有这样的资源而在第110行出现404错误。

注意:我的项目在appengine中只有hello world应用程序,但这些测试方法正在寻找appengine中不存在的资源。我错过了什么?

+0

您必须在appengine上部署示例应用程序才能使测试正常工作(请参阅编辑我的答案)。 – konqi

回答

0

看看第31行in the test。它使用一个名为'TEST_PROJECT_ID'的不同环境变量(见第24行)。它应该和设置正确的环境变量一样简单。您还可以在单​​元测试中为URL添加调试输出,以便知道使用的是哪个主机名。

编辑1:你是什么意思,你只有在appengine世界你好应用程序? 'send_message'资源和init_servlet(返回由行84断言的项目id)在示例的web.xml中定义。您必须在针对它运行测试之前部署此应用程序(或查找此应用程序已在运行的实例)。如果因为测试失败而无法部署应用程序,则可以通过将-DskipTests参数添加到maven命令来跳过surefire测试。这也被解释为in the readme of the project

+0

环境变量按预期提供。我的观察结果如下: 对于testTopPage() - 第72行,响应代码为200。但在第84行失败,因为内容没有我的项目_id。对于testSendMessage() - 在第133行失败并出现404错误,url = getAppBaseURL()+“send_message”;因为没有这样的资源。 对于testPushHandlerIsProtected() - 由于没有这样的资源而在第110行出现404错误。 这些测试方法正在寻找在appengine中不存在的资源。我错过了什么?如何获得这项工作? – Vetri

+0

用测试运行失败观察更新了问题。 – Vetri

+1

是的。在部署项目时我遇到一些困难。发布一个单独的问题来解决这里部署时遇到的错误 - http://stackoverflow.com/questions/39234400/github-google-pubsub-java-samples-unable-to-deploy-appengine-push-applicatio – Vetri