Backport merge fixes added to ENT (#4618)

Fix test and address code review comments.
This commit is contained in:
Tudor Malene 2019-01-29 13:45:04 +00:00 committed by GitHub
parent 8f3e527d98
commit 262a7ad1b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 135 additions and 131 deletions

View File

@ -2,9 +2,6 @@ package net.corda.serialization.reproduction;
import net.corda.client.rpc.CordaRPCClient;
import net.corda.core.concurrent.CordaFuture;
import net.corda.core.flows.FlowLogic;
import net.corda.core.flows.StartableByRPC;
import net.corda.core.serialization.CordaSerializable;
import net.corda.node.services.Permissions;
import net.corda.testing.driver.Driver;
import net.corda.testing.driver.DriverParameters;
@ -14,10 +11,7 @@ import net.corda.testing.node.User;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class GenericReturnFailureReproductionIntegrationTest {
@ -36,33 +30,7 @@ public class GenericReturnFailureReproductionIntegrationTest {
}
@StartableByRPC
public static class SuperSimpleGenericFlow extends FlowLogic<GenericHolder<String>> {
public SuperSimpleGenericFlow() {
}
@Override
public GenericHolder<String> call() {
return new GenericHolder<>(IntStream.of(100).mapToObj((i) -> "" + i).collect(Collectors.toList()));
}
}
@CordaSerializable
public static class GenericHolder<S> {
private final List<S> items;
public GenericHolder(List<S> items) {
this.items = items;
}
public List<S> getItems() {
return items;
}
}
private static <Y> Y getOrThrow(CordaFuture<Y> future) {
try {
return future.get();
} catch (InterruptedException | ExecutionException e) {

View File

@ -0,0 +1,33 @@
package net.corda.serialization.reproduction;
import net.corda.core.flows.FlowLogic;
import net.corda.core.flows.StartableByRPC;
import net.corda.core.serialization.CordaSerializable;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@StartableByRPC
public class SuperSimpleGenericFlow extends FlowLogic<GenericHolder<String>> {
public SuperSimpleGenericFlow() {
}
@Override
public GenericHolder<String> call() {
return new GenericHolder<>(IntStream.of(100).mapToObj((i) -> "" + i).collect(Collectors.toList()));
}
}
@CordaSerializable
class GenericHolder<S> {
private final List<S> items;
GenericHolder(List<S> items) {
this.items = items;
}
public List<S> getItems() {
return items;
}
}

View File

@ -81,17 +81,17 @@ class HashLookupCommandTest {
private fun issueTransaction(node: NodeHandle): SecureHash {
return node.rpc.startFlow(::DummyIssue).returnValue.get()
}
}
@StartableByRPC
internal class DummyIssue : FlowLogic<SecureHash>() {
@Suspendable
override fun call(): SecureHash {
val me = serviceHub.myInfo.legalIdentities.first().ref(0)
val fakeNotary = me.party
val builder = DummyContract.generateInitial(1, fakeNotary as Party, me)
val stx = serviceHub.signInitialTransaction(builder)
serviceHub.recordTransactions(stx)
return stx.id
}
@StartableByRPC
internal class DummyIssue : FlowLogic<SecureHash>() {
@Suspendable
override fun call(): SecureHash {
val me = serviceHub.myInfo.legalIdentities.first().ref(0)
val fakeNotary = me.party
val builder = DummyContract.generateInitial(1, fakeNotary as Party, me)
val stx = serviceHub.signInitialTransaction(builder)
serviceHub.recordTransactions(stx)
return stx.id
}
}
}

View File

@ -148,7 +148,7 @@ class InteractiveShellIntegrationTest {
@Ignore
@Test
fun `ssh runs flows via standalone shell`() {
val user = User("u", "p", setOf(Permissions.startFlow<SSHServerTest.FlowICanRun>(),
val user = User("u", "p", setOf(Permissions.startFlow<FlowICanRun>(),
Permissions.invokeRpc(CordaRPCOps::registeredFlows),
Permissions.invokeRpc(CordaRPCOps::nodeInfo)))
driver(DriverParameters(notarySpecs = emptyList())) {
@ -191,7 +191,7 @@ class InteractiveShellIntegrationTest {
@Ignore
@Test
fun `ssh run flows via standalone shell over ssl to node`() {
val user = User("mark", "dadada", setOf(Permissions.startFlow<SSHServerTest.FlowICanRun>(),
val user = User("mark", "dadada", setOf(Permissions.startFlow<FlowICanRun>(),
Permissions.invokeRpc(CordaRPCOps::registeredFlows),
Permissions.invokeRpc(CordaRPCOps::nodeInfo)/*all()*/))
@ -245,33 +245,6 @@ class InteractiveShellIntegrationTest {
}
}
@Suppress("UNUSED")
@StartableByRPC
class NoOpFlow : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
override fun call() {
println("NO OP!")
}
}
@Suppress("UNUSED")
@StartableByRPC
class NoOpFlowA : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
override fun call() {
println("NO OP! (A)")
}
}
@Suppress("UNUSED")
@StartableByRPC
class BurbleFlow : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
override fun call() {
println("NO OP! (Burble)")
}
}
@Test
fun `shell should start flow with fully qualified class name`() {
val user = User("u", "p", setOf(all()))
@ -298,7 +271,7 @@ class InteractiveShellIntegrationTest {
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
}
InteractiveShell.runFlowByNameFragment(
InteractiveShellIntegrationTest::class.qualifiedName + "\$NoOpFlow",
"NoOpFlow",
"", output, node.rpc, ansiProgressRenderer)
}
assertThat(successful).isTrue()
@ -330,7 +303,7 @@ class InteractiveShellIntegrationTest {
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
}
InteractiveShell.runFlowByNameFragment(
"InteractiveShellIntegrationTest\$NoOpFlowA",
"NoOpFlowA",
"", output, node.rpc, ansiProgressRenderer)
}
assertThat(successful).isTrue()
@ -362,7 +335,7 @@ class InteractiveShellIntegrationTest {
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
}
InteractiveShell.runFlowByNameFragment(
InteractiveShellIntegrationTest::class.qualifiedName + "\$NoOpFlo",
"NoOpFlo",
"", output, node.rpc, ansiProgressRenderer)
}
assertThat(successful).isTrue()
@ -399,4 +372,31 @@ class InteractiveShellIntegrationTest {
}
assertThat(successful).isTrue()
}
}
@Suppress("UNUSED")
@StartableByRPC
class NoOpFlow : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
override fun call() {
println("NO OP!")
}
}
@Suppress("UNUSED")
@StartableByRPC
class NoOpFlowA : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
override fun call() {
println("NO OP! (A)")
}
}
@Suppress("UNUSED")
@StartableByRPC
class BurbleFlow : FlowLogic<Unit>() {
override val progressTracker = ProgressTracker()
override fun call() {
println("NO OP! (Burble)")
}
}

View File

@ -150,32 +150,33 @@ class SSHServerTest {
session.disconnect()
// There are ANSI control characters involved, so we want to avoid direct byte to byte matching.
assertThat(linesWithDoneCount).hasSize(1)
assertThat(linesWithDoneCount).size().isGreaterThanOrEqualTo(1)
}
}
@StartableByRPC
@InitiatingFlow
class FlowICanRun : FlowLogic<String>() {
private val HELLO_STEP = ProgressTracker.Step("Hello")
@Suspendable
override fun call(): String {
progressTracker?.currentStep = HELLO_STEP
return "bambam"
}
override val progressTracker: ProgressTracker? = ProgressTracker(HELLO_STEP)
}
@Suppress("unused")
@StartableByRPC
@InitiatingFlow
class FlowICannotRun(private val otherParty: Party) : FlowLogic<String>() {
@Suspendable
override fun call(): String = initiateFlow(otherParty).receive<String>().unwrap { it }
override val progressTracker: ProgressTracker? = ProgressTracker()
}
}
@StartableByRPC
@InitiatingFlow
class FlowICanRun : FlowLogic<String>() {
private val HELLO_STEP = ProgressTracker.Step("Hello")
@Suspendable
override fun call(): String {
progressTracker?.currentStep = HELLO_STEP
return "bambam"
}
override val progressTracker: ProgressTracker? = ProgressTracker(HELLO_STEP)
}
@Suppress("unused")
@StartableByRPC
@InitiatingFlow
class FlowICannotRun(private val otherParty: Party) : FlowLogic<String>() {
@Suspendable
override fun call(): String = initiateFlow(otherParty).receive<String>().unwrap { it }
override val progressTracker: ProgressTracker? = ProgressTracker()
}

View File

@ -110,20 +110,6 @@ class InteractiveShellTest {
""".trimIndent()
}
@Suppress("UNUSED")
class FlowA(val a: String) : FlowLogic<String>() {
constructor(b: Int?) : this(b.toString())
constructor(b: Int?, c: String) : this(b.toString() + c)
constructor(amount: Amount<Currency>) : this(amount.toString())
constructor(pair: Pair<Amount<Currency>, SecureHash.SHA256>) : this(pair.toString())
constructor(party: Party) : this(party.name.toString())
constructor(b: Int?, amount: Amount<UserValue>) : this("${(b ?: 0) + amount.quantity} ${amount.token}")
constructor(b: Array<String>) : this(b.joinToString("+"))
constructor(amounts: Array<Amount<UserValue>>) : this(amounts.joinToString("++", transform = Amount<UserValue>::toString))
override val progressTracker = ProgressTracker()
override fun call() = a
}
private val ids = InMemoryIdentityService(listOf(megaCorp.identity), DEV_ROOT_CA.certificate)
@Suppress("DEPRECATION")
@ -148,7 +134,7 @@ class InteractiveShellTest {
return objectMapper
}
@Test
fun flowStartSimple() {
check("a: Hi there", "Hi there")
@ -161,26 +147,26 @@ class InteractiveShellTest {
@Test
fun flowStartWithNestedTypes() = check(
input = "pair: { first: $100.12, second: df489807f81c8c8829e509e1bcb92e6692b9dd9d624b7456435cb2f51dc82587 }",
expected = "(100.12 USD, DF489807F81C8C8829E509E1BCB92E6692B9DD9D624B7456435CB2F51DC82587)"
input = "pair: { first: $100.12, second: df489807f81c8c8829e509e1bcb92e6692b9dd9d624b7456435cb2f51dc82587 }",
expected = "(100.12 USD, DF489807F81C8C8829E509E1BCB92E6692B9DD9D624B7456435CB2F51DC82587)"
)
@Test
fun flowStartWithArrayType() = check(
input = "b: [ One, Two, Three, Four ]",
expected = "One+Two+Three+Four"
input = "b: [ One, Two, Three, Four ]",
expected = "One+Two+Three+Four"
)
@Test
fun flowStartWithUserAmount() = check(
input = """b: 500, amount: { "quantity": 10001, "token":{ "label": "of value" } }""",
expected = "10501 of value"
input = """b: 500, amount: { "quantity": 10001, "token":{ "label": "of value" } }""",
expected = "10501 of value"
)
@Test
fun flowStartWithArrayOfNestedTypes() = check(
input = """amounts: [ { "quantity": 10, "token": { "label": "(1)" } }, { "quantity": 200, "token": { "label": "(2)" } } ]""",
expected = "10 (1)++200 (2)"
input = """amounts: [ { "quantity": 10, "token": { "label": "(1)" } }, { "quantity": 200, "token": { "label": "(2)" } } ]""",
expected = "10 (1)++200 (2)"
)
@Test(expected = InteractiveShell.NoApplicableConstructor::class)
@ -198,11 +184,11 @@ class InteractiveShellTest {
check("", expected = "")
}
val correct = setOf(
"[amounts: Amount<InteractiveShellTest.UserValue>[]]: missing parameter amounts",
"[amounts: Amount<UserValue>[]]: missing parameter amounts",
"[amount: Amount<Currency>]: missing parameter amount",
"[pair: Pair<Amount<Currency>, SecureHash.SHA256>]: missing parameter pair",
"[party: Party]: missing parameter party",
"[b: Integer, amount: Amount<InteractiveShellTest.UserValue>]: missing parameter b",
"[b: Integer, amount: Amount<UserValue>]: missing parameter b",
"[b: String[]]: missing parameter b",
"[b: Integer, c: String]: missing parameter b",
"[a: String]: missing parameter a",
@ -245,8 +231,24 @@ class InteractiveShellTest {
verify(printWriter).println(NETWORK_MAP_JSON_PAYLOAD.replace("\n", System.lineSeparator()))
}
@ToStringSerialize
data class UserValue(@JsonProperty("label") val label: String) {
override fun toString() = label
}
}
}
@ToStringSerialize
data class UserValue(@JsonProperty("label") val label: String) {
override fun toString() = label
}
@Suppress("UNUSED")
class FlowA(val a: String) : FlowLogic<String>() {
constructor(b: Int?) : this(b.toString())
constructor(b: Int?, c: String) : this(b.toString() + c)
constructor(amount: Amount<Currency>) : this(amount.toString())
constructor(pair: Pair<Amount<Currency>, SecureHash.SHA256>) : this(pair.toString())
constructor(party: Party) : this(party.name.toString())
constructor(b: Int?, amount: Amount<UserValue>) : this("${(b ?: 0) + amount.quantity} ${amount.token}")
constructor(b: Array<String>) : this(b.joinToString("+"))
constructor(amounts: Array<Amount<UserValue>>) : this(amounts.joinToString("++", transform = Amount<UserValue>::toString))
override val progressTracker = ProgressTracker()
override fun call() = a
}