Search in sources :

Example 6 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class IgniteTestUtils method runAsync.

/**
 * Runs callable task asyncronously.
 *
 * @param task Callable.
 * @param threadName Thread name.
 * @return Future with task result.
 */
public static <T> CompletableFuture<T> runAsync(final Callable<T> task, String threadName) {
    final NamedThreadFactory thrFactory = new NamedThreadFactory(threadName);
    final CompletableFuture<T> fut = new CompletableFuture<T>();
    thrFactory.newThread(() -> {
        try {
            // Execute task.
            T res = task.call();
            fut.complete(res);
        } catch (Throwable e) {
            fut.completeExceptionally(e);
        }
    }).start();
    return fut;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory)

Example 7 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class IgniteTestUtils method runMultiThreadedAsync.

/**
 * Runs callable object in specified number of threads.
 *
 * @param call Callable.
 * @param threadNum Number of threads.
 * @param threadName Thread names.
 * @return Future for the run. Future returns execution time in milliseconds.
 */
public static CompletableFuture<Long> runMultiThreadedAsync(Callable<?> call, int threadNum, final String threadName) {
    List<Callable<?>> calls = Collections.<Callable<?>>nCopies(threadNum, call);
    NamedThreadFactory threadFactory = new NamedThreadFactory(threadName);
    return runAsync(() -> runMultiThreaded(calls, threadFactory));
}
Also used : NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Callable(java.util.concurrent.Callable)

Example 8 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class IgniteTestUtils method runMultiThreaded.

/**
 * Runs callable tasks in specified number of threads.
 *
 * @param call Callable.
 * @param threadNum Number of threads.
 * @param threadName Thread names.
 * @return Execution time in milliseconds.
 * @throws Exception If failed.
 */
public static long runMultiThreaded(Callable<?> call, int threadNum, String threadName) throws Exception {
    List<Callable<?>> calls = Collections.nCopies(threadNum, call);
    NamedThreadFactory threadFactory = new NamedThreadFactory(threadName);
    return runMultiThreaded(calls, threadFactory);
}
Also used : NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Callable(java.util.concurrent.Callable)

Example 9 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class ItSimpleCounterServerTest method before.

/**
 * Before each.
 */
@BeforeEach
void before() throws Exception {
    LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
    var addr = new NetworkAddress("localhost", PORT);
    ClusterService service = clusterService(PORT, List.of(addr), true);
    server = new JraftServerImpl(service, dataPath) {

        @Override
        public synchronized void stop() {
            super.stop();
            service.stop();
        }
    };
    server.start();
    ClusterNode serverNode = server.clusterService().topologyService().localMember();
    assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_0, new CounterListener(), List.of(new Peer(serverNode.address()))));
    assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_1, new CounterListener(), List.of(new Peer(serverNode.address()))));
    ClusterService clientNode1 = clusterService(PORT + 1, List.of(addr), true);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    client1 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_0, clientNode1, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
    ClusterService clientNode2 = clusterService(PORT + 2, List.of(addr), true);
    client2 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_1, clientNode2, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
    assertTrue(waitForTopology(service, 3, 1000));
    assertTrue(waitForTopology(clientNode1, 3, 1000));
    assertTrue(waitForTopology(clientNode2, 3, 1000));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with NamedThreadFactory

use of org.apache.ignite.internal.thread.NamedThreadFactory in project ignite-3 by apache.

the class ItMetaStorageServiceTest method beforeTest.

/**
 * Run {@code NODES} cluster nodes.
 */
@BeforeEach
public void beforeTest(TestInfo testInfo) throws Exception {
    List<NetworkAddress> localAddresses = findLocalAddresses(NODE_PORT_BASE, NODE_PORT_BASE + NODES);
    var nodeFinder = new StaticNodeFinder(localAddresses);
    localAddresses.stream().map(addr -> ClusterServiceTestUtils.clusterService(testInfo, addr.port(), nodeFinder, NETWORK_FACTORY)).forEach(clusterService -> {
        clusterService.start();
        cluster.add(clusterService);
    });
    for (ClusterService node : cluster) {
        assertTrue(waitForTopology(node, NODES, 1000));
    }
    LOG.info("Cluster started.");
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    metaStorageSvc = prepareMetaStorage();
}
Also used : CompoundCondition.and(org.apache.ignite.internal.metastorage.client.CompoundCondition.and) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StatementResult(org.apache.ignite.internal.metastorage.server.StatementResult) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompoundCondition.or(org.apache.ignite.internal.metastorage.client.CompoundCondition.or) ValueCondition(org.apache.ignite.internal.metastorage.server.ValueCondition) Disabled(org.junit.jupiter.api.Disabled) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) Path(java.nio.file.Path) Operations.ops(org.apache.ignite.internal.metastorage.client.Operations.ops) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) EntryEvent(org.apache.ignite.internal.metastorage.server.EntryEvent) Collection(java.util.Collection) Set(java.util.Set) Cursor(org.apache.ignite.internal.util.Cursor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) RevisionCondition(org.apache.ignite.internal.metastorage.server.RevisionCondition) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) TestInfo(org.junit.jupiter.api.TestInfo) RaftServer(org.apache.ignite.internal.raft.server.RaftServer) Conditions.value(org.apache.ignite.internal.metastorage.client.Conditions.value) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NotNull(org.jetbrains.annotations.NotNull) AbstractSimpleCondition(org.apache.ignite.internal.metastorage.server.AbstractSimpleCondition) RaftGroupServiceImpl(org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl) ClusterServiceTestUtils.findLocalAddresses(org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Operations.remove(org.apache.ignite.internal.metastorage.client.Operations.remove) ClusterServiceTestUtils(org.apache.ignite.utils.ClusterServiceTestUtils) Mock(org.mockito.Mock) Loza(org.apache.ignite.internal.raft.Loza) ServerConditionMatcher.cond(org.apache.ignite.internal.metastorage.client.ItMetaStorageServiceTest.ServerConditionMatcher.cond) ArrayList(java.util.ArrayList) AndCondition(org.apache.ignite.internal.metastorage.server.AndCondition) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) If.iif(org.apache.ignite.internal.metastorage.client.If.iif) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtils.waitForTopology(org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology) Type(org.apache.ignite.internal.metastorage.server.ValueCondition.Type) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Conditions.revision(org.apache.ignite.internal.metastorage.client.Conditions.revision) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) Description(org.hamcrest.Description) Iterator(java.util.Iterator) ByteArray(org.apache.ignite.lang.ByteArray) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) OrCondition(org.apache.ignite.internal.metastorage.server.OrCondition) Mockito.verify(org.mockito.Mockito.verify) WorkDirectory(org.apache.ignite.internal.testframework.WorkDirectory) NetworkAddress(org.apache.ignite.network.NetworkAddress) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) Operations.put(org.apache.ignite.internal.metastorage.client.Operations.put) TreeMap(java.util.TreeMap) AbstractCompoundCondition(org.apache.ignite.internal.metastorage.server.AbstractCompoundCondition) OperationType(org.apache.ignite.internal.metastorage.common.OperationType) ClusterService(org.apache.ignite.network.ClusterService) ServerUpdateMatcher.upd(org.apache.ignite.internal.metastorage.client.ItMetaStorageServiceTest.ServerUpdateMatcher.upd) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) Collections(java.util.Collections) Update(org.apache.ignite.internal.metastorage.server.Update) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)12 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 NetworkAddress (org.apache.ignite.network.NetworkAddress)5 Peer (org.apache.ignite.raft.client.Peer)5 ClusterService (org.apache.ignite.network.ClusterService)4 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)4 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Loza (org.apache.ignite.internal.raft.Loza)3 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)3 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)3 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)3 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)3 RaftGroupServiceImpl (org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl)3 TestUtils.waitForTopology (org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology)3 ClusterServiceTestUtils (org.apache.ignite.utils.ClusterServiceTestUtils)3 ClusterServiceTestUtils.findLocalAddresses (org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses)3