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;
}
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));
}
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);
}
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));
}
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();
}
Aggregations