public S getSchemaByID(String topic, String id) { CachedSchemaTuple cacheKey = new CachedSchemaTuple(topic, id); S schema = cachedById.get(cacheKey); if (schema == null) { synchronized (this) { if (shouldFetchFromSchemaRegistry(id)) { schema = fetchFromSchemaRegistry(topic, id); cachedById.putIfAbsent(new CachedSchemaTuple(topic, id), schema); } else { throw new SchemaNotFoundException(); } } } return schema; }
public static MessageDecoder createMockDecoder30PercentSchemaNotFound() { MessageDecoder mockDecoder = EasyMock.createNiceMock(MessageDecoder.class); EasyMock.expect(mockDecoder.decode(EasyMock.anyObject())).andThrow(new SchemaNotFoundException()).times(3); EasyMock.expect(mockDecoder.decode(EasyMock.anyObject())).andReturn(new CamusWrapper<String>("dummy")).times(7); EasyMock.replay(mockDecoder); return mockDecoder; }
@Test public void testMinInterval() throws InterruptedException { EasyMock.expect(registry.getSchemaByID(EasyMock.anyString(), EasyMock.anyString())).andThrow( new SchemaNotFoundException()); EasyMock.expectLastCall().times(4); EasyMock.replay(registry); props.setProperty(GET_SCHEMA_BY_ID_MAX_RETIRES, String.valueOf(Integer.MAX_VALUE)); props.setProperty(GET_SCHEMA_BY_ID_MIN_INTERVAL_SECONDS, "2"); cachedRegistry = new CachedSchemaRegistry<Schema>(registry, props); for (int i = 0; i < 2; i++) { for (int j = 0; j < 5; j++) { try { cachedRegistry.getSchemaByID("dummyTopic", "dummyID"); } catch (SchemaNotFoundException e) { } try { cachedRegistry.getSchemaByID("dummyTopic", "dummyID2"); } catch (SchemaNotFoundException e) { } } Thread.sleep(2500); } EasyMock.verify(registry); } }
@Test public void testMaxRetries() { EasyMock.expect(registry.getSchemaByID(EasyMock.anyString(), EasyMock.anyString())).andThrow( new SchemaNotFoundException()); EasyMock.expectLastCall().times(20); EasyMock.replay(registry); props.setProperty(GET_SCHEMA_BY_ID_MAX_RETIRES, "10"); props.setProperty(GET_SCHEMA_BY_ID_MIN_INTERVAL_SECONDS, "0"); cachedRegistry = new CachedSchemaRegistry<Schema>(registry, props); for (int i = 0; i < 100; i++) { try { cachedRegistry.getSchemaByID("dummyTopic", "dummyID"); } catch (SchemaNotFoundException e) { } try { cachedRegistry.getSchemaByID("dummyTopic", "dummyID2"); } catch (SchemaNotFoundException e) { } } EasyMock.verify(registry); }
@Override public S getSchemaByID(String topicName, String idStr) { try { S schema = schemasById.get(new MemorySchemaRegistryTuple(topicName, Long.parseLong(idStr))); if (schema == null) { throw new SchemaNotFoundException(); } return schema; } catch (NumberFormatException e) { throw new SchemaNotFoundException("Supplied a non-long id string.", e); } }
@Override public S getSchemaByID(String topicName, String idStr) { try { S schema = schemasById.get(new MemorySchemaRegistryTuple(topicName, Long.parseLong(idStr))); if (schema == null) { throw new SchemaNotFoundException(); } return schema; } catch (NumberFormatException e) { throw new SchemaNotFoundException("Supplied a non-long id string.", e); } }
@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 Schema getSchemaByID(String topic, String id) { Subject subject = client.lookup(topic); if (subject == null) { throw new SchemaNotFoundException("Schema not found for " + topic); } SchemaEntry entry = subject.lookupById(id); if (entry == null) throw new SchemaNotFoundException("Schema not found for " + topic + " " + id); return Schema.parse(entry.getSchema()); }
@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 S getSchemaByID(String topic, String id) { File file = getSchemaPath(topic, id, false); if (!file.exists()) { file = getSchemaPath(topic, id, true); } if (!file.exists()) { throw new SchemaNotFoundException("No matching schema found for topic " + topic + " and id " + id + "."); } return serde.fromBytes(readBytes(file)); }
@Override public S getSchemaByID(String topic, String id) { File file = getSchemaPath(topic, id, false); if (!file.exists()) { file = getSchemaPath(topic, id, true); } if (!file.exists()) { throw new SchemaNotFoundException("No matching schema found for topic " + topic + " and id " + id + "."); } return serde.fromBytes(readBytes(file)); }
public S getSchemaByID(String topic, String id) { CachedSchemaTuple cacheKey = new CachedSchemaTuple(topic, id); S schema = cachedById.get(cacheKey); if (schema == null) { synchronized (this) { if (shouldFetchFromSchemaRegistry(id)) { schema = fetchFromSchemaRegistry(topic, id); cachedById.putIfAbsent(new CachedSchemaTuple(topic, id), schema); } else { throw new SchemaNotFoundException(); } } } return schema; }
@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())); } }