sashapolo commented on code in PR #3393: URL: https://github.com/apache/ignite-3/pull/3393#discussion_r1519758505
########## modules/core/src/test/java/org/apache/ignite/internal/thread/PublicApiThreadingTest.java: ########## @@ -0,0 +1,158 @@ +/* + * 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.thread; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.apache.ignite.internal.util.IgniteUtils; +import org.hamcrest.core.CombinableMatcher; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class PublicApiThreadingTest { + private final ExecutorService internalThreadPool = Executors.newSingleThreadExecutor(task -> new TestThread(task, true)); + private final ExecutorService asyncContinuationExecutor = Executors.newSingleThreadExecutor(task -> new TestThread(task, false)); + + private static CompletableFuture<Thread> getCompletionThreadFuture(CompletableFuture<Void> publicFuture) { + return publicFuture.thenApply(unused -> Thread.currentThread()); + } + + private static CombinableMatcher<Object> internalPoolThread() { + return both(instanceOf(TestThread.class)).and(hasProperty("internal", is(true))); Review Comment: Do we really need to use `hasProperty` here? Can we read the field value in a "normal" way? ########## modules/core/src/main/java/org/apache/ignite/internal/thread/PublicApiThreading.java: ########## @@ -48,12 +51,16 @@ public static void endInternalCall() { * @return Call result. */ public static <T> T doInternalCall(Supplier<T> call) { + boolean wasInInternalCallBefore = inInternalCall(); + startInternalCall(); Review Comment: Do we need to check the `wasInInternalCallBefore` flag? I understand that this method is idempotent, but it will be more consistent. Maybe we should even avoid the try-finally schenanigans if we are already in an internal call. ########## modules/table/src/integrationTest/java/org/apache/ignite/internal/threading/ItKvRecordApiThreadingTest.java: ########## @@ -84,13 +104,24 @@ private static Table testTable() { return CLUSTER.aliveNode().tables().table(TABLE_NAME); } + @BeforeEach + void upsertRecord() { + KeyValueView<Integer, String> view = plainKeyValueView(); + + // #KEY is used by tests related to KV operations and queries. + view.put(null, KEY, "one"); + } + @SuppressWarnings("rawtypes") @CartesianTest void keyValueViewFuturesCompleteInContinuationsPool( @Enum KeyValueViewAsyncOperation operation, @Enum KeyValueViewKind kind ) { - assumeTrue(kind.supportsGetNullable() || !operation.isGetNullable()); + assumeTrue( + kind.supportsGetNullable() || !operation.isGetNullable(), + "getNullable() is not supported for this view, so skipping the test" Review Comment: ```suggestion "getNullable() is not supported by views of type " + kind ``` ########## modules/table/src/integrationTest/java/org/apache/ignite/internal/threading/ItKvRecordApiThreadingTest.java: ########## @@ -207,6 +233,119 @@ private static RecordContext<Tuple> binaryRecordContext() { return new RecordContext<>(KEY_RECORD.toKeyTuple(), new Record(KEY, "one").toFullTuple(), new Record(KEY, "two").toFullTuple()); } + @SuppressWarnings("rawtypes") Review Comment: Why do you need to use raw types in these tests? I was able to get rid of them by simply using the wildcard type everywhere ########## modules/table/src/integrationTest/java/org/apache/ignite/internal/threading/ItKvRecordApiThreadingTest.java: ########## @@ -207,6 +233,119 @@ private static RecordContext<Tuple> binaryRecordContext() { return new RecordContext<>(KEY_RECORD.toKeyTuple(), new Record(KEY, "one").toFullTuple(), new Record(KEY, "two").toFullTuple()); } + @SuppressWarnings("rawtypes") + @CartesianTest + void commonViewFuturesCompleteInContinuationsPool(@Enum CommonViewAsyncOperation operation, @Enum ViewKind kind) { + CriteriaQuerySource tableView = kind.criteriaQuerySource(); + + @SuppressWarnings("unchecked") CompletableFuture<Thread> completerFuture = forcingSwitchFromUserThread( Review Comment: Same applies to this: if you replace some generics with a wildcard type, then no suppression is needed. -- 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]
