Search in sources :

Example 6 with TableManager

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

the class TableManagerTest method testInternalApiTableManagerOnStop.

/**
 * Tests a work of the public API for Table manager {@see org.apache.ignite.internal.table.IgniteTablesInternal} when the manager is
 * stopping.
 */
@Test
public void testInternalApiTableManagerOnStop() {
    createTableManager(tblManagerFut);
    TableManager tableManager = tblManagerFut.join();
    tableManager.beforeNodeStop();
    tableManager.stop();
    UUID fakeTblId = UUID.randomUUID();
    assertThrows(IgniteException.class, () -> tableManager.table(fakeTblId));
    assertThrows(IgniteException.class, () -> tableManager.tableAsync(fakeTblId));
    assertThrows(NodeStoppingException.class, () -> tableManager.setBaseline(Collections.singleton("fakeNode0")));
}
Also used : TableManager(org.apache.ignite.internal.table.distributed.TableManager) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 7 with TableManager

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

the class TableManagerTest method testApiTableManagerOnStop.

/**
 * Tests a work of the public API for Table manager {@see org.apache.ignite.table.manager.IgniteTables} when the manager is stopping.
 */
@Test
public void testApiTableManagerOnStop() {
    createTableManager(tblManagerFut);
    TableManager tableManager = tblManagerFut.join();
    tableManager.beforeNodeStop();
    tableManager.stop();
    String tblFullName = "PUBLIC." + DYNAMIC_TABLE_FOR_DROP_NAME;
    Consumer<TableChange> createTableChange = (TableChange change) -> SchemaConfigurationConverter.convert(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(), change).changeReplicas(REPLICAS).changePartitions(PARTITIONS);
    final Consumer<TableChange> addColumnChange = (TableChange change) -> change.changeColumns(cols -> {
        int colIdx = change.columns().namedListKeys().stream().mapToInt(Integer::parseInt).max().getAsInt() + 1;
        cols.create(String.valueOf(colIdx), colChg -> SchemaConfigurationConverter.convert(SchemaBuilders.column("name", ColumnType.string()).build(), colChg));
    });
    TableManager igniteTables = tableManager;
    assertThrows(IgniteException.class, () -> igniteTables.createTable(tblFullName, createTableChange));
    assertThrows(IgniteException.class, () -> igniteTables.createTableAsync(tblFullName, createTableChange));
    assertThrows(IgniteException.class, () -> igniteTables.alterTable(tblFullName, addColumnChange));
    assertThrows(IgniteException.class, () -> igniteTables.alterTableAsync(tblFullName, addColumnChange));
    assertThrows(IgniteException.class, () -> igniteTables.dropTable(tblFullName));
    assertThrows(IgniteException.class, () -> igniteTables.dropTableAsync(tblFullName));
    assertThrows(IgniteException.class, () -> igniteTables.tables());
    assertThrows(IgniteException.class, () -> igniteTables.tablesAsync());
    assertThrows(IgniteException.class, () -> igniteTables.table(tblFullName));
    assertThrows(IgniteException.class, () -> igniteTables.tableAsync(tblFullName));
}
Also used : TableManager(org.apache.ignite.internal.table.distributed.TableManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 8 with TableManager

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

the class TableManagerTest method testDropTable.

/**
 * Tests drop a table through public API.
 *
 * @throws Exception If failed.
 */
@Test
public void testDropTable() 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);
    TableManager tableManager = tblManagerFut.join();
    tableManager.dropTable(scmTbl.canonicalName());
    assertNull(tableManager.table(scmTbl.canonicalName()));
    assertEquals(0, tableManager.tables().size());
}
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 9 with TableManager

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

the class StopCalciteModuleTest method before.

/**
 * Before.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@BeforeEach
public void before(TestInfo testInfo) {
    when(clusterSrvc.messagingService()).thenReturn(msgSrvc);
    when(clusterSrvc.topologyService()).thenReturn(topologySrvc);
    when(clusterSrvc.localConfiguration()).thenReturn(localCfg);
    ClusterNode node = new ClusterNode("mock-node-id", NODE_NAME, null);
    when(topologySrvc.localMember()).thenReturn(node);
    when(topologySrvc.allMembers()).thenReturn(Collections.singleton(node));
    SchemaDescriptor schemaDesc = new SchemaDescriptor(1, new Column[] { new Column(0, "ID", NativeTypes.INT32, false) }, new Column[] { new Column(1, "VAL", NativeTypes.INT32, false) });
    schemaReg = new SchemaRegistryImpl(1, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);
    when(tbl.name()).thenReturn("PUBLIC.TEST");
    // Mock create table (notify on register listener).
    doAnswer(invocation -> {
        EventListener<TableEventParameters> clo = (EventListener<TableEventParameters>) invocation.getArguments()[1];
        clo.notify(new TableEventParameters(0, UUID.randomUUID(), "TEST", new TableImpl(tbl, schemaReg)), null);
        return null;
    }).when(tableManager).listen(eq(TableEvent.CREATE), any());
    RowAssembler asm = new RowAssembler(schemaReg.schema(), 0, 0, 0, 0);
    asm.appendInt(0);
    asm.appendInt(0);
    BinaryRow binaryRow = asm.build();
    // Mock table scan
    doAnswer(invocation -> {
        int part = (int) invocation.getArguments()[0];
        return (Flow.Publisher<BinaryRow>) s -> {
            s.onSubscribe(new Flow.Subscription() {

                @Override
                public void request(long n) {
                }

                @Override
                public void cancel() {
                }
            });
            if (part == 0) {
                for (int i = 0; i < ROWS; ++i) {
                    s.onNext(binaryRow);
                }
            }
            s.onComplete();
        };
    }).when(tbl).scan(anyInt(), any());
    LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ThreadInfo(java.lang.management.ThreadInfo) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) TableImpl(org.apache.ignite.internal.table.TableImpl) Flow(java.util.concurrent.Flow) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ManagementFactory(java.lang.management.ManagementFactory) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) MessagingService(org.apache.ignite.network.MessagingService) TableManager(org.apache.ignite.internal.table.distributed.TableManager) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Mockito.when(org.mockito.Mockito.when) ThreadMXBean(java.lang.management.ThreadMXBean) UUID(java.util.UUID) TestInfo(org.junit.jupiter.api.TestInfo) ClusterNode(org.apache.ignite.network.ClusterNode) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) Column(org.apache.ignite.internal.schema.Column) TableEvent(org.apache.ignite.internal.table.event.TableEvent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClusterService(org.apache.ignite.network.ClusterService) EventListener(org.apache.ignite.internal.manager.EventListener) Collections(java.util.Collections) SchemaRegistry(org.apache.ignite.internal.schema.SchemaRegistry) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableImpl(org.apache.ignite.internal.table.TableImpl) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Flow(java.util.concurrent.Flow) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Column(org.apache.ignite.internal.schema.Column) EventListener(org.apache.ignite.internal.manager.EventListener) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with TableManager

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

the class MockedStructuresTest method createTableManager.

/**
 * Creates Table manager.
 *
 * @return Table manager.
 */
@NotNull
private TableManager createTableManager() {
    TableManager tableManager = new TableManager(revisionUpdater, tblsCfg, dataStorageCfg, rm, bm, ts, workDir, tm);
    tableManager.start();
    return tableManager;
}
Also used : TableManager(org.apache.ignite.internal.table.distributed.TableManager) NotNull(org.jetbrains.annotations.NotNull)

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