@Test public void testTooManyLevelThenException() throws Exception { for (int i = 1; i <= 100; i++) { instance.addEntry(new JsonLineModel("id" + i, i, JsonHandler.createObjectNode())); } assertThatThrownBy(() -> instance.addEntry(new JsonLineModel("id101", 101, JsonHandler.createObjectNode()))) .isInstanceOf(IllegalStateException.class); }
public void addEntry(JsonLineModel line) throws IOException { if (line.getDistribGroup() == null) { throw new IllegalArgumentException("Null distribution group " + JsonHandler.unprettyPrint(line)); } if (!filesByLevel.containsKey(line.getDistribGroup())) { if (filesByLevel.size() >= MAX_LEVELS) { throw new IllegalStateException("Too many levels " + MAX_LEVELS); } File newLocalFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); filesByLevel.put(line.getDistribGroup(), newLocalFile); writersByLevel.put(line.getDistribGroup(), new JsonLineWriter(new FileOutputStream(newLocalFile))); } JsonLineWriter jsonLineWriter = writersByLevel.get(line.getDistribGroup()); jsonLineWriter.addEntry(line); }
SortedLevelJsonLineWriter implements AutoCloseable { public void addEntry(JsonLineModel line) throws IOException { if (line.getDistribGroup() == null) { throw new IllegalArgumentException("Null distribution group " + JsonHandler.unprettyPrint(line)); } if (!filesByLevel.containsKey(line.getDistribGroup())) { if (filesByLevel.size() >= MAX_LEVELS) { throw new IllegalStateException("Too many levels " + MAX_LEVELS); } File newLocalFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); filesByLevel.put(line.getDistribGroup(), newLocalFile); writersByLevel.put(line.getDistribGroup(), new JsonLineWriter(new FileOutputStream(newLocalFile))); } JsonLineWriter jsonLineWriter = writersByLevel.get(line.getDistribGroup()); jsonLineWriter.addEntry(line); } }
SortedLevelJsonLineWriter implements AutoCloseable { public void addEntry(JsonLineModel line) throws IOException { if (line.getDistribGroup() == null) { throw new IllegalArgumentException("Null distribution group " + JsonHandler.unprettyPrint(line)); } if (!filesByLevel.containsKey(line.getDistribGroup())) { if (filesByLevel.size() >= MAX_LEVELS) { throw new IllegalStateException("Too many levels " + MAX_LEVELS); } File newLocalFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); filesByLevel.put(line.getDistribGroup(), newLocalFile); writersByLevel.put(line.getDistribGroup(), new JsonLineWriter(new FileOutputStream(newLocalFile))); } JsonLineWriter jsonLineWriter = writersByLevel.get(line.getDistribGroup()); jsonLineWriter.addEntry(line); } SortedLevelJsonLineWriter(HandlerIO handler); }
SortedLevelJsonLineWriter implements AutoCloseable { public void addEntry(JsonLineModel line) throws IOException { if (line.getDistribGroup() == null) { throw new IllegalArgumentException("Null distribution group " + JsonHandler.unprettyPrint(line)); } if (!filesByLevel.containsKey(line.getDistribGroup())) { if (filesByLevel.size() >= MAX_LEVELS) { throw new IllegalStateException("Too many levels " + MAX_LEVELS); } File newLocalFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); filesByLevel.put(line.getDistribGroup(), newLocalFile); writersByLevel.put(line.getDistribGroup(), new JsonLineWriter(new FileOutputStream(newLocalFile))); } JsonLineWriter jsonLineWriter = writersByLevel.get(line.getDistribGroup()); jsonLineWriter.addEntry(line); } SortedLevelJsonLineWriter(HandlerIO handler); void addEntry(JsonLineModel line); void exportToWorkspace(String filename, boolean ascending); @Override void close(); }
SortedLevelJsonLineWriter implements AutoCloseable { public void addEntry(JsonLineModel line) throws IOException { if (line.getDistribGroup() == null) { throw new IllegalArgumentException("Null distribution group " + JsonHandler.unprettyPrint(line)); } if (!filesByLevel.containsKey(line.getDistribGroup())) { if (filesByLevel.size() >= MAX_LEVELS) { throw new IllegalStateException("Too many levels " + MAX_LEVELS); } File newLocalFile = handler.getNewLocalFile(GUIDFactory.newGUID().toString()); filesByLevel.put(line.getDistribGroup(), newLocalFile); writersByLevel.put(line.getDistribGroup(), new JsonLineWriter(new FileOutputStream(newLocalFile))); } JsonLineWriter jsonLineWriter = writersByLevel.get(line.getDistribGroup()); jsonLineWriter.addEntry(line); } SortedLevelJsonLineWriter(HandlerIO handler); void addEntry(JsonLineModel line); void exportToWorkspace(String filename, boolean ascending); @Override void close();  }