disable local router caches

This commit is contained in:
a10zn8
2022-12-12 17:10:39 +04:00
parent e144a9b0de
commit 2c666eed99
13 changed files with 53 additions and 23 deletions

View File

@@ -47,4 +47,14 @@ class CacheConfigReaderSpec extends Specification {
//later may be not null if we support something else besides Redis
act == null
}
def "Local read disabled"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("cache-local-router-disabled.yaml")
when:
def act = reader.read(config)
then:
!act.requestsCacheEnabled
}
}

View File

@@ -21,10 +21,10 @@ import com.google.protobuf.ByteString
import io.emeraldpay.api.proto.BlockchainOuterClass
import io.emeraldpay.api.proto.Common
import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.config.CacheConfig
import io.emeraldpay.dshackle.quorum.QuorumReaderFactory
import io.emeraldpay.dshackle.quorum.QuorumRpcReader
import io.emeraldpay.dshackle.reader.Reader
import io.emeraldpay.dshackle.startup.ConfiguredUpstreams
import io.emeraldpay.dshackle.test.MultistreamHolderMock
import io.emeraldpay.dshackle.test.TestingCommons
import io.emeraldpay.dshackle.quorum.AlwaysQuorum
@@ -52,14 +52,19 @@ class NativeCallSpec extends Specification {
ObjectMapper objectMapper = Global.objectMapper
def nativeCall(MultistreamHolder upstreams = null, ResponseSigner signer = null) {
def nativeCall(MultistreamHolder upstreams = null, ResponseSigner signer = null, Boolean enableCache = true) {
if (upstreams == null) {
upstreams = Stub(MultistreamHolder)
}
if (signer == null) {
signer = Stub(ResponseSigner)
}
new NativeCall(upstreams, signer)
def config = new CacheConfig()
config.requestsCacheEnabled = enableCache
new NativeCall(upstreams, signer, config)
}
def "Tries router first"() {

View File

@@ -327,8 +327,9 @@ class MultistreamSpec extends Specification {
super(chain, upstreams, caches)
}
@NotNull
@Override
Mono<Reader<JsonRpcRequest, JsonRpcResponse>> getRoutedApi(@NotNull Selector.Matcher matcher) {
Mono<Reader<JsonRpcRequest, JsonRpcResponse>> getRoutedApi(boolean localEnabled) {
return null
}

View File

@@ -2,6 +2,7 @@ package io.emeraldpay.dshackle.upstream.ethereum
import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.cache.Caches
import io.emeraldpay.dshackle.config.CacheConfig
import io.emeraldpay.dshackle.reader.EmptyReader
import io.emeraldpay.dshackle.test.TestingCommons
import io.emeraldpay.dshackle.upstream.EmptyHead
@@ -29,7 +30,8 @@ class LocalCallRouterSpec extends Specification {
ConstantFactory.constantFactory(new DefaultEthereumMethods(Chain.ETHEREUM))
),
methods,
new EmptyHead()
new EmptyHead(),
true
)
when:
def act = router.read(new JsonRpcRequest("eth_coinbase", [])).block(Duration.ofSeconds(1))
@@ -47,7 +49,8 @@ class LocalCallRouterSpec extends Specification {
ConstantFactory.constantFactory(new DefaultEthereumMethods(Chain.ETHEREUM))
),
methods,
new EmptyHead()
new EmptyHead(),
true
)
when:
def act = router.read(new JsonRpcRequest("eth_getTransactionByHash", ["test"], 10))
@@ -69,7 +72,7 @@ class LocalCallRouterSpec extends Specification {
}
}
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
def router = new LocalCallRouter(reader, methods, head)
def router = new LocalCallRouter(reader, methods, head, true)
when:
def act = router.getBlockByNumber(["latest", false])
@@ -95,7 +98,7 @@ class LocalCallRouterSpec extends Specification {
}
}
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
def router = new LocalCallRouter(reader, methods, head)
def router = new LocalCallRouter(reader, methods, head, true)
when:
def act = router.getBlockByNumber(["earliest", false])
@@ -121,7 +124,7 @@ class LocalCallRouterSpec extends Specification {
}
}
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
def router = new LocalCallRouter(reader, methods, head)
def router = new LocalCallRouter(reader, methods, head, true)
when:
def act = router.getBlockByNumber(["0x123ef", false])

View File

@@ -0,0 +1,2 @@
cache:
requests-cache-enabled: false