alievmirza commented on code in PR #7845: URL: https://github.com/apache/ignite-3/pull/7845#discussion_r2995810985
########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/schema/SchemaSyncMetricSourceTest.java: ########## @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.table.distributed.schema; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.apache.ignite.internal.metrics.DistributionMetric; +import org.apache.ignite.internal.metrics.MetricRegistry; +import org.apache.ignite.internal.metrics.MetricSet; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** Tests for {@link SchemaSyncMetricSource}. */ +class SchemaSyncMetricSourceTest extends BaseIgniteAbstractTest { + private SchemaSyncMetricSource source; + private DistributionMetric waits; + + @BeforeEach + void setUp() { + source = new SchemaSyncMetricSource(); + MetricRegistry registry = new MetricRegistry(); Review Comment: done ########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/schema/SchemaSyncServiceImplTest.java: ########## @@ -70,4 +75,42 @@ void waitsOnSchemaSafeTimeTillSchemaCompletenessSubtractingDelayDuration() { safeTimeFuture.complete(null); assertThat(waitFuture, willCompleteSuccessfully()); } + + @Test + void waitRecorderIsCalledWithDurationOnCompletion() { + List<Long> recorded = new ArrayList<>(); + schemaSyncService = new SchemaSyncServiceImpl(schemaSafeTimeTracker, delayDurationMs, recorded::add); + + HybridTimestamp ts = clock.now(); + var safeTimeFuture = new CompletableFuture<Void>(); + + when(schemaSafeTimeTracker.waitFor(ts.subtractPhysicalTime(delayDurationMs.getAsLong()))).thenReturn(safeTimeFuture); + + schemaSyncService.waitForMetadataCompleteness(ts); + + assertThat(recorded, empty()); + + safeTimeFuture.complete(null); + + assertThat(recorded, hasSize(1)); + assertThat(recorded.get(0), greaterThanOrEqualTo(0L)); + } + + @Test + void waitRecorderIsCalledEvenWhenFutureCompletesExceptionally() { + List<Long> recorded = new ArrayList<>(); + schemaSyncService = new SchemaSyncServiceImpl(schemaSafeTimeTracker, delayDurationMs, recorded::add); + + HybridTimestamp ts = clock.now(); + var safeTimeFuture = new CompletableFuture<Void>(); + + when(schemaSafeTimeTracker.waitFor(ts.subtractPhysicalTime(delayDurationMs.getAsLong()))).thenReturn(safeTimeFuture); + + schemaSyncService.waitForMetadataCompleteness(ts); + + safeTimeFuture.completeExceptionally(new RuntimeException("test error")); + + assertThat(recorded, hasSize(1)); + assertThat(recorded.get(0), greaterThanOrEqualTo(0L)); + } Review Comment: added ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/SchemaSyncServiceImpl.java: ########## @@ -31,17 +32,38 @@ public class SchemaSyncServiceImpl implements SchemaSyncService { private final LongSupplier delayDurationMs; + private final LongConsumer waitDurationMsRecorder; + /** * Constructor. */ public SchemaSyncServiceImpl(SchemaSafeTimeTracker schemaSafeTimeTracker, LongSupplier delayDurationMs) { + this(schemaSafeTimeTracker, delayDurationMs, durationMs -> {}); + } + + /** + * Constructor with metrics recording. + * + * @param schemaSafeTimeTracker Schema safe time tracker. + * @param delayDurationMs Supplier of the delay duration in milliseconds. + * @param waitDurationMsRecorder Consumer that receives the duration (in ms) of each completed wait. + */ + public SchemaSyncServiceImpl( + SchemaSafeTimeTracker schemaSafeTimeTracker, + LongSupplier delayDurationMs, + LongConsumer waitDurationMsRecorder + ) { this.schemaSafeTimeTracker = schemaSafeTimeTracker; this.delayDurationMs = delayDurationMs; + this.waitDurationMsRecorder = waitDurationMsRecorder; } @Override public CompletableFuture<Void> waitForMetadataCompleteness(HybridTimestamp ts) { - return schemaSafeTimeTracker.waitFor(metastoreSafeTimeToWait(ts)); + long startMs = System.currentTimeMillis(); Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
