private void _testPrimitiveSerDes(String topicPrefix) { Object[] payloads = AvroSchemaRegistryClientUtil.generatePrimitivePayloads(); for (Object payload : payloads) { String topic = topicPrefix + ":" + (payload != null ? payload.getClass().getName() : "null"); _testKafkaSerDes(topic, true, payload); _testKafkaSerDes(topic, false, payload); } }
@Test public void testPrimitiveSerDes() { String topicPrefix = TEST_NAME_RULE.getMethodName() + "-" + System.currentTimeMillis(); _testPrimitiveSerDes(topicPrefix); }
@Test public void testAvroRecordsSerDes() throws Exception { String topicPrefix = TEST_NAME_RULE.getMethodName() + "-" + System.currentTimeMillis(); String genericRecordTopic = topicPrefix + "-generic"; Object genericRecordForDevice = AvroSchemaRegistryClientUtil.createGenericRecordForDevice(); _testKafkaSerDes(genericRecordTopic, true, genericRecordForDevice); _testKafkaSerDes(genericRecordTopic, true, genericRecordForDevice); Device specificRecord = AvroSchemaRegistryClientUtil.createSpecificRecord(); String specificRecordTopic = topicPrefix + "-specific"; _testKafkaSerDes(specificRecordTopic, true, specificRecord); _testKafkaSerDes(specificRecordTopic, false, specificRecord); }
@Test public void testIncompatibleSchemas() throws Exception { String topic = TEST_NAME_RULE.getMethodName() + "-" + System.currentTimeMillis(); // send initial message Object initialMsg = AvroSchemaRegistryClientUtil.createGenericRecordForDevice(); _testKafkaSerDes(topic, true, initialMsg); _testKafkaSerDes(topic, false, initialMsg); // send a message with incompatible version of the schema Object incompatMsg = AvroSchemaRegistryClientUtil.createGenericRecordForIncompatDevice(); try { _testKafkaSerDes(topic, true, incompatMsg); Assert.fail("An error should have been received here because of incompatible schemas"); } catch (Exception e) { // should have received an error. } // send a message with compatible version of the schema Object compatMsg = AvroSchemaRegistryClientUtil.createGenericRecordForCompatDevice(); _testKafkaSerDes(topic, true, compatMsg); _testKafkaSerDes(topic, false, compatMsg); }