Search in sources :

Example 1 with MessagingService

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

the class ClusterServiceTestUtils method clusterService.

/**
 * Creates a cluster service and required node configuration manager beneath it. Populates node configuration with specified port.
 * Manages configuration manager lifecycle: on cluster service start starts node configuration manager, on cluster service stop - stops
 * node configuration manager.
 *
 * @param testInfo                 Test info.
 * @param port                     Local port.
 * @param nodeFinder               Node finder.
 * @param clusterSvcFactory        Cluster service factory.
 */
public static ClusterService clusterService(TestInfo testInfo, int port, NodeFinder nodeFinder, TestScaleCubeClusterServiceFactory clusterSvcFactory) {
    var registry = new MessageSerializationRegistryImpl();
    REGISTRY_INITIALIZERS.forEach(c -> {
        try {
            c.invoke(c.getDeclaringClass(), registry);
        } catch (Throwable e) {
            throw new RuntimeException("Failed to invoke registry initializer", e);
        }
    });
    var ctx = new ClusterLocalConfiguration(testNodeName(testInfo, port), registry);
    ConfigurationManager nodeConfigurationMgr = new ConfigurationManager(Collections.singleton(NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(ConfigurationType.LOCAL), List.of(), List.of());
    NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
    var bootstrapFactory = new NettyBootstrapFactory(configuration, ctx.getName());
    var clusterSvc = clusterSvcFactory.createClusterService(ctx, configuration, bootstrapFactory);
    assert nodeFinder instanceof StaticNodeFinder : "Only StaticNodeFinder is supported at the moment";
    return new ClusterService() {

        @Override
        public TopologyService topologyService() {
            return clusterSvc.topologyService();
        }

        @Override
        public MessagingService messagingService() {
            return clusterSvc.messagingService();
        }

        @Override
        public ClusterLocalConfiguration localConfiguration() {
            return clusterSvc.localConfiguration();
        }

        @Override
        public boolean isStopped() {
            return clusterSvc.isStopped();
        }

        @Override
        public void start() {
            nodeConfigurationMgr.start();
            NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
            configuration.change(netCfg -> netCfg.changePort(port).changeNodeFinder(c -> c.changeType(NodeFinderType.STATIC.toString()).changeNetClusterNodes(nodeFinder.findNodes().stream().map(NetworkAddress::toString).toArray(String[]::new)))).join();
            bootstrapFactory.start();
            clusterSvc.start();
        }

        @Override
        public void stop() {
            try {
                clusterSvc.stop();
                bootstrapFactory.stop();
                nodeConfigurationMgr.stop();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : IntStream(java.util.stream.IntStream) ClassGraph(io.github.classgraph.ClassGraph) NodeFinderType(org.apache.ignite.configuration.schemas.network.NodeFinderType) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConfigurationType(org.apache.ignite.configuration.annotation.ConfigurationType) IgniteTestUtils.testNodeName(org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) Map(java.util.Map) NodeFinder(org.apache.ignite.network.NodeFinder) ScanResult(io.github.classgraph.ScanResult) Method(java.lang.reflect.Method) MessagingService(org.apache.ignite.network.MessagingService) MessageSerializationRegistryInitializer(org.apache.ignite.network.serialization.MessageSerializationRegistryInitializer) TopologyService(org.apache.ignite.network.TopologyService) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) ClassInfo(io.github.classgraph.ClassInfo) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) TestInfo(org.junit.jupiter.api.TestInfo) NetworkAddress(org.apache.ignite.network.NetworkAddress) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MessageSerializationRegistry(org.apache.ignite.network.serialization.MessageSerializationRegistry) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) ClusterService(org.apache.ignite.network.ClusterService) NetworkMessagesSerializationRegistryInitializer(org.apache.ignite.internal.network.NetworkMessagesSerializationRegistryInitializer) MessageSerializationRegistryImpl(org.apache.ignite.network.MessageSerializationRegistryImpl) Collections(java.util.Collections) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ClusterService(org.apache.ignite.network.ClusterService) MessageSerializationRegistryImpl(org.apache.ignite.network.MessageSerializationRegistryImpl) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager)

Example 2 with MessagingService

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

the class MockedStructuresTest method mockManagers.

// todo copy-paste from TableManagerTest will be removed after https://issues.apache.org/jira/browse/IGNITE-16050
/**
 * Instantiates a table and prepares Table manager.
 *
 * @return Table manager.
 */
private TableManager mockManagers() throws NodeStoppingException {
    when(rm.prepareRaftGroup(any(), any(), any())).thenAnswer(mock -> {
        RaftGroupService raftGrpSrvcMock = mock(RaftGroupService.class);
        when(raftGrpSrvcMock.leader()).thenReturn(new Peer(new NetworkAddress("localhost", 47500)));
        return completedFuture(raftGrpSrvcMock);
    });
    when(ts.getByAddress(any(NetworkAddress.class))).thenReturn(new ClusterNode(UUID.randomUUID().toString(), "node0", new NetworkAddress("localhost", 47500)));
    try (MockedStatic<SchemaUtils> schemaServiceMock = mockStatic(SchemaUtils.class)) {
        schemaServiceMock.when(() -> SchemaUtils.prepareSchemaDescriptor(anyInt(), any())).thenReturn(mock(SchemaDescriptor.class));
    }
    when(cs.messagingService()).thenAnswer(invocation -> {
        MessagingService ret = mock(MessagingService.class);
        return ret;
    });
    when(cs.localConfiguration()).thenAnswer(invocation -> {
        ClusterLocalConfiguration ret = mock(ClusterLocalConfiguration.class);
        when(ret.getName()).thenReturn("node1");
        return ret;
    });
    when(cs.topologyService()).thenAnswer(invocation -> {
        TopologyService ret = mock(TopologyService.class);
        when(ret.localMember()).thenReturn(new ClusterNode("1", "node1", null));
        return ret;
    });
    TableManager tableManager = createTableManager();
    return tableManager;
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) TableManager(org.apache.ignite.internal.table.distributed.TableManager) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) MessagingService(org.apache.ignite.network.MessagingService) TopologyService(org.apache.ignite.network.TopologyService)

Example 3 with MessagingService

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

the class RecordBinaryViewOperationsTest method createTableImpl.

@NotNull
private TableImpl createTableImpl(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 4 with MessagingService

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

the class RecordViewOperationsTest method recordView.

/**
 * Creates RecordView.
 */
private RecordViewImpl<TestObjectWithAllTypes> recordView() {
    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<TestObjectWithAllTypes> recMapper = 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("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("primitiveLongCol".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 RecordViewImpl<>(table, new DummySchemaManagerImpl(schema), recMapper);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) RecordView(org.apache.ignite.table.RecordView) 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) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) 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) Collection(java.util.Collection) 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) 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) NotNull(org.jetbrains.annotations.NotNull) 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 5 with MessagingService

use of org.apache.ignite.network.MessagingService 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)

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