@Override public synchronized SchemaEntry latest() { isValid(); return latest; }
private static void appendLineToFile(File file, final String line) { writeToFile(file, new WriteOp() { @Override protected void write(Writer writer) throws IOException { writer.append(line).append('\n'); } }, true); }
@Override protected void registerSubjectInBackend(final String subjectName, final SubjectConfig config) { final File subjectDir = new File(rootDir, subjectName); if (subjectDir.exists()) { throw new RuntimeException( "Cannot create a FileSubject, directory already exists: " + subjectDir.getAbsolutePath()); } if (!subjectDir.mkdir()) { throw new RuntimeException("Cannot create a FileSubject dir: " + subjectDir.getAbsolutePath()); } createNewFileInDir(subjectDir, SCHEMA_IDS); File subjectProperties = createNewFileInDir(subjectDir, SUBJECT_PROPERTIES); Properties props = new Properties(); props.putAll(RepositoryUtil.safeConfig(config).asMap()); writePropertyFile(subjectProperties, props); }
@Test(expected = RuntimeException.class) public void testInvalidDir() throws IOException { String badPath = TEST_PATH + "/bad"; new File(TEST_PATH).mkdirs(); new File(badPath).createNewFile(); LocalFileSystemRepository r = newRepo(badPath); r.close(); }
loadSubjects(rootDir, subjectCache);
private LocalFileSystemRepository newRepo(String path) { return new LocalFileSystemRepository(path, new ValidatorFactory.Builder().build()); }
@Override protected void registerSubjectInBackend(final String subjectName, final SubjectConfig config) { final File subjectDir = new File(rootDir, subjectName); if (subjectDir.exists()) { throw new RuntimeException( "Cannot create a FileSubject, directory already exists: " + subjectDir.getAbsolutePath()); } if (!subjectDir.mkdir()) { throw new RuntimeException("Cannot create a FileSubject dir: " + subjectDir.getAbsolutePath()); } createNewFileInDir(subjectDir, SCHEMA_IDS); File subjectProperties = createNewFileInDir(subjectDir, SUBJECT_PROPERTIES); Properties props = new Properties(); props.putAll(RepositoryUtil.safeConfig(config).asMap()); writePropertyFile(subjectProperties, props); }
@After public void cleanUp() throws Exception { LoggerFactory.getLogger(getClass()).debug("Closing"); getRepo().close(); // see https://github.com/schema-repo/schema-repo/issues/12 if (System.getProperty("os.name", "").toLowerCase().contains("windows")) { System.gc(); Thread.sleep(100); } // Clean up the repo's content rmDir(new File(REPO_PATH)); }
loadSubjects(rootDir, subjectCache);
@Override public synchronized SchemaEntry latest() { isValid(); return latest; }
private static void writePropertyFile(File file, final Properties prop) { writeToFile(file, new WriteOp() { @Override protected void write(Writer writer) throws IOException { prop.store(writer, "Schema Repository Subject Properties"); } }, false); }
@Test public void testPathHandling() throws SchemaValidationException { String paths[] = new String[] { "data", "data/", "/tmp/file_repo", "/tmp/file_repo/", "/tmp/file_repo/" }; for (String path : paths) { LocalFileSystemRepository r = newRepo(TEST_PATH + path); try { File expected = new File(TEST_PATH, path); assertTrue("Expected directory not created: " + expected.getAbsolutePath() + " for path: " + path, expected.exists()); } finally { r.close(); // should be ok to call close twice r.close(); } } // verify idempotent newRepo(TEST_PATH + "/tmp/repo").close(); newRepo(TEST_PATH + "/tmp/repo").close(); }
@Override public synchronized Iterable<SchemaEntry> allEntries() { isValid(); List<SchemaEntry> entries = new ArrayList<SchemaEntry>(); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schema = readSchemaForId(idStr); entries.add(new SchemaEntry(idStr, schema)); } Collections.reverse(entries); return entries; }
private static void writePropertyFile(File file, final Properties prop) { writeToFile(file, new WriteOp() { @Override protected void write(Writer writer) throws IOException { prop.store(writer, "Schema Repository Subject Properties"); } }, false); }
@Override public synchronized Iterable<SchemaEntry> allEntries() { isValid(); List<SchemaEntry> entries = new ArrayList<SchemaEntry>(); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schema = readSchemaForId(idStr); entries.add(new SchemaEntry(idStr, schema)); } Collections.reverse(entries); return entries; }
private static void appendLineToFile(File file, final String line) { writeToFile(file, new WriteOp() { @Override protected void write(Writer writer) throws IOException { writer.append(line).append('\n'); } }, true); }
@Override public synchronized SchemaEntry lookupById(String id) { isValid(); String schema = readSchemaForIdOrNull(id); if (schema != null) { return new SchemaEntry(id, schema); } return null; }
@Override public synchronized SchemaEntry lookupById(String id) { isValid(); String schema = readSchemaForIdOrNull(id); if (schema != null) { return new SchemaEntry(id, schema); } return null; }
@Override public synchronized SchemaEntry registerIfLatest(String schema, SchemaEntry latest) throws SchemaValidationException { isValid(); if (latest == this.latest // both null || (latest != null && latest.equals(this.latest))) { return register(schema); } else { return null; } }