2017-08-23 63 views
1

從M13升級到M14時,在MockNetwork中測試Oracle時,我得到以下運行時異常。看起來像嘗試構建過濾的事務時發生異常。對於M14,我將數據庫更改爲CordaPersistence = configureDatabase(makeTestDataSourceProperties())。有沒有辦法讓它工作?net.corda.core.serialization.SerializationContext未設置

@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) 

回答

3

我們使用的序列化框架在M14成爲注入準備爲未來的變化。 MockNetwork應該爲你處理這個問題,但是我沒有看到你給出的堆棧跟蹤。對於獨立單元測試,請嘗試讓您的測試類延伸net.corda.testing.TestDependencyInjectionBase,它將每個測試包裝在一個初始化和重置步驟中以便爲您注入。

如果你不能從這個類繼承,那麼你總是可以複製它的行爲,但是如果我們需要在將來注入其他組件時擴展這個類將會有更多的未來證明。

+0

謝謝,瑞克。這工作。 – JohnZ