sergey-chugunov-1985 commented on code in PR #12740: URL: https://github.com/apache/ignite/pull/12740#discussion_r3614358620
########## modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/mdc/MdcDataGeneratorApplication.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.ducktest.tests.mdc; + +import java.util.Map; +import java.util.TreeMap; +import java.util.function.IntFunction; +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.ducktest.tests.dto.IndexedDataRecord; + +/** + * Populates the MDC cache with a deterministic data set: keys in {@code [from, to)}, + * values {@code IndexedDataRecord(key)} (or the key itself in {@code sqlMode}). + * Run it before the network partition. Review Comment: ```suggestion * Runs it until the network partition event. ``` ########## modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/Utils.java: ########## @@ -0,0 +1,84 @@ +/* + * 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.ducktest.utils; + +import java.util.Locale; +import java.util.function.Supplier; +import com.fasterxml.jackson.databind.JsonNode; + +/** Small helpers shared by the ducktest applications. */ +public final class Utils { + /** */ + private Utils() { + // No-op. + } + + /** + * Runs the operation, records its latency into {@code stats} and returns its result. + * If the operation throws, nothing is recorded and the exception propagates. + */ + public static <T> T timed(OpStats stats, Supplier<T> op) { + long startNs = System.nanoTime(); + + T val = op.get(); + + stats.record(System.nanoTime() - startNs); + + return val; + } + + /** + * Runs the void operation and records its latency into {@code stats}. + * If the operation throws, nothing is recorded and the exception propagates. + */ + public static void timed(OpStats stats, Runnable op) { + timed(stats, () -> { + op.run(); + + return null; + }); + } + + /** Formats a nanosecond latency as milliseconds with 3 decimal places. */ + public static String fmtMs(double ns) { + return String.format(Locale.US, "%.3f", ns < 0 ? -1.0 : ns / 1e6); + } + + /** Parses an optional enum-valued field. Defaults only on missing/null. */ Review Comment: ```suggestion /** Parses an optional enum-valued field. Defaults only on missing/null. */ ``` -- 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]
