反序列化尾码响应

时间:2019-08-18 23:18:38

标签: java future finagle

我正在为Finagle控制器编写单元测试,并且为了验证,我很难将来自Twitter Future的响应反序列化。当我打印Future时,可以看到所有内容,但是当我执行Await.result()时,会得到一个空指针。我不断得到相同的结果:

java.lang.ClassCastException: java.lang.String cannot be cast to com.twitter.finagle.http.Response

这是我的代码:

        Future
            .value(response)
            .onSuccess(cons(r -> {
                try {
                    Response response1 = Await.result(r);
                    logger.info("response1: {}", response1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }));

关于如何将Future反序列化为我可以检查其值的对象的任何建议?

这是整个堆栈跟踪:

java.lang.ClassCastException: java.lang.String cannot be cast to com.twitter.finagle.http.Response
at com.fitbit.sleep.score.http.SleepScoreControllerUnitTest.lambda$testGetByListIsSuccessful$0(SleepScoreControllerUnitTest.java:83)
at com.twitter.util.Function$$anon$4.apply(Function.scala:122)
at com.twitter.util.Function$$anon$4.apply(Function.scala:121)
at com.twitter.util.Future$$anonfun$onSuccess$1.apply(Future.scala:1820)
at com.twitter.util.Future$$anonfun$onSuccess$1.apply(Future.scala:1819)
at com.twitter.util.ConstFuture$$anon$8.run(Future.scala:2131)
at com.twitter.concurrent.LocalScheduler$Activation.run(Scheduler.scala:198)
at com.twitter.concurrent.LocalScheduler$Activation.submit(Scheduler.scala:157)
at com.twitter.concurrent.LocalScheduler.submit(Scheduler.scala:274)
at com.twitter.concurrent.Scheduler$.submit(Scheduler.scala:109)
at com.twitter.util.ConstFuture.respond(Future.scala:2127)
at com.twitter.util.Future.onSuccess(Future.scala:1819)
at com.fitbit.sleep.score.http.SleepScoreControllerUnitTest.testGetByListIsSuccessful(SleepScoreControllerUnitTest.java:81)
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.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.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

0 个答案:

没有答案