@Override public SchemaDetails<S> getLatestSchemaByTopic(String topicName) { File topicDir = getTopicPath(topicName); if (topicDir.exists()) { for (File file : topicDir.listFiles()) { if (file.getName().endsWith(".latest")) { String id = file.getName().replace(".schema.latest", ""); return new SchemaDetails<S>(topicName, id, serde.fromBytes(readBytes(file))); } } } throw new SchemaNotFoundException("Unable to find a latest schema for topic " + topicName + "."); }
@Override public SchemaDetails<S> getLatestSchemaByTopic(String topicName) { MemorySchemaRegistryTuple tuple = latest.get(topicName); if (tuple == null) { throw new SchemaNotFoundException(); } S schema = schemasById.get(tuple); if (schema == null) { throw new SchemaNotFoundException(); } return new SchemaDetails<S>(topicName, Long.toString(tuple.getId()), schema); }
@Override public SchemaDetails<S> getLatestSchemaByTopic(String topicName) { MemorySchemaRegistryTuple tuple = latest.get(topicName); if (tuple == null) { throw new SchemaNotFoundException(); } S schema = schemasById.get(tuple); if (schema == null) { throw new SchemaNotFoundException(); } return new SchemaDetails<S>(topicName, Long.toString(tuple.getId()), schema); }
@Override public SchemaDetails<S> getLatestSchemaByTopic(String topicName) { File topicDir = getTopicPath(topicName); if (topicDir.exists()) { for (File file : topicDir.listFiles()) { if (file.getName().endsWith(".latest")) { String id = file.getName().replace(".schema.latest", ""); return new SchemaDetails<S>(topicName, id, serde.fromBytes(readBytes(file))); } } } throw new SchemaNotFoundException("Unable to find a latest schema for topic " + topicName + "."); }
@Override public SchemaDetails<Schema> getLatestSchemaByTopic(String topicName) { Subject subject = client.lookup(topicName); if (subject == null) { throw new SchemaNotFoundException("Schema not found for " + topicName); } SchemaEntry entry = subject.latest(); if (entry == null) throw new SchemaNotFoundException("Schema not found for " + topicName); return new SchemaDetails<Schema>(topicName, entry.getId(), Schema.parse(entry.getSchema())); } }
assertEquals(new SchemaDetails("test", id, getSchema1()), registry.getLatestSchemaByTopic("test")); assertEquals(new SchemaDetails("test", secondId, getSchema2()), registry.getLatestSchemaByTopic("test")); assertEquals(new SchemaDetails("test", secondId, getSchema2()), registry.getLatestSchemaByTopic("test"));