fix managed methods reusing old quorums
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.emeraldpay.dshackle.startup
|
||||
|
||||
import io.emeraldpay.dshackle.FileResolver
|
||||
import io.emeraldpay.dshackle.cache.CachesFactory
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.quorum.NonEmptyQuorum
|
||||
import io.emeraldpay.dshackle.upstream.CallTargetsHolder
|
||||
@@ -36,7 +35,7 @@ class ConfiguredUpstreamsSpec extends Specification {
|
||||
def act = configurer.buildMethods(upstream, Chain.ETHEREUM)
|
||||
then:
|
||||
act instanceof ManagedCallMethods
|
||||
act.getQuorumFor("foo_bar") instanceof NonEmptyQuorum
|
||||
act.createQuorumFor("foo_bar") instanceof NonEmptyQuorum
|
||||
}
|
||||
|
||||
def "Got static response from extra methods"() {
|
||||
|
||||
@@ -58,9 +58,9 @@ class MultistreamSpec extends Specification {
|
||||
act.isCallable("eth_test1")
|
||||
act.isCallable("eth_test2")
|
||||
act.isCallable("eth_test3")
|
||||
act.getQuorumFor("eth_test1") instanceof AlwaysQuorum
|
||||
act.getQuorumFor("eth_test2") instanceof AlwaysQuorum
|
||||
act.getQuorumFor("eth_test3") instanceof AlwaysQuorum
|
||||
act.createQuorumFor("eth_test1") instanceof AlwaysQuorum
|
||||
act.createQuorumFor("eth_test2") instanceof AlwaysQuorum
|
||||
act.createQuorumFor("eth_test3") instanceof AlwaysQuorum
|
||||
}
|
||||
|
||||
def "Filter Best Status accepts any input when none available "() {
|
||||
|
||||
@@ -31,11 +31,11 @@ class AggregatedCallMethodsSpec extends Specification {
|
||||
def delegate2 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_test", "foo_bar"]
|
||||
1 * isCallable("eth_test") >> true
|
||||
1 * getQuorumFor("eth_test") >> quorum
|
||||
1 * createQuorumFor("eth_test") >> quorum
|
||||
}
|
||||
def aggregate = new AggregatedCallMethods([delegate1, delegate2])
|
||||
when:
|
||||
def act = aggregate.getQuorumFor("eth_test")
|
||||
def act = aggregate.createQuorumFor("eth_test")
|
||||
then:
|
||||
act == quorum
|
||||
}
|
||||
|
||||
@@ -18,14 +18,15 @@ package io.emeraldpay.dshackle.upstream.calls
|
||||
|
||||
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
|
||||
import io.emeraldpay.dshackle.quorum.BroadcastQuorum
|
||||
import io.emeraldpay.dshackle.quorum.CallQuorum
|
||||
import io.emeraldpay.dshackle.quorum.NonEmptyQuorum
|
||||
import io.emeraldpay.dshackle.quorum.NonceQuorum
|
||||
import io.emeraldpay.dshackle.quorum.NotLaggingQuorum
|
||||
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
|
||||
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class ManagedCallMethodsSpec extends Specification {
|
||||
|
||||
def "Gets quorum for enabled method"() {
|
||||
@@ -36,7 +37,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
[] as Set
|
||||
)
|
||||
when:
|
||||
def act = managed.getQuorumFor("eth_test")
|
||||
def act = managed.createQuorumFor("eth_test")
|
||||
then:
|
||||
act instanceof AlwaysQuorum
|
||||
}
|
||||
@@ -72,7 +73,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
def delegated = ["eth_test", "eth_test2"] as Set
|
||||
def delegate = Mock(CallMethods) {
|
||||
_ * it.getSupportedMethods() >> delegated
|
||||
0 * it.getQuorumFor("eth_test") >> new BroadcastQuorum()
|
||||
0 * it.createQuorumFor("eth_test") >> new BroadcastQuorum()
|
||||
}
|
||||
def managed = new ManagedCallMethods(
|
||||
delegate,
|
||||
@@ -80,7 +81,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
["foo_bar"] as Set
|
||||
)
|
||||
when:
|
||||
def act = managed.getQuorumFor("eth_test")
|
||||
def act = managed.createQuorumFor("eth_test")
|
||||
then:
|
||||
act != null
|
||||
act instanceof AlwaysQuorum
|
||||
@@ -96,18 +97,40 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
managed.setQuorum("eth_test", "not_empty")
|
||||
managed.setQuorum("eth_foo", "not_lagging")
|
||||
when:
|
||||
def act = managed.getQuorumFor("eth_test")
|
||||
def act = managed.createQuorumFor("eth_test")
|
||||
then:
|
||||
act instanceof NonEmptyQuorum
|
||||
|
||||
when:
|
||||
act = managed.getQuorumFor("eth_foo")
|
||||
act = managed.createQuorumFor("eth_foo")
|
||||
then:
|
||||
act instanceof NotLaggingQuorum
|
||||
|
||||
when:
|
||||
act = managed.getQuorumFor("eth_bar")
|
||||
act = managed.createQuorumFor("eth_bar")
|
||||
then:
|
||||
act instanceof AlwaysQuorum
|
||||
}
|
||||
|
||||
def "Doesn't reuse same instance"() {
|
||||
def managed = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM),
|
||||
["eth_test"] as Set,
|
||||
[] as Set
|
||||
)
|
||||
def parallel = Executors.newFixedThreadPool(16)
|
||||
when:
|
||||
List<CallQuorum> instances = []
|
||||
50.times {
|
||||
instances << managed.createQuorumFor("eth_test")
|
||||
}
|
||||
parallel.shutdown()
|
||||
parallel.awaitTermination(5, TimeUnit.SECONDS)
|
||||
|
||||
def ids = instances.collect { System.identityHashCode(it) }
|
||||
|
||||
then:
|
||||
instances.size() == 50
|
||||
ids.toSet().size() == 50
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user