Search in sources :

Example 1 with SchemaUtils

use of org.apache.ignite.internal.schema.SchemaUtils 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 2 with SchemaUtils

use of org.apache.ignite.internal.schema.SchemaUtils in project ignite-3 by apache.

the class TableManagerTest method mockManagersAndCreateTableWithDelay.

/**
 * Instantiates a table and prepares Table manager. When the latch would open, the method completes.
 *
 * @param tableDefinition Configuration schema for a table.
 * @param tblManagerFut   Future for table manager.
 * @param phaser          Phaser for the wait.
 * @return Table manager.
 * @throws NodeStoppingException If something went wrong.
 */
@NotNull
private TableImpl mockManagersAndCreateTableWithDelay(TableDefinition tableDefinition, CompletableFuture<TableManager> tblManagerFut, Phaser phaser) 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 CompletableFuture.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));
    }
    try (MockedStatic<AffinityUtils> affinityServiceMock = mockStatic(AffinityUtils.class)) {
        ArrayList<List<ClusterNode>> assignment = new ArrayList<>(PARTITIONS);
        for (int part = 0; part < PARTITIONS; part++) {
            assignment.add(new ArrayList<>(Collections.singleton(node)));
        }
        affinityServiceMock.when(() -> AffinityUtils.calculateAssignments(any(), anyInt(), anyInt())).thenReturn(assignment);
    }
    TableManager tableManager = createTableManager(tblManagerFut);
    final int tablesBeforeCreation = tableManager.tables().size();
    tblsCfg.tables().listen(ctx -> {
        boolean createTbl = ctx.newValue().get(tableDefinition.canonicalName()) != null && ctx.oldValue().get(tableDefinition.canonicalName()) == null;
        boolean dropTbl = ctx.oldValue().get(tableDefinition.canonicalName()) != null && ctx.newValue().get(tableDefinition.canonicalName()) == null;
        if (!createTbl && !dropTbl) {
            return CompletableFuture.completedFuture(null);
        }
        if (phaser != null) {
            phaser.arriveAndAwaitAdvance();
        }
        return CompletableFuture.completedFuture(null);
    });
    TableImpl tbl2 = (TableImpl) tableManager.createTable(tableDefinition.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(tableDefinition, tblCh).changeReplicas(REPLICAS).changePartitions(PARTITIONS));
    assertNotNull(tbl2);
    assertEquals(tablesBeforeCreation + 1, tableManager.tables().size());
    return tbl2;
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) BeforeEach(org.junit.jupiter.api.BeforeEach) Disabled(org.junit.jupiter.api.Disabled) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Collection(java.util.Collection) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) UUID(java.util.UUID) ColumnType(org.apache.ignite.schema.definition.ColumnType) TxManager(org.apache.ignite.internal.tx.TxManager) ClusterNode(org.apache.ignite.network.ClusterNode) Test(org.junit.jupiter.api.Test) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NotNull(org.jetbrains.annotations.NotNull) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) HashIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) IgniteException(org.apache.ignite.lang.IgniteException) Mock(org.mockito.Mock) Mockito.mockStatic(org.mockito.Mockito.mockStatic) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Loza(org.apache.ignite.internal.raft.Loza) CompletableFuture(java.util.concurrent.CompletableFuture) PartialIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema) SortedIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema) ArrayList(java.util.ArrayList) InjectConfiguration(org.apache.ignite.internal.configuration.testframework.InjectConfiguration) ConfigurationExtension(org.apache.ignite.internal.configuration.testframework.ConfigurationExtension) RocksDbDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) TableManager(org.apache.ignite.internal.table.distributed.TableManager) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) ConfigurationStorageRevisionListenerHolder(org.apache.ignite.internal.configuration.notifications.ConfigurationStorageRevisionListenerHolder) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) BaselineManager(org.apache.ignite.internal.baseline.BaselineManager) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) LockManager(org.apache.ignite.internal.tx.LockManager) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) ExtendedTableConfigurationSchema(org.apache.ignite.internal.configuration.schema.ExtendedTableConfigurationSchema) Phaser(java.util.concurrent.Phaser) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) InjectRevisionListenerHolder(org.apache.ignite.internal.configuration.testframework.InjectRevisionListenerHolder) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Table(org.apache.ignite.table.Table) Collections(java.util.Collections) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) ArrayList(java.util.ArrayList) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) NetworkAddress(org.apache.ignite.network.NetworkAddress) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) TableManager(org.apache.ignite.internal.table.distributed.TableManager) List(java.util.List) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)2 SchemaUtils (org.apache.ignite.internal.schema.SchemaUtils)2 TableManager (org.apache.ignite.internal.table.distributed.TableManager)2 ClusterNode (org.apache.ignite.network.ClusterNode)2 NetworkAddress (org.apache.ignite.network.NetworkAddress)2 TopologyService (org.apache.ignite.network.TopologyService)2 Peer (org.apache.ignite.raft.client.Peer)2 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Phaser (java.util.concurrent.Phaser)1 Consumer (java.util.function.Consumer)1 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)1 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)1 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)1 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)1