Search in sources :

Example 1 with TableManager

use of org.apache.ignite.internal.table.distributed.TableManager 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 TableManager

use of org.apache.ignite.internal.table.distributed.TableManager 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)

Example 3 with TableManager

use of org.apache.ignite.internal.table.distributed.TableManager in project ignite-3 by apache.

the class TableManagerTest method tableManagerStopTest.

/**
 * Cheks that the all RAFT nodes will be stopped when Table manager is stopping.
 *
 * @throws Exception If failed.
 */
@Test
public void tableManagerStopTest() throws Exception {
    TableDefinition scmTbl = SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_FOR_DROP_NAME).columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build()).withPrimaryKey("key").build();
    mockManagersAndCreateTable(scmTbl, tblManagerFut);
    verify(rm, times(PARTITIONS)).prepareRaftGroup(anyString(), any(), any());
    TableManager tableManager = tblManagerFut.join();
    tableManager.stop();
    verify(rm, times(PARTITIONS)).stopRaftGroup(anyString());
}
Also used : TableDefinition(org.apache.ignite.schema.definition.TableDefinition) TableManager(org.apache.ignite.internal.table.distributed.TableManager) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 4 with TableManager

use of org.apache.ignite.internal.table.distributed.TableManager in project ignite-3 by apache.

the class TableManagerTest method testStaticTableConfigured.

/**
 * Tests a table which was defined before start through bootstrap configuration.
 */
@Disabled("https://issues.apache.org/jira/browse/IGNITE-16433")
@Test
public void testStaticTableConfigured() {
    TableManager tableManager = new TableManager(revisionUpdater, tblsCfg, dataStorageCfg, rm, bm, ts, workDir, tm);
    assertEquals(1, tableManager.tables().size());
    assertNotNull(tableManager.table(STATIC_TABLE_NAME));
}
Also used : TableManager(org.apache.ignite.internal.table.distributed.TableManager) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with TableManager

use of org.apache.ignite.internal.table.distributed.TableManager in project ignite-3 by apache.

the class TableManagerTest method createTableManager.

/**
 * Creates Table manager.
 *
 * @param tblManagerFut Future to wrap Table manager.
 * @return Table manager.
 */
@NotNull
private TableManager createTableManager(CompletableFuture<TableManager> tblManagerFut) {
    TableManager tableManager = new TableManager(revisionUpdater, tblsCfg, dataStorageCfg, rm, bm, ts, workDir, tm);
    tableManager.start();
    tblManagerFut.complete(tableManager);
    return tableManager;
}
Also used : TableManager(org.apache.ignite.internal.table.distributed.TableManager) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull)

Aggregations

TableManager (org.apache.ignite.internal.table.distributed.TableManager)10 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)6 Test (org.junit.jupiter.api.Test)6 UUID (java.util.UUID)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 ClusterNode (org.apache.ignite.network.ClusterNode)3 TopologyService (org.apache.ignite.network.TopologyService)3 Collections (java.util.Collections)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 TableChange (org.apache.ignite.configuration.schemas.table.TableChange)2 SchemaUtils (org.apache.ignite.internal.schema.SchemaUtils)2 IgniteException (org.apache.ignite.lang.IgniteException)2 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)2 ClusterLocalConfiguration (org.apache.ignite.network.ClusterLocalConfiguration)2 MessagingService (org.apache.ignite.network.MessagingService)2 NetworkAddress (org.apache.ignite.network.NetworkAddress)2 Peer (org.apache.ignite.raft.client.Peer)2 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)2 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)2