Search in sources :

Example 6 with MessagingService

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

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));
}
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 8 with MessagingService

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);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DOUBLE(org.apache.ignite.internal.schema.NativeTypes.DOUBLE) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) KeyValueView(org.apache.ignite.table.KeyValueView) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) INT8(org.apache.ignite.internal.schema.NativeTypes.INT8) Mapper(org.apache.ignite.table.mapper.Mapper) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MessagingService(org.apache.ignite.network.MessagingService) FLOAT(org.apache.ignite.internal.schema.NativeTypes.FLOAT) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) NativeTypes.datetime(org.apache.ignite.internal.schema.NativeTypes.datetime) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) NativeTypes.timestamp(org.apache.ignite.internal.schema.NativeTypes.timestamp) Set(java.util.Set) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) Collectors(java.util.stream.Collectors) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) BYTES(org.apache.ignite.internal.schema.NativeTypes.BYTES) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) STRING(org.apache.ignite.internal.schema.NativeTypes.STRING) Column(org.apache.ignite.internal.schema.Column) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NativeTypes.time(org.apache.ignite.internal.schema.NativeTypes.time) ClusterService(org.apache.ignite.network.ClusterService) INT16(org.apache.ignite.internal.schema.NativeTypes.INT16) INT32(org.apache.ignite.internal.schema.NativeTypes.INT32) Collections(java.util.Collections) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TxManager(org.apache.ignite.internal.tx.TxManager) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Column(org.apache.ignite.internal.schema.Column) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl)

Example 9 with MessagingService

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;
}
Also used : TxFinishResponse(org.apache.ignite.internal.tx.message.TxFinishResponse) TxFinishRequest(org.apache.ignite.internal.tx.message.TxFinishRequest) NetworkAddress(org.apache.ignite.network.NetworkAddress) MessagingService(org.apache.ignite.network.MessagingService)

Example 10 with 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);
}
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) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) MessagingService(org.apache.ignite.network.MessagingService)

Aggregations

MessagingService (org.apache.ignite.network.MessagingService)12 ClusterService (org.apache.ignite.network.ClusterService)9 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)7 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)7 DummyInternalTableImpl (org.apache.ignite.internal.table.impl.DummyInternalTableImpl)7 HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)7 TxManagerImpl (org.apache.ignite.internal.tx.impl.TxManagerImpl)7 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)6 TxManager (org.apache.ignite.internal.tx.TxManager)5 List (java.util.List)4 Test (org.junit.jupiter.api.Test)4 Collections (java.util.Collections)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 LockManager (org.apache.ignite.internal.tx.LockManager)3 NetworkAddress (org.apache.ignite.network.NetworkAddress)3 NotNull (org.jetbrains.annotations.NotNull)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Random (java.util.Random)2 Set (java.util.Set)2