Search in sources :

Example 21 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class AbstractBasicIntegrationTest method createTable.

protected static void createTable(TableDefinitionBuilder tblBld) {
    TableDefinition schTbl1 = tblBld.build();
    CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
}
Also used : TableDefinition(org.apache.ignite.schema.definition.TableDefinition)

Example 22 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class TableManagerTest method testGetTableDuringCreation.

/**
 * Instantiates a table and prepares Table manager.
 */
@Test
public void testGetTableDuringCreation() {
    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();
    Phaser phaser = new Phaser(2);
    CompletableFuture<Table> createFut = CompletableFuture.supplyAsync(() -> {
        try {
            return mockManagersAndCreateTableWithDelay(scmTbl, tblManagerFut, phaser);
        } catch (NodeStoppingException e) {
            fail(e.getMessage());
        }
        return null;
    });
    CompletableFuture<Table> getFut = CompletableFuture.supplyAsync(() -> {
        phaser.awaitAdvance(0);
        return tblManagerFut.join().table(scmTbl.canonicalName());
    });
    CompletableFuture<Collection<Table>> getAllTablesFut = CompletableFuture.supplyAsync(() -> {
        phaser.awaitAdvance(0);
        return tblManagerFut.join().tables();
    });
    assertFalse(createFut.isDone());
    assertFalse(getFut.isDone());
    assertFalse(getAllTablesFut.isDone());
    phaser.arrive();
    assertSame(createFut.join(), getFut.join());
    assertEquals(1, getAllTablesFut.join().size());
}
Also used : Table(org.apache.ignite.table.Table) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Collection(java.util.Collection) Phaser(java.util.concurrent.Phaser) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 23 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class TableManagerTest method testCreateTable.

/**
 * Tests create a table through public API.
 *
 * @throws Exception If failed.
 */
@Test
public void testCreateTable() throws Exception {
    TableDefinition scmTbl = SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_NAME).columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build()).withPrimaryKey("key").build();
    Table table = mockManagersAndCreateTable(scmTbl, tblManagerFut);
    assertNotNull(table);
    assertSame(table, tblManagerFut.join().table(scmTbl.canonicalName()));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 24 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition 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 25 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class TableManagerTest method testDoubledCreateTable.

/**
 * Tries to create a table that already exists.
 *
 * @throws Exception If failed.
 */
@Test
public void testDoubledCreateTable() throws Exception {
    TableDefinition scmTbl = SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_NAME).columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build()).withPrimaryKey("key").build();
    Table table = mockManagersAndCreateTable(scmTbl, tblManagerFut);
    assertNotNull(table);
    assertThrows(RuntimeException.class, () -> tblManagerFut.join().createTable(scmTbl.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(scmTbl, tblCh).changeReplicas(REPLICAS).changePartitions(PARTITIONS)));
    assertSame(table, tblManagerFut.join().table(scmTbl.canonicalName()));
}
Also used : 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) Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Aggregations

TableDefinition (org.apache.ignite.schema.definition.TableDefinition)37 Test (org.junit.jupiter.api.Test)25 Table (org.apache.ignite.table.Table)14 List (java.util.List)11 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)11 ColumnType (org.apache.ignite.schema.definition.ColumnType)11 Disabled (org.junit.jupiter.api.Disabled)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Collection (java.util.Collection)9 TableDefinitionBuilder (org.apache.ignite.schema.definition.builder.TableDefinitionBuilder)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Collections (java.util.Collections)8 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)8 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)8 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)8 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)8 SortedIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema)8 TablesConfiguration (org.apache.ignite.configuration.schemas.table.TablesConfiguration)8 AfterEach (org.junit.jupiter.api.AfterEach)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8