@Test public void shouldList() throws IOException { final Iterator<DataSetMetadata> emptyList = repository.list().iterator(); assertFalse(emptyList.hasNext()); int expected = 26; for (int i = 1; i <= expected; i++) { repository.save(getMetadata(String.valueOf(i))); } final Iterator<DataSetMetadata> actual = repository.list().iterator(); final AtomicInteger count = new AtomicInteger(0); actual.forEachRemaining(dataSetMetadata -> { assertTrue(Integer.valueOf(dataSetMetadata.getId()) <= expected); count.addAndGet(1); }); assertEquals(expected, count.intValue()); }
@Override public void save(DataSetMetadata metadata) { String id = metadata.getId(); ReentrantReadWriteLock lock = locks.getLock(id); final File file = getFile(id); lock.writeLock().lock(); try (GZIPOutputStream output = new GZIPOutputStream(new FileOutputStream(file))) { mapper.writer().writeValue(output, metadata); } catch (IOException e) { LOG.error("Error saving {}", metadata, e); throw new TDPException(DataSetErrorCodes.UNABLE_TO_STORE_DATASET_METADATA, e, ExceptionContext.build().put("id", metadata.getId())); } finally { lock.writeLock().unlock(); } }
FileSystemDataSetMetadataRepository extends ObjectDataSetMetadataRepository { @Override public void save(DataSetMetadata metadata) { String id = metadata.getId(); ReentrantReadWriteLock lock = locks.getLock(id); final File file = getFile(id); lock.writeLock().lock(); try (GZIPOutputStream output = new GZIPOutputStream(new FileOutputStream(file))) { mapper.writer().writeValue(output, metadata); } catch (IOException e) { LOG.error("Error saving {}", metadata, e); throw new TDPException(DataSetErrorCodes.UNABLE_TO_STORE_DATASET_METADATA, e, ExceptionContext.build().put("id", metadata.getId())); } finally { lock.writeLock().unlock(); } } }
FileSystemDataSetMetadataRepository extends ObjectDataSetMetadataRepository { @Override public void save(DataSetMetadata metadata) { String id = metadata.getId(); ReentrantReadWriteLock lock = locks.getLock(id); final File file = getFile(id); lock.writeLock().lock(); try (GZIPOutputStream output = new GZIPOutputStream(new FileOutputStream(file))) { mapper.writer().writeValue(output, metadata); } catch (IOException e) { LOG.error("Error saving {}", metadata, e); throw new TDPException(DataSetErrorCodes.UNABLE_TO_STORE_DATASET_METADATA, e, ExceptionContext.build().put("id", metadata.getId())); } finally { lock.writeLock().unlock(); } }  }
FileSystemDataSetMetadataRepository extends ObjectDataSetMetadataRepository { @Override public void save(DataSetMetadata metadata) { String id = metadata.getId(); ReentrantReadWriteLock lock = locks.getLock(id); final File file = getFile(id); lock.writeLock().lock(); try (GZIPOutputStream output = new GZIPOutputStream(new FileOutputStream(file))) { mapper.writer().writeValue(output, metadata); } catch (IOException e) { LOG.error("Error saving {}", metadata, e); throw new TDPException(DataSetErrorCodes.UNABLE_TO_STORE_DATASET_METADATA, e, ExceptionContext.build().put("id", metadata.getId())); } finally { lock.writeLock().unlock(); } }  @Override void save(DataSetMetadata metadata); @Override DataSetMetadata get(String id); @Override void remove(String id); @Override Stream<DataSetMetadata> source(); }
FileSystemDataSetMetadataRepository extends ObjectDataSetMetadataRepository { @Override public void save(DataSetMetadata metadata) { String id = metadata.getId(); ReentrantReadWriteLock lock = locks.getLock(id); final File file = getFile(id); lock.writeLock().lock(); try (GZIPOutputStream output = new GZIPOutputStream(new FileOutputStream(file))) { mapper.writer().writeValue(output, metadata); } catch (IOException e) { LOG.error("Error saving {}", metadata, e); throw new TDPException(DataSetErrorCodes.UNABLE_TO_STORE_DATASET_METADATA, e, ExceptionContext.build().put("id", metadata.getId())); } finally { lock.writeLock().unlock(); } }  @Override void save(DataSetMetadata metadata); @Override DataSetMetadata get(String id); @Override void remove(String id); @Override Stream<DataSetMetadata> source();  }