FileSystemSchemaRegistryService extends VersionedSchemaSetBackedRegistryService { public static FileSystemSchemaRegistryService build(Config config) throws InvalidConfigException { return build(config.build()); } private  FileSystemSchemaRegistryService(StaticConfig config); static FileSystemSchemaRegistryService build(Config config); static FileSystemSchemaRegistryService build(StaticConfig config); boolean startSchemasRefreshThread(); void stopSchemasRefreshThread(); @Override void registerSchema(VersionedSchema schema); static final String MODULE; static final Logger LOG; }
@Test public void testFallbackToResource() throws Exception { FileSystemSchemaRegistryService.Config configBuilder = new FileSystemSchemaRegistryService.Config(); configBuilder.setFallbackToResources(true); configBuilder.setSchemaDir("/no/such/dir"); FileSystemSchemaRegistryService.StaticConfig config = configBuilder.build(); FileSystemSchemaRegistryService service = FileSystemSchemaRegistryService.build(config); Map<Short,String > fakeSchemas = service.fetchAllSchemaVersionsBySourceName("com.linkedin.events.example.fake.FakeSchema"); Assert.assertNotNull(fakeSchemas); Assert.assertTrue(2 <= fakeSchemas.size()); String personSchema = service.fetchLatestSchemaBySourceName("com.linkedin.events.example.person.Person"); Assert.assertNotNull(personSchema); }
@Test(expectedExceptions=InvalidConfigException.class) public void testErrorOnMissingSchemasDir() throws InvalidConfigException { final String dirName = "/lets/hope/no/one/creates/this/dir"; Assert.assertFalse((new File(dirName)).exists()); FileSystemSchemaRegistryService.Config cfgBuilder = new FileSystemSchemaRegistryService.Config(); cfgBuilder.setFallbackToResources(false); cfgBuilder.setSchemaDir(dirName); FileSystemSchemaRegistryService.build(cfgBuilder); }
@Test(expectedExceptions=DatabusRuntimeException.class) public void testErrorOnEmptySchemasDir() throws IOException, InvalidConfigException { File tempDir = FileUtils.createTempDir("testErrorOnEmptySchemasDir"); Assert.assertTrue(tempDir.exists()); FileSystemSchemaRegistryService.Config cfgBuilder = new FileSystemSchemaRegistryService.Config(); cfgBuilder.setFallbackToResources(false); cfgBuilder.setSchemaDir(tempDir.getAbsolutePath()); FileSystemSchemaRegistryService.build(cfgBuilder); }