use of org.apache.ignite.network.MessagingService 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.MessagingService in project ignite-3 by apache.
the class KeyValueViewOperationsSimpleSchemaTest 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.MessagingService in project ignite-3 by apache.
the class KeyValueViewOperationsTest method kvView.
/**
* Creates key-value view.
*/
private KeyValueViewImpl<TestKeyObject, TestObjectWithAllTypes> kvView() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
Mapper<TestKeyObject> keyMapper = Mapper.of(TestKeyObject.class);
Mapper<TestObjectWithAllTypes> valMapper = Mapper.of(TestObjectWithAllTypes.class);
Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, valCols);
// Validate all types are tested.
Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
assertEquals(Collections.emptySet(), missedTypes);
return new KeyValueViewImpl<>(table, new DummySchemaManagerImpl(schema), keyMapper, valMapper);
}
use of org.apache.ignite.network.MessagingService in project ignite-3 by apache.
the class MessagingServiceTestUtils method mockMessagingService.
/**
* Prepares messaging service mock.
*
* @param txManager Transaction manager.
* @return Messaging service mock.
*/
public static MessagingService mockMessagingService(TxManager txManager) {
MessagingService messagingService = Mockito.mock(MessagingService.class, RETURNS_DEEP_STUBS);
doAnswer(invocationClose -> {
assert invocationClose.getArgument(1) instanceof TxFinishRequest;
TxFinishRequest txFinishRequest = invocationClose.getArgument(1);
if (txFinishRequest.commit()) {
txManager.commitAsync(txFinishRequest.timestamp()).get();
} else {
txManager.rollbackAsync(txFinishRequest.timestamp()).get();
}
return CompletableFuture.completedFuture(mock(TxFinishResponse.class));
}).when(messagingService).invoke(any(NetworkAddress.class), any(TxFinishRequest.class), anyLong());
return messagingService;
}
use of org.apache.ignite.network.MessagingService in project ignite-3 by apache.
the class SchemaValidationTest method createTable.
/**
* Creates a table for tests.
*
* @return The test table.
*/
private InternalTable createTable() {
clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManagerImpl txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
return new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
}
Aggregations