使用Firebase和App Engine灵活环境进行集成测试

时间:2016-10-04 16:05:24

标签: google-app-engine firebase integration-testing junit4

我目前正在App Engine灵活环境中开发Java服务器,我在尝试进行集成测试时遇到了一些问题。

问题似乎不是代码,因为只有获取Firebase引用才会发生异常。

@BeforeClass
public static void beforeAllTests() throws IOException {
    String dbJson;
    String dbUrl;
    dbJson = "src/main/webapp/WEB-INF/xxxxx.json";
    dbUrl = "https://xxxx.firebaseio.com/";
    FirebaseOptions options = new  FirebaseOptions.Builder().setServiceAccount(new FileInputStream(dbJson))
            .setDatabaseUrl(dbUrl).build();
    FirebaseApp.initializeApp(options);
    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
}

这足以重现问题。错误日志是:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.firebase.database.core.GaePlatform.getGaeThreadFactory(GaePlatform.java:67)
at com.google.firebase.database.core.GaePlatform.isActive(GaePlatform.java:78)
at com.google.firebase.database.core.Context.getPlatform(Context.java:42)
at com.google.firebase.database.core.Context.ensureLogger(Context.java:211)
at com.google.firebase.database.core.Context.initServices(Context.java:77)
at com.google.firebase.database.core.Context.freeze(Context.java:64)
at com.google.firebase.database.core.RepoManager.createLocalRepo(RepoManager.java:78)
at com.google.firebase.database.core.RepoManager.createRepo(RepoManager.java:28)
at com.google.firebase.database.FirebaseDatabase.ensureRepo(FirebaseDatabase.java:249)
at com.google.firebase.database.FirebaseDatabase.getReference(FirebaseDatabase.java:114)
at com.basetis.appengine.utils.FirebaseUtils.initializeApp(FirebaseUtils.java:15)
at integration.TestIntegration.beforeAllTests(TestIntegration.java:32)
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.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
    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 com.google.firebase.database.core.GaePlatform.getGaeThreadFactory(GaePlatform.java:62)
    ... 26 more
Caused by: java.lang.NullPointerException
    at com.google.appengine.api.ThreadManager.backgroundThreadFactory(ThreadManager.java:72)
    ... 31 more

我正在使用Firebase 3.0.1 SDK。感谢您花时间阅读本文。

0 个答案:

没有答案