rpuch commented on a change in pull request #734: URL: https://github.com/apache/ignite-3/pull/734#discussion_r829891135
########## File path: modules/compute/src/test/java/org/apache/ignite/internal/compute/ComputeComponentImplTest.java ########## @@ -0,0 +1,426 @@ +/* + * 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.compute; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.time.Duration; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.ignite.Ignite; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.JobExecutionContext; +import org.apache.ignite.configuration.ConfigurationValue; +import org.apache.ignite.configuration.schemas.compute.ComputeConfiguration; +import org.apache.ignite.internal.compute.message.ExecuteRequest; +import org.apache.ignite.internal.compute.message.ExecuteResponse; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.apache.ignite.lang.NodeStoppingException; +import org.apache.ignite.network.ClusterNode; +import org.apache.ignite.network.MessagingService; +import org.apache.ignite.network.NetworkAddress; +import org.apache.ignite.network.NetworkMessageHandler; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +@Timeout(10) +class ComputeComponentImplTest { + private static final String INSTANCE_NAME = "Ignite-0"; + + @Mock + private Ignite ignite; + + @Mock + private MessagingService messagingService; + + @Mock + private ComputeConfiguration computeConfiguration; + + @Mock + private ConfigurationValue<Integer> threadPoolSizeValue; + + @InjectMocks + private ComputeComponentImpl computeComponent; + + @Captor + private ArgumentCaptor<ExecuteRequest> executeRequestCaptor; + @Captor + private ArgumentCaptor<ExecuteResponse> executeResponseCaptor; + + private final ClusterNode remoteNode = new ClusterNode("remote", "remote", new NetworkAddress("remote-host", 1, "remote")); + + private final AtomicReference<NetworkMessageHandler> computeMessageHandlerRef = new AtomicReference<>(); + + private final AtomicBoolean responseSent = new AtomicBoolean(false); + + @BeforeEach + void setUp() { + when(computeConfiguration.threadPoolSize()).thenReturn(threadPoolSizeValue); + when(threadPoolSizeValue.value()).thenReturn(8); + + lenient().when(ignite.name()).thenReturn(INSTANCE_NAME); Review comment: Here, `lenient()` makes sure that Mockito does not fail a test if the test does not invoke `Ignite#name()` method. This is helpful to setup a common default behavior, but allow this behavior to be 'optional' (i.e. never called). -- 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]
