net.corda.core.serialization.SerializationContext未设置

时间:2017-08-23 05:18:34

标签: corda

从M13升级到M14时,在MockNetwork中测试oracle时出现以下运行时异常。看起来在尝试构建过滤的事务时发生异常。对于M14,我将数据库更改为CordaPersistence = configureDatabase(makeTestDataSourceProperties())。有没有办法让它发挥作用?

    @Test
    fun `sign - ok`() {
        database.transaction {
            val fxRateRequest = FXRateRequest(USD, EUR/*, LocalDate.now(), Tenor("1D")*/)
            val now = Instant.now()
            val fxRateResponse = FXRateContract.Sign(fxRateRequest, BigDecimal(0.8), TimeWindow.between(now, now.plusSeconds(30)))
            val command = Command(fxRateResponse, listOf(oracle_KeyPair.public))
            val state = FXRateContract.State(ALICE)
            val wtx: WireTransaction = TransactionType.General.Builder(DUMMY_NOTARY)
                    .withItems(state, command)
                    .toWireTransaction()
            val ftx: FilteredTransaction = wtx.buildFilteredTransaction(Predicate { x -> /*filterCmds*/fixCmdFilter(x) })

            val signature = oracle.sign(ftx)
            /** Post M13.0, we can use this instead of the assert */
//            wtx.checkSignature(signature)

            assert(signature.verify(ftx.rootHash.bytes))
        }
    }

异常

Write-once property var net.corda.core.serialization.SerializationDefaults.P2P_CONTEXT: net.corda.core.serialization.SerializationContext not set.
java.lang.IllegalStateException: Write-once property var net.corda.core.serialization.SerializationDefaults.P2P_CONTEXT: net.corda.core.serialization.SerializationContext not set.
    at net.corda.core.internal.WriteOnceProperty.getValue(WriteOnceProperty.kt:12)
    at net.corda.core.serialization.SerializationDefaults.getP2P_CONTEXT(SerializationAPI.kt)
    at net.corda.core.transactions.MerkleTransactionKt.serializedHash(MerkleTransaction.kt:16)
    at net.corda.core.transactions.TraversableTransaction$DefaultImpls.getAvailableComponentHashes(MerkleTransaction.kt:68)
    at net.corda.core.transactions.WireTransaction.getAvailableComponentHashes(WireTransaction.kt:20)
    at net.corda.core.transactions.WireTransaction$merkleTree$2.invoke(WireTransaction.kt:92)
    at net.corda.core.transactions.WireTransaction$merkleTree$2.invoke(WireTransaction.kt:20)
    at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130)
    at net.corda.core.transactions.WireTransaction.getMerkleTree(WireTransaction.kt)
    at net.corda.core.transactions.FilteredTransaction$Companion.buildMerkleTransaction(MerkleTransaction.kt:124)
    at net.corda.core.transactions.WireTransaction.buildFilteredTransaction(WireTransaction.kt:86)
    at argent.service.NodeFXRateTransactionTest_Mock$sign - ok$1.invoke(NodeFXRateTransactionTest_Mock.kt:121)
    at argent.service.NodeFXRateTransactionTest_Mock$sign - ok$1.invoke(NodeFXRateTransactionTest_Mock.kt:36)
    at net.corda.node.utilities.CordaPersistence.inTopLevelTransaction(CordaPersistence.kt:67)
    at net.corda.node.utilities.CordaPersistence.transaction(CordaPersistence.kt:58)
    at net.corda.node.utilities.CordaPersistence.transaction(CordaPersistence.kt:48)
    at argent.service.NodeFXRateTransactionTest_Mock.sign - ok(NodeFXRateTransactionTest_Mock.kt: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.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.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    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.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
    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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:3)

我们使用的序列化框架在M14中注入,为将来的变化做准备。 MockNetwork应该为你处理这个问题,但是我没有在你给出的堆栈跟踪中看到这一点。对于独立单元测试,请尝试让测试类扩展net.corda.testing.TestDependencyInjectionBase,这将在初始化和重置步骤中包装每个测试,以便为您注入。

如果你不能从那个类扩展,那么你总是可以复制它的行为,但是扩展这个类将是未来何时以及是否需要注入其他组件的未来证据。