forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial checkpoint when protocol is first added
- Loading branch information
1 parent
eb4c24a
commit 860353c
Showing
5 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.r3corda.node.services.statemachine | ||
|
||
import co.paralleluniverse.fibers.Fiber | ||
import co.paralleluniverse.fibers.Suspendable | ||
import com.r3corda.core.messaging.MessagingService | ||
import com.r3corda.core.protocols.ProtocolLogic | ||
import com.r3corda.node.services.MockServices | ||
import com.r3corda.node.services.api.Checkpoint | ||
import com.r3corda.node.services.api.CheckpointStorage | ||
import com.r3corda.node.services.network.InMemoryMessagingNetwork | ||
import com.r3corda.node.utilities.AffinityExecutor | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.After | ||
import org.junit.Test | ||
import java.util.* | ||
|
||
class StateMachineManagerTests { | ||
|
||
val checkpointStorage = RecordingCheckpointStorage() | ||
val network = InMemoryMessagingNetwork().InMemoryMessaging(true, InMemoryMessagingNetwork.Handle(1, "mock")) | ||
val smm = createManager() | ||
|
||
@After | ||
fun cleanUp() { | ||
network.stop() | ||
} | ||
|
||
@Test | ||
fun `newly added protocol is preserved on restart`() { | ||
smm.add("mock", ProtocolWithoutCheckpoints()) | ||
// Ensure we're restoring from the original add checkpoint | ||
assertThat(checkpointStorage.allCheckpoints).hasSize(1) | ||
val restoredProtocol = createManager().run { | ||
start() | ||
findStateMachines(ProtocolWithoutCheckpoints::class.java).single().first | ||
} | ||
assertThat(restoredProtocol.protocolStarted).isTrue() | ||
} | ||
|
||
private fun createManager() = StateMachineManager(object : MockServices() { | ||
override val networkService: MessagingService get() = network | ||
}, emptyList(), checkpointStorage, AffinityExecutor.SAME_THREAD) | ||
|
||
|
||
private class ProtocolWithoutCheckpoints : ProtocolLogic<Unit>() { | ||
|
||
@Transient var protocolStarted = false | ||
|
||
@Suspendable | ||
override fun call() { | ||
protocolStarted = true | ||
Fiber.park() | ||
} | ||
} | ||
|
||
|
||
class RecordingCheckpointStorage : CheckpointStorage { | ||
|
||
private val _checkpoints = ArrayList<Checkpoint>() | ||
val allCheckpoints = ArrayList<Checkpoint>() | ||
|
||
override fun addCheckpoint(checkpoint: Checkpoint) { | ||
_checkpoints.add(checkpoint) | ||
allCheckpoints.add(checkpoint) | ||
} | ||
|
||
override fun removeCheckpoint(checkpoint: Checkpoint) { | ||
_checkpoints.remove(checkpoint) | ||
} | ||
|
||
override val checkpoints: Iterable<Checkpoint> get() = _checkpoints | ||
} | ||
|
||
} |