CsvParameterEntrySerializer implements ParameterEntrySerializer { @Override public void serialize(SerializationConfig config, Writer writer, Parameter parameter, ParameterEntryBatchLoader parameterEntryLoader) throws ParamSerializationException { CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreferenceBuilder.csvPreference(config)); try { long startTime = System.currentTimeMillis(); logger.debug("started parameter entries serialization at {}", startTime); csvWriter.write(extractHeader(parameter)); int counter = 0; while (parameterEntryLoader.hasMore()) { for (ParameterEntry entry : parameterEntryLoader.nextBatch(PARAMETER_ENTRY_BATCH_SIZE)) { csvWriter.write(entry.getLevels()); counter++; csvWriter.flush(); } } csvWriter.flush(); long endTime = System.currentTimeMillis(); logger.debug("serializing {} parameter entries took {}", counter, endTime - startTime); } catch (IOException exception) { throw new EntriesCSVSerializationException(exception); } catch (ParamBatchLoadingException batchException) { throw new EntriesCSVSerializationException(batchException); } finally { StreamCloser.closeStream(writer); } }  @Override void serialize(SerializationConfig config, Writer writer, Parameter parameter, ParameterEntryBatchLoader parameterEntryLoader);  }
@Test public void shouldWriteParameterEntryHeaderUsingLevelNames() throws Exception { Level[] levels = new Level[]{ level().withName("one").build(), level().withName("two").build() }; Parameter parameter = parameter().withLevels(levels).build(); StringWriter writer = new StringWriter(); serializer.serialize(config, writer, parameter, entryBatchLoader); assertThat(writer.toString()).containsOnlyOnce("one;two"); }
@Test public void shouldSerializeParameterEntriesWithHeader() throws Exception { Level[] levels = new Level[]{ level().withName("one").build(), level().withName("two").build() }; Parameter parameter = parameter().withLevels(levels).build(); ParameterEntry[] entries = new ParameterEntry[]{ parameterEntry().withLevels("entry_one", "entry_one").build(), parameterEntry().withLevels("entry_two", "entry_two").build() }; when(entryBatchLoader.hasMore()).thenAnswer(new EntryBatchLoaderHasMoreAnswer()); when(entryBatchLoader.nextBatch(anyInt())).thenReturn(Arrays.asList(entries)); StringWriter writer = new StringWriter(); serializer.serialize(config, writer, parameter, entryBatchLoader); assertThat(writer.toString()).containsOnlyOnce("one;two") .containsOnlyOnce("entry_one;entry_one").containsOnlyOnce("entry_two;entry_two"); }