Search in sources :

Example 91 with SchemaDescriptor

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);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Example 92 with SchemaDescriptor

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());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Test(org.junit.jupiter.api.Test)

Example 93 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Example 94 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Example 95 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)105 Column (org.apache.ignite.internal.schema.Column)78 Test (org.junit.jupiter.api.Test)48 Tuple (org.apache.ignite.table.Tuple)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 Row (org.apache.ignite.internal.schema.row.Row)32 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)22 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 TableImpl (org.apache.ignite.internal.table.TableImpl)7 Random (java.util.Random)6 Map (java.util.Map)5