Search in sources :

Example 11 with ClusterService

use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.

the class KeyValueBinaryViewOperationsTest method createTable.

@NotNull
private TableImpl createTable(SchemaDescriptor schema) {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    LockManager lockManager = new HeapLockManager();
    TxManager txManager = new TxManagerImpl(clusterService, lockManager);
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    return new TableImpl(table, new DummySchemaManagerImpl(schema));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) LockManager(org.apache.ignite.internal.tx.LockManager) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with ClusterService

use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.

the class ItLozaTest method testRaftServiceUsingSharedExecutor.

/**
 * Tests that RaftGroupServiceImpl uses shared executor for retrying RaftGroupServiceImpl#sendWithRetry().
 */
@Test
public void testRaftServiceUsingSharedExecutor(TestInfo testInfo) throws Exception {
    ClusterService service = null;
    Loza loza = null;
    RaftGroupService[] grpSrvcs = new RaftGroupService[5];
    try {
        service = spy(clusterService(testInfo, PORT, List.of()));
        MessagingService messagingServiceMock = spy(service.messagingService());
        when(service.messagingService()).thenReturn(messagingServiceMock);
        CompletableFuture<NetworkMessage> exception = CompletableFuture.failedFuture(new Exception(new IOException()));
        loza = new Loza(service, dataPath);
        loza.start();
        for (int i = 0; i < grpSrvcs.length; i++) {
            // return an error on first invocation
            doReturn(exception).doAnswer(invocation -> {
                assertThat(Thread.currentThread().getName(), containsString(Loza.CLIENT_POOL_NAME));
                return exception;
            }).doCallRealMethod().when(messagingServiceMock).invoke(any(NetworkAddress.class), any(), anyLong());
            grpSrvcs[i] = startClient(Integer.toString(i), service.topologyService().localMember(), loza);
            verify(messagingServiceMock, times(3 * (i + 1))).invoke(any(NetworkAddress.class), any(), anyLong());
        }
    } finally {
        for (RaftGroupService srvc : grpSrvcs) {
            srvc.shutdown();
            loza.stopRaftGroup(srvc.groupId());
        }
        if (loza != null) {
            loza.stop();
        }
        if (service != null) {
            service.stop();
        }
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ClusterServiceTestUtils(org.apache.ignite.utils.ClusterServiceTestUtils) CompletableFuture(java.util.concurrent.CompletableFuture) RaftGroupListener(org.apache.ignite.raft.client.service.RaftGroupListener) Mockito.spy(org.mockito.Mockito.spy) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(java.nio.file.Path) MessagingService(org.apache.ignite.network.MessagingService) NetworkMessage(org.apache.ignite.network.NetworkMessage) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) TestInfo(org.junit.jupiter.api.TestInfo) Mockito.verify(org.mockito.Mockito.verify) WorkDirectory(org.apache.ignite.internal.testframework.WorkDirectory) ClusterNode(org.apache.ignite.network.ClusterNode) NetworkAddress(org.apache.ignite.network.NetworkAddress) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ClusterService(org.apache.ignite.network.ClusterService) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) IOException(java.io.IOException) NetworkMessage(org.apache.ignite.network.NetworkMessage) IOException(java.io.IOException) MessagingService(org.apache.ignite.network.MessagingService) Test(org.junit.jupiter.api.Test)

Example 13 with ClusterService

use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.

the class ItAbstractListenerSnapshotTest method startClient.

/**
 * Starts a client with a specific address.
 *
 * @return The service.
 */
private RaftGroupService startClient(TestInfo testInfo, String groupId, NetworkAddress addr) throws Exception {
    ClusterService clientNode = clusterService(testInfo, CLIENT_PORT + clients.size(), addr);
    RaftGroupService client = RaftGroupServiceImpl.start(groupId, clientNode, FACTORY, 10_000, List.of(new Peer(addr)), false, 200, executor).get(3, TimeUnit.SECONDS);
    // Transactios by now require a leader to build a mapping.
    client.refreshLeader().join();
    clients.add(client);
    return client;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) Peer(org.apache.ignite.raft.client.Peer)

Example 14 with ClusterService

use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.

the class PartitionCommandListenerTest method before.

/**
 * Initializes a table listener before tests.
 */
@BeforeEach
public void before() {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    NetworkAddress addr = new NetworkAddress("127.0.0.1", 5003);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(addr);
    commandListener = new PartitionListener(UUID.randomUUID(), new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), new TxManagerImpl(clusterService, new HeapLockManager())));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with ClusterService

use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.

the class ItClusterServiceTest method testShutdown.

@Test
void testShutdown(TestInfo testInfo) {
    var addr = new NetworkAddress("localhost", 10000);
    ClusterService service = clusterService(testInfo, addr.port(), new StaticNodeFinder(List.of(addr)), new TestScaleCubeClusterServiceFactory());
    service.start();
    service.stop();
    assertThat(service.isStopped(), is(true));
    ExecutionException e = assertThrows(ExecutionException.class, () -> service.messagingService().send(mock(ClusterNode.class), mock(NetworkMessage.class)).get(5, TimeUnit.SECONDS));
    assertThat(e.getCause(), isA(NodeStoppingException.class));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ExecutionException(java.util.concurrent.ExecutionException) NetworkMessage(org.apache.ignite.network.NetworkMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterService (org.apache.ignite.network.ClusterService)42 NetworkAddress (org.apache.ignite.network.NetworkAddress)18 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)12 Test (org.junit.jupiter.api.Test)12 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)11 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)11 HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)11 TxManagerImpl (org.apache.ignite.internal.tx.impl.TxManagerImpl)11 List (java.util.List)10 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)10 ClusterNode (org.apache.ignite.network.ClusterNode)9 MessagingService (org.apache.ignite.network.MessagingService)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 DummyInternalTableImpl (org.apache.ignite.internal.table.impl.DummyInternalTableImpl)7 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)7 TxManager (org.apache.ignite.internal.tx.TxManager)7 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)7 AfterEach (org.junit.jupiter.api.AfterEach)7 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)6 Peer (org.apache.ignite.raft.client.Peer)6