Skip to content

Commit

Permalink
CORDA-540: Allow AMQP switch for storage context (corda#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkolomeyko authored Oct 4, 2017
1 parent f5784f7 commit 2ca140d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.corda.core.node.services.Vault
import net.corda.core.node.services.VaultService
import net.corda.core.schemas.CommonSchemaV1
import net.corda.core.schemas.PersistentStateRef
import net.corda.core.serialization.SerializationDefaults
import net.corda.core.serialization.deserialize
import net.corda.core.transactions.SignedTransaction
import net.corda.finance.DOLLARS
Expand Down Expand Up @@ -140,7 +141,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() {

// execute query
val queryResults = entityManager.createQuery(criteriaQuery).resultList
val coins = queryResults.map { it.contractState.deserialize<TransactionState<Cash.State>>().data }.sumCash()
val coins = queryResults.map { it.contractState.deserialize<TransactionState<Cash.State>>(context = SerializationDefaults.STORAGE_CONTEXT).data }.sumCash()
assertThat(coins.toDecimal() >= BigDecimal("50.00"))
}

Expand Down Expand Up @@ -661,7 +662,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() {
val queryResults = entityManager.createQuery(criteriaQuery).resultList

queryResults.forEach {
val contractState = it.contractState.deserialize<TransactionState<ContractState>>()
val contractState = it.contractState.deserialize<TransactionState<ContractState>>(context = SerializationDefaults.STORAGE_CONTEXT)
val cashState = contractState.data as Cash.State
println("${it.stateRef} with owner: ${cashState.owner.owningKey.toBase58String()}") }

Expand Down Expand Up @@ -745,7 +746,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() {
// execute query
val queryResults = entityManager.createQuery(criteriaQuery).resultList
queryResults.forEach {
val contractState = it.contractState.deserialize<TransactionState<ContractState>>()
val contractState = it.contractState.deserialize<TransactionState<ContractState>>(context = SerializationDefaults.STORAGE_CONTEXT)
val cashState = contractState.data as Cash.State
println("${it.stateRef} with owner ${cashState.owner.owningKey.toBase58String()} and participants ${cashState.participants.map { it.owningKey.toBase58String() }}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ fun initialiseTestSerialization() {
registerScheme(AMQPServerSerializationScheme())
}

val AMQP_ENABLE_PROP_NAME = "net.corda.testing.amqp.enable"
// TODO: Remove these "if" conditions once we fully switched to AMQP
(SerializationDefaults.P2P_CONTEXT as TestSerializationContext).delegate = if (java.lang.Boolean.getBoolean(AMQP_ENABLE_PROP_NAME)) {
AMQP_P2P_CONTEXT
} else {
KRYO_P2P_CONTEXT
}
(SerializationDefaults.P2P_CONTEXT as TestSerializationContext).delegate = if (isAmqpEnabled()) AMQP_P2P_CONTEXT else KRYO_P2P_CONTEXT
(SerializationDefaults.RPC_SERVER_CONTEXT as TestSerializationContext).delegate = KRYO_RPC_SERVER_CONTEXT
(SerializationDefaults.RPC_CLIENT_CONTEXT as TestSerializationContext).delegate = KRYO_RPC_CLIENT_CONTEXT
(SerializationDefaults.STORAGE_CONTEXT as TestSerializationContext).delegate = KRYO_STORAGE_CONTEXT
(SerializationDefaults.STORAGE_CONTEXT as TestSerializationContext).delegate = if (isAmqpEnabled()) AMQP_STORAGE_CONTEXT else KRYO_STORAGE_CONTEXT
(SerializationDefaults.CHECKPOINT_CONTEXT as TestSerializationContext).delegate = KRYO_CHECKPOINT_CONTEXT
}

private const val AMQP_ENABLE_PROP_NAME = "net.corda.testing.amqp.enable"

// TODO: Remove usages of this function when we fully switched to AMQP
private fun isAmqpEnabled(): Boolean = java.lang.Boolean.getBoolean(AMQP_ENABLE_PROP_NAME)

fun resetTestSerialization() {
(SerializationDefaults.SERIALIZATION_FACTORY as TestSerializationFactory).delegate = null
(SerializationDefaults.P2P_CONTEXT as TestSerializationContext).delegate = null
Expand Down

0 comments on commit 2ca140d

Please sign in to comment.