use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method testComplexPrimaryKey.
/**
* Convert table with complex primary key and check it.
*/
@Test
public void testComplexPrimaryKey() {
TableDefinitionBuilder bldr = getBuilder(false, false);
TableDefinition tblSchm = bldr.withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT8", "ID").build()).build();
SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
assertEquals(2, tblDscr.keyColumns().length());
assertEquals(2, tblDscr.colocationColumns().length);
assertEquals(columns - 2, tblDscr.valueColumns().length());
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method testComplexPrimaryKeyWithAffinity.
/**
* Convert table with complex primary key with affinity column configured and check it.
*/
@Test
public void testComplexPrimaryKeyWithAffinity() {
TableDefinitionBuilder bldr = getBuilder(false, false);
TableDefinition tblSchm = bldr.withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT8", "ID").withColocationColumns("INT8").build()).build();
SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
assertEquals(2, tblDscr.keyColumns().length());
assertEquals(1, tblDscr.colocationColumns().length);
assertEquals(columns - 2, tblDscr.valueColumns().length());
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testWrongSchemaVersionRegistration.
/**
* Check registration of schema with wrong versions.
*/
@Test
public void testWrongSchemaVersionRegistration() {
final SchemaDescriptor schemaV0 = new SchemaDescriptor(INITIAL_SCHEMA_VERSION, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
final SchemaDescriptor schemaV1 = new SchemaDescriptor(0, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
final SchemaDescriptor schemaV2 = new SchemaDescriptor(2, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
final SchemaRegistryImpl reg = new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION);
assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
assertNull(reg.schema());
// Try to register schema with initial version.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV0));
assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
assertNull(reg.schema());
assertThrows(SchemaRegistryException.class, () -> reg.schema(INITIAL_SCHEMA_VERSION));
// Try to register schema with version of 0-zero.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV1));
assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
assertThrows(SchemaRegistryException.class, () -> reg.schema(INITIAL_SCHEMA_VERSION));
assertThrows(SchemaRegistryException.class, () -> reg.schema(0));
// Try to register schema with version of 2.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV2));
assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
assertThrows(SchemaRegistryException.class, () -> reg.schema(INITIAL_SCHEMA_VERSION));
assertThrows(SchemaRegistryException.class, () -> reg.schema(0));
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testSchemaCleanup.
/**
* Check schema cleanup.
*/
@Test
public void testSchemaCleanup() {
final SchemaDescriptor schemaV1 = new SchemaDescriptor(1, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
final SchemaDescriptor schemaV2 = new SchemaDescriptor(2, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV3 = new SchemaDescriptor(3, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV4 = new SchemaDescriptor(4, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, true) });
final SchemaRegistryImpl reg = new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION);
assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
// Fail to cleanup initial schema
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(INITIAL_SCHEMA_VERSION));
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(0));
// Register schema with very first version.
reg.onSchemaRegistered(schemaV1);
assertEquals(1, reg.lastSchemaVersion());
assertNotNull(reg.schema());
assertNotNull(reg.schema(1));
// Try to remove latest schema.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(1));
assertEquals(1, reg.lastSchemaVersion());
assertNotNull(reg.schema());
assertNotNull(reg.schema(1));
// Register new schema with next version.
reg.onSchemaRegistered(schemaV2);
reg.onSchemaRegistered(schemaV3);
assertEquals(3, reg.lastSchemaVersion());
assertNotNull(reg.schema(1));
assertNotNull(reg.schema(2));
assertNotNull(reg.schema(3));
// Remove outdated schema 1.
reg.onSchemaDropped(1);
assertEquals(3, reg.lastSchemaVersion());
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertNotNull(reg.schema(2));
assertNotNull(reg.schema(3));
// Remove non-existed schemas.
reg.onSchemaDropped(1);
assertEquals(3, reg.lastSchemaVersion());
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertNotNull(reg.schema(2));
assertNotNull(reg.schema(3));
// Register new schema with next version.
reg.onSchemaRegistered(schemaV4);
assertEquals(4, reg.lastSchemaVersion());
assertNotNull(reg.schema(2));
assertNotNull(reg.schema(3));
assertNotNull(reg.schema(4));
// Remove non-existed schemas.
reg.onSchemaDropped(1);
assertEquals(4, reg.lastSchemaVersion());
assertSameSchema(schemaV4, reg.schema());
assertSameSchema(schemaV2, reg.schema(2));
assertSameSchema(schemaV3, reg.schema(3));
assertSameSchema(schemaV4, reg.schema(4));
// Out of order remove.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(3));
// Correct removal order.
reg.onSchemaDropped(2);
reg.onSchemaDropped(3);
assertEquals(4, reg.lastSchemaVersion());
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
assertSameSchema(schemaV4, reg.schema());
assertSameSchema(schemaV4, reg.schema(4));
// Try to remove latest schema.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(4));
assertEquals(4, reg.lastSchemaVersion());
assertSameSchema(schemaV4, reg.schema(4));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testSchemaWithHistoryCleanup.
/**
* Check schema cleanup.
*/
@Test
public void testSchemaWithHistoryCleanup() {
final SchemaDescriptor schemaV2 = new SchemaDescriptor(2, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV3 = new SchemaDescriptor(3, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV4 = new SchemaDescriptor(4, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, true) });
Map<Integer, SchemaDescriptor> history = schemaHistory(schemaV2, schemaV3, schemaV4);
final SchemaRegistryImpl reg = new SchemaRegistryImpl(4, history::get, () -> INITIAL_SCHEMA_VERSION);
assertEquals(4, reg.lastSchemaVersion());
assertSameSchema(schemaV4, reg.schema());
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
assertSameSchema(schemaV3, reg.schema(3));
assertSameSchema(schemaV4, reg.schema(4));
history.remove(1);
reg.onSchemaDropped(1);
assertEquals(4, reg.lastSchemaVersion());
assertNotNull(reg.schema(2));
assertNotNull(reg.schema(3));
assertNotNull(reg.schema(4));
history.remove(2);
history.remove(3);
reg.onSchemaDropped(2);
reg.onSchemaDropped(3);
assertEquals(4, reg.lastSchemaVersion());
assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
assertNotNull(reg.schema(4));
}
Aggregations