Search in sources :

Example 11 with SchemaRegistrySerializer

use of io.confluent.kafka.schemaregistry.storage.serialization.SchemaRegistrySerializer in project schema-registry by confluentinc.

the class KafkaStoreTest method testKafkaStoreMessageHandlerSameIdDifferentDeletedSchema.

@Test
public void testKafkaStoreMessageHandlerSameIdDifferentDeletedSchema() throws Exception {
    Properties props = new Properties();
    props.put(SchemaRegistryConfig.KAFKASTORE_BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
    props.put(SchemaRegistryConfig.KAFKASTORE_TOPIC_CONFIG, ClusterTestHarness.KAFKASTORE_TOPIC);
    SchemaRegistryConfig config = new SchemaRegistryConfig(props);
    KafkaSchemaRegistry schemaRegistry = new KafkaSchemaRegistry(config, new SchemaRegistrySerializer());
    KafkaStore<SchemaRegistryKey, SchemaRegistryValue> kafkaStore = schemaRegistry.kafkaStore;
    kafkaStore.init();
    int id = 100;
    kafkaStore.put(new SchemaKey("subject", 1), new SchemaValue("subject", 1, id, "schemaString", false));
    kafkaStore.put(new SchemaKey("subject", 1), new SchemaValue("subject", 1, id, "schemaString", true));
    kafkaStore.put(new SchemaKey("subject2", 1), new SchemaValue("subject2", 1, id, "schemaString2", false));
    int size = 0;
    try (CloseableIterator<SchemaRegistryKey> keys = kafkaStore.getAllKeys()) {
        for (Iterator<SchemaRegistryKey> iter = keys; iter.hasNext(); ) {
            size++;
            iter.next();
        }
    }
    assertEquals(1, size);
}
Also used : SchemaRegistryConfig(io.confluent.kafka.schemaregistry.rest.SchemaRegistryConfig) SchemaRegistrySerializer(io.confluent.kafka.schemaregistry.storage.serialization.SchemaRegistrySerializer) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with SchemaRegistrySerializer

use of io.confluent.kafka.schemaregistry.storage.serialization.SchemaRegistrySerializer in project schema-registry by confluentinc.

the class SchemaRegistryKeysTest method testStoreKeyOrder.

private void testStoreKeyOrder(SchemaRegistryKey[] orderedKeys) throws StoreInitializationException {
    int numKeys = orderedKeys.length;
    InMemoryCache<SchemaRegistryKey, SchemaRegistryValue> store = new InMemoryCache<>(new SchemaRegistrySerializer());
    store.init();
    while (--numKeys >= 0) {
        try {
            store.put(orderedKeys[numKeys], toValue(orderedKeys[numKeys]));
        } catch (StoreException e) {
            fail("Error writing key " + orderedKeys[numKeys].toString() + " to the in memory store");
        }
    }
    // test key order
    try (CloseableIterator<SchemaRegistryKey> keys = store.getAllKeys()) {
        SchemaRegistryKey[] retrievedKeyOrder = new SchemaRegistryKey[orderedKeys.length];
        int keyIndex = 0;
        while (keys.hasNext()) {
            retrievedKeyOrder[keyIndex++] = keys.next();
        }
        assertArrayEquals(orderedKeys, retrievedKeyOrder);
    } catch (StoreException e) {
        fail();
    }
}
Also used : SchemaRegistrySerializer(io.confluent.kafka.schemaregistry.storage.serialization.SchemaRegistrySerializer) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Aggregations

SchemaRegistrySerializer (io.confluent.kafka.schemaregistry.storage.serialization.SchemaRegistrySerializer)12 SchemaRegistryConfig (io.confluent.kafka.schemaregistry.rest.SchemaRegistryConfig)10 Properties (java.util.Properties)10 Test (org.junit.Test)10 IncrementalIdGenerator (io.confluent.kafka.schemaregistry.id.IncrementalIdGenerator)2 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)1 KafkaSchemaRegistry (io.confluent.kafka.schemaregistry.storage.KafkaSchemaRegistry)1 StoreException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)1