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