mirror of
https://github.com/corda/corda.git
synced 2024-12-28 08:48:57 +00:00
Fixed the CorDapp configuration demo (#2967)
This commit is contained in:
parent
9d2b7f0b7b
commit
1288f63998
@ -1,4 +1,4 @@
|
||||
gradlePluginsVersion=4.0.11
|
||||
gradlePluginsVersion=4.0.12
|
||||
kotlinVersion=1.2.20
|
||||
platformVersion=4
|
||||
guavaVersion=21.0
|
||||
|
@ -2,7 +2,6 @@ package net.corda.node.internal.cordapp
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.corda.core.internal.cordapp.CordappConfigProvider
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import java.io.File
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.corda.core.internal.cordapp
|
||||
package net.corda.node.internal.cordapp
|
||||
|
||||
import com.typesafe.config.Config
|
||||
|
||||
|
@ -7,7 +7,6 @@ import net.corda.core.cordapp.Cordapp
|
||||
import net.corda.core.cordapp.CordappContext
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.internal.DEPLOYED_CORDAPP_UPLOADER
|
||||
import net.corda.core.internal.cordapp.CordappConfigProvider
|
||||
import net.corda.core.internal.createCordappContext
|
||||
import net.corda.core.node.services.AttachmentId
|
||||
import net.corda.core.node.services.AttachmentStorage
|
||||
|
@ -2,15 +2,12 @@ package net.corda.node.internal.cordapp
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import junit.framework.Assert.assertNull
|
||||
import net.corda.core.internal.cordapp.CordappConfigProvider
|
||||
import net.corda.core.node.services.AttachmentStorage
|
||||
import net.corda.testing.common.internal.testNetworkParameters
|
||||
import net.corda.testing.internal.MockCordappConfigProvider
|
||||
import net.corda.testing.services.MockAttachmentStorage
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.net.URL
|
||||
@ -19,9 +16,9 @@ class CordappProviderImplTests {
|
||||
private companion object {
|
||||
val isolatedJAR = this::class.java.getResource("isolated.jar")!!
|
||||
// TODO: Cordapp name should differ from the JAR name
|
||||
val isolatedCordappName = "isolated"
|
||||
const val isolatedCordappName = "isolated"
|
||||
val emptyJAR = this::class.java.getResource("empty.jar")!!
|
||||
val validConfig = ConfigFactory.parseString("key=value")
|
||||
val validConfig: Config = ConfigFactory.parseString("key=value")
|
||||
|
||||
val stubConfigProvider = object : CordappConfigProvider {
|
||||
override fun getConfigByName(name: String): Config = ConfigFactory.empty()
|
||||
@ -77,7 +74,7 @@ class CordappProviderImplTests {
|
||||
@Test
|
||||
fun `test cordapp configuration`() {
|
||||
val configProvider = MockCordappConfigProvider()
|
||||
configProvider.cordappConfigs.put(isolatedCordappName, validConfig)
|
||||
configProvider.cordappConfigs[isolatedCordappName] = validConfig
|
||||
val loader = CordappLoader.createDevMode(listOf(isolatedJAR))
|
||||
val provider = CordappProviderImpl(loader, configProvider, attachmentStore, whitelistedContractImplementations)
|
||||
|
||||
|
@ -6,18 +6,18 @@ This sample shows a simple example of how to use per-cordapp configuration. It i
|
||||
* Gradle build file to show how to install your Cordapp configuration
|
||||
* A flow that consumes the Cordapp configuration
|
||||
|
||||
## Usage
|
||||
To run from the command line in Unix:
|
||||
|
||||
To run the sample you must first build it from the project root with;
|
||||
1. Run ``./gradlew samples:cordapp-configuration:deployNodes`` to create a set of configs and installs under
|
||||
``samples/cordapp-configuration/build/nodes``
|
||||
2. Run ``./samples/cordapp-configuration/build/nodes/runnodes`` to open up three new terminals with the three nodes
|
||||
3. At the shell prompt for Bank A or Bank B run ``start net.corda.configsample.GetStringConfigFlow configKey: someStringValue``.
|
||||
This will start the flow and read the `someStringValue` CorDapp config.
|
||||
|
||||
./gradlew deployNodes
|
||||
|
||||
This will deploy the node with the configuration installed.
|
||||
The relevant section is the ``deployNodes`` task.
|
||||
To run from the command line in Windows:
|
||||
|
||||
## Running
|
||||
|
||||
* Windows: `build\nodes\runnodes`
|
||||
* Mac/Linux: `./build/nodes/runnodes`
|
||||
|
||||
Once the nodes have started up and show a prompt you can now run your flow.
|
||||
1. Run ``gradlew samples:cordapp-configuration:deployNodes`` to create a set of configs and installs under
|
||||
``samples\cordapp-configuration\build\nodes``
|
||||
2. Run ``samples\cordapp-configuration\build\nodes\runnodes`` to open up three new terminals with the three nodes
|
||||
3. At the shell prompt for Bank A or Bank B run ``start net.corda.configsample.GetStringConfigFlow configKey: someStringValue``.
|
||||
This will start the flow and read the `someStringValue` CorDapp config.
|
||||
|
@ -1,10 +0,0 @@
|
||||
package net.corda.configsample
|
||||
|
||||
import net.corda.core.flows.FlowLogic
|
||||
|
||||
class ConfigSampleFlow : FlowLogic<String>() {
|
||||
override fun call(): String {
|
||||
val config = serviceHub.getAppContext().config
|
||||
return config.getString("someStringValue")
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package net.corda.configsample
|
||||
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.StartableByRPC
|
||||
import net.corda.core.utilities.ProgressTracker
|
||||
|
||||
@StartableByRPC
|
||||
class GetStringConfigFlow(private val configKey: String) : FlowLogic<String>() {
|
||||
object READING : ProgressTracker.Step("Reading config")
|
||||
override val progressTracker = ProgressTracker(READING)
|
||||
|
||||
@Suspendable
|
||||
override fun call(): String {
|
||||
progressTracker.currentStep = READING
|
||||
val config = serviceHub.getAppContext().config
|
||||
return config.getString(configKey)
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package net.corda.testing.internal
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.corda.core.internal.cordapp.CordappConfigProvider
|
||||
import net.corda.node.internal.cordapp.CordappConfigProvider
|
||||
|
||||
class MockCordappConfigProvider : CordappConfigProvider {
|
||||
val cordappConfigs = mutableMapOf<String, Config> ()
|
||||
|
Loading…
Reference in New Issue
Block a user