use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KvMarshallerTest method checkBasicType.
/**
* Generate random key-value pair of given types and check serialization and deserialization works fine.
*
* @param factory KvMarshaller factory.
* @param keyType Key type.
* @param valType Value type.
* @throws MarshallerException If (de)serialization failed.
*/
private void checkBasicType(MarshallerFactory factory, NativeType keyType, NativeType valType) throws MarshallerException {
final Object key = generateRandomValue(keyType);
final Object val = generateRandomValue(valType);
Column[] keyCols = new Column[] { new Column("key", keyType, false) };
Column[] valCols = new Column[] { new Column("val", valType, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
KvMarshaller<Object, Object> marshaller = factory.create(schema, Mapper.of((Class<Object>) key.getClass(), "\"key\""), Mapper.of((Class<Object>) val.getClass(), "\"val\""));
BinaryRow row = marshaller.marshal(key, val);
Object key1 = marshaller.unmarshalKey(new Row(schema, row));
Object val1 = marshaller.unmarshalValue(new Row(schema, row));
assertTrue(key.getClass().isInstance(key1));
assertTrue(val.getClass().isInstance(val1));
compareObjects(keyType, key, key);
compareObjects(valType, val, val1);
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testSchemaCacheCleanup.
/**
* Check schema cache cleanup.
*/
@Test
public void testSchemaCacheCleanup() {
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) });
schemaV2.columnMapping(createMapper(schemaV2).add(schemaV2.column("valStringCol")));
final SchemaDescriptor schemaV3 = new SchemaDescriptor(3, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valStringCol", STRING, true) });
schemaV3.columnMapping(createMapper(schemaV3).add(schemaV3.column("valStringCol").schemaIndex(), schemaV2.column("valStringCol").schemaIndex()));
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) });
schemaV4.columnMapping(createMapper(schemaV4).add(schemaV4.column("valBytesCol")));
final SchemaRegistryImpl reg = new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION);
final Map<Long, ColumnMapper> cache = reg.mappingCache();
reg.onSchemaRegistered(schemaV1);
reg.onSchemaRegistered(schemaV2);
reg.onSchemaRegistered(schemaV3);
reg.onSchemaRegistered(schemaV4);
assertEquals(0, cache.size());
reg.resolveMapping(schemaV4, schemaV1);
reg.resolveMapping(schemaV3, schemaV1);
reg.resolveMapping(schemaV4, schemaV2);
assertEquals(3, cache.size());
reg.onSchemaDropped(schemaV1.version());
assertEquals(1, cache.size());
reg.onSchemaDropped(schemaV2.version());
assertEquals(0, cache.size());
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testSchemaRegistration.
/**
* Check initial schema registration.
*/
@Test
public void testSchemaRegistration() {
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 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());
assertNull(reg.schema());
// Register schema with very first version.
reg.onSchemaRegistered(schemaV1);
assertEquals(1, reg.lastSchemaVersion());
assertSameSchema(schemaV1, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
// Register schema with next version.
reg.onSchemaRegistered(schemaV2);
assertEquals(2, reg.lastSchemaVersion());
assertSameSchema(schemaV2, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
// Try to register schema with version of 4.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV4));
assertEquals(2, reg.lastSchemaVersion());
assertSameSchema(schemaV2, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
assertThrows(SchemaRegistryException.class, () -> reg.schema(4));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testInitialSchemaWithFullHistory.
/**
* Check schema registration with full history.
*/
@Test
public void testInitialSchemaWithFullHistory() {
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) });
Map<Integer, SchemaDescriptor> history = schemaHistory(schemaV1, schemaV2);
final SchemaRegistryImpl reg = new SchemaRegistryImpl(2, history::get, () -> INITIAL_SCHEMA_VERSION);
assertEquals(2, reg.lastSchemaVersion());
assertSameSchema(schemaV2, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
// Register schema with duplicate version.
assertThrows(SchemaRegistrationConflictException.class, () -> reg.onSchemaRegistered(schemaV1));
assertEquals(2, reg.lastSchemaVersion());
assertSameSchema(schemaV2, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
// Register schema with out-of-order version.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV4));
assertEquals(2, reg.lastSchemaVersion());
assertSameSchema(schemaV2, reg.schema());
assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
// Register schema with next version.
reg.onSchemaRegistered(schemaV3);
assertEquals(3, reg.lastSchemaVersion());
assertSameSchema(schemaV3, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
assertSameSchema(schemaV3, reg.schema(3));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testDuplicateSchemaRegistration.
/**
* Check schema registration.
*/
@Test
public void testDuplicateSchemaRegistration() {
final SchemaDescriptor schemaV1 = new SchemaDescriptor(1, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
final SchemaDescriptor wrongSchema = new SchemaDescriptor(1, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, 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 SchemaRegistryImpl reg = new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION);
assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
// Register schema with very first version.
reg.onSchemaRegistered(schemaV1);
assertEquals(1, reg.lastSchemaVersion());
assertSameSchema(schemaV1, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
// Try to register same schema once again.
assertThrows(SchemaRegistrationConflictException.class, () -> reg.onSchemaRegistered(schemaV1));
assertEquals(1, reg.lastSchemaVersion());
assertSameSchema(schemaV1, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
// Try to register another schema with same version and check nothing was registered.
assertThrows(SchemaRegistrationConflictException.class, () -> reg.onSchemaRegistered(wrongSchema));
assertEquals(1, reg.lastSchemaVersion());
assertEquals(1, reg.schema().version());
assertSameSchema(schemaV1, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
// Register schema with next version.
reg.onSchemaRegistered(schemaV2);
assertEquals(2, reg.lastSchemaVersion());
assertSameSchema(schemaV2, reg.schema());
assertSameSchema(schemaV1, reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
}
Aggregations