Search in sources :

Example 1 with QosTimer

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer in project besu by hyperledger.

the class EngineExchangeTransitionConfigurationTest method shouldNotWarnWhenExchangeConfigurationCalledWithinTimeout.

@Test
public void shouldNotWarnWhenExchangeConfigurationCalledWithinTimeout(final TestContext ctx) {
    final long TEST_QOS_TIMEOUT = 75L;
    final Async async = ctx.async();
    final AtomicInteger logCounter = new AtomicInteger(0);
    final var spyMethod = spy(method);
    final var spyTimer = spy(new QosTimer(vertx, TEST_QOS_TIMEOUT, z -> logCounter.incrementAndGet()));
    when(mergeContext.getTerminalPoWBlock()).thenReturn(Optional.empty());
    when(mergeContext.getTerminalTotalDifficulty()).thenReturn(Difficulty.of(1337L));
    when(spyMethod.getQosTimer()).thenReturn(spyTimer);
    spyTimer.resetTimer();
    // call exchangeTransitionConfiguration 50 milliseconds hence to reset our QoS timer
    vertx.setTimer(50L, z -> spyMethod.syncResponse(new JsonRpcRequestContext(new JsonRpcRequest("2.0", RpcMethod.ENGINE_EXCHANGE_TRANSITION_CONFIGURATION.getMethodName(), new Object[] { new EngineExchangeTransitionConfigurationParameter("24", Hash.fromHexStringLenient("0x01").toHexString(), new UnsignedLongParameter(0)) }))));
    vertx.setTimer(100L, z -> {
        try {
            // once on construction, once on call:
            verify(spyTimer, times(2)).resetTimer();
        } catch (Exception ex) {
            ctx.fail(ex);
        }
        // should not warn
        ctx.assertEquals(0, logCounter.get());
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) RunWith(org.junit.runner.RunWith) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Bytes(org.apache.tuweni.bytes.Bytes) Mockito.spy(org.mockito.Mockito.spy) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) JsonRpcResponseType(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponseType) Address(org.hyperledger.besu.datatypes.Address) UnsignedLongParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Wei(org.hyperledger.besu.datatypes.Wei) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Bytes32(org.apache.tuweni.bytes.Bytes32) Before(org.junit.Before) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) LogsBloomFilter(org.hyperledger.besu.evm.log.LogsBloomFilter) Mockito.times(org.mockito.Mockito.times) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Mockito.verify(org.mockito.Mockito.verify) QosTimer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer) Mockito(org.mockito.Mockito) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) ParsedExtraData(org.hyperledger.besu.ethereum.core.ParsedExtraData) EngineExchangeTransitionConfigurationParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineExchangeTransitionConfigurationParameter) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Optional(java.util.Optional) BlockHeaderFunctions(org.hyperledger.besu.ethereum.core.BlockHeaderFunctions) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) EngineExchangeTransitionConfigurationResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineExchangeTransitionConfigurationResult) QosTimer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer) UnsignedLongParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EngineExchangeTransitionConfigurationParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineExchangeTransitionConfigurationParameter) Async(io.vertx.ext.unit.Async) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Example 2 with QosTimer

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer in project besu by hyperledger.

the class EngineExchangeTransitionConfigurationTest method shouldNotWarnWhenTimerExecutesBeforeTimeout.

@Test
public void shouldNotWarnWhenTimerExecutesBeforeTimeout(final TestContext ctx) {
    final long TEST_QOS_TIMEOUT = 500L;
    final Async async = ctx.async();
    final AtomicInteger logCounter = new AtomicInteger(0);
    final var spyMethod = spy(method);
    final var spyTimer = spy(new QosTimer(vertx, TEST_QOS_TIMEOUT, z -> logCounter.incrementAndGet()));
    when(spyMethod.getQosTimer()).thenReturn(spyTimer);
    spyTimer.resetTimer();
    vertx.setTimer(50L, z -> {
        try {
            // just once on construction:
            verify(spyTimer, times(1)).resetTimer();
        } catch (Exception ex) {
            ctx.fail(ex);
        }
        // should not warn
        ctx.assertEquals(0, logCounter.get());
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) RunWith(org.junit.runner.RunWith) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Bytes(org.apache.tuweni.bytes.Bytes) Mockito.spy(org.mockito.Mockito.spy) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) JsonRpcResponseType(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponseType) Address(org.hyperledger.besu.datatypes.Address) UnsignedLongParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Wei(org.hyperledger.besu.datatypes.Wei) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Bytes32(org.apache.tuweni.bytes.Bytes32) Before(org.junit.Before) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) LogsBloomFilter(org.hyperledger.besu.evm.log.LogsBloomFilter) Mockito.times(org.mockito.Mockito.times) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Mockito.verify(org.mockito.Mockito.verify) QosTimer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer) Mockito(org.mockito.Mockito) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) ParsedExtraData(org.hyperledger.besu.ethereum.core.ParsedExtraData) EngineExchangeTransitionConfigurationParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineExchangeTransitionConfigurationParameter) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Optional(java.util.Optional) BlockHeaderFunctions(org.hyperledger.besu.ethereum.core.BlockHeaderFunctions) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) EngineExchangeTransitionConfigurationResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineExchangeTransitionConfigurationResult) QosTimer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Async(io.vertx.ext.unit.Async) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Example 3 with QosTimer

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer in project besu by hyperledger.

the class EngineExchangeTransitionConfigurationTest method shouldWarnWhenExchangeConfigNotCalledWithinTimeout.

@Test
public void shouldWarnWhenExchangeConfigNotCalledWithinTimeout(final TestContext ctx) {
    final long TEST_QOS_TIMEOUT = 75L;
    final Async async = ctx.async();
    final AtomicInteger logCounter = new AtomicInteger(0);
    final var spyMethod = spy(method);
    final var spyTimer = spy(new QosTimer(vertx, TEST_QOS_TIMEOUT, z -> logCounter.incrementAndGet()));
    when(spyMethod.getQosTimer()).thenReturn(spyTimer);
    spyTimer.resetTimer();
    vertx.setTimer(100L, z -> {
        try {
            // just once on construction:
            verify(spyTimer, times(1)).resetTimer();
        } catch (Exception ex) {
            ctx.fail(ex);
        }
        // assert one warn:
        ctx.assertEquals(1, logCounter.get());
        async.complete();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) RunWith(org.junit.runner.RunWith) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Bytes(org.apache.tuweni.bytes.Bytes) Mockito.spy(org.mockito.Mockito.spy) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) JsonRpcResponseType(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponseType) Address(org.hyperledger.besu.datatypes.Address) UnsignedLongParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Wei(org.hyperledger.besu.datatypes.Wei) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Bytes32(org.apache.tuweni.bytes.Bytes32) Before(org.junit.Before) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) LogsBloomFilter(org.hyperledger.besu.evm.log.LogsBloomFilter) Mockito.times(org.mockito.Mockito.times) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Mockito.verify(org.mockito.Mockito.verify) QosTimer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer) Mockito(org.mockito.Mockito) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) ParsedExtraData(org.hyperledger.besu.ethereum.core.ParsedExtraData) EngineExchangeTransitionConfigurationParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineExchangeTransitionConfigurationParameter) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Optional(java.util.Optional) BlockHeaderFunctions(org.hyperledger.besu.ethereum.core.BlockHeaderFunctions) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) EngineExchangeTransitionConfigurationResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineExchangeTransitionConfigurationResult) QosTimer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.QosTimer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Async(io.vertx.ext.unit.Async) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Vertx (io.vertx.core.Vertx)3 Async (io.vertx.ext.unit.Async)3 TestContext (io.vertx.ext.unit.TestContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 Map (java.util.Map)3 Optional (java.util.Optional)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Bytes (org.apache.tuweni.bytes.Bytes)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 MergeContext (org.hyperledger.besu.consensus.merge.MergeContext)3 Address (org.hyperledger.besu.datatypes.Address)3 Hash (org.hyperledger.besu.datatypes.Hash)3 Wei (org.hyperledger.besu.datatypes.Wei)3 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)3 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)3 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)3 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)3