@Test public void testWriteWithDelete() throws Exception { writer.open(executionContext); writer.write(Collections.singletonList("test1")); writer.close(); assertEquals("test1", readLine()); closeReader(); writer.setShouldDeleteIfExists(true); writer.open(executionContext); writer.write(Collections.singletonList("test2")); assertEquals("test2", readLine()); }
@Test public void testWriteWithAppend() throws Exception { writer.setAppendAllowed(true); writer.open(executionContext); writer.write(Collections.singletonList("test1")); writer.close(); assertEquals("test1", readLine()); closeReader(); writer.open(executionContext); writer.write(Collections.singletonList("test2")); assertEquals("test1", readLine()); assertEquals("test2", readLine()); }
@Test public void testWriteWithAppendRestartOnSecondChunk() throws Exception { // This should be overridden via the writer#setAppendAllowed(true) writer.setShouldDeleteIfExists(true); writer.setAppendAllowed(true); writer.open(executionContext); writer.write(Collections.singletonList("test1")); writer.close(); assertEquals("test1", readLine()); closeReader(); writer.open(executionContext); writer.write(Collections.singletonList(TEST_STRING)); writer.update(executionContext); writer.write(Collections.singletonList(TEST_STRING)); writer.close(); assertEquals("test1", readLine()); assertEquals(TEST_STRING, readLine()); assertEquals(TEST_STRING, readLine()); assertEquals(null, readLine()); writer.open(executionContext); writer.write(Collections.singletonList(TEST_STRING)); writer.close(); closeReader(); assertEquals("test1", readLine()); assertEquals(TEST_STRING, readLine()); assertEquals(TEST_STRING, readLine()); assertEquals(null, readLine()); }
writer.write(Collections.singletonList(TEST_STRING)); writer.close(); closeReader(); lineFromFile = readLine(); assertEquals("a", lineFromFile);
@Test public void testWriteWithAppendAfterHeaders() throws Exception { writer.setHeaderCallback(new FlatFileHeaderCallback() { @Override public void writeHeader(Writer writer) throws IOException { writer.write("a\nb"); } }); writer.setAppendAllowed(true); writer.open(executionContext); writer.write(Collections.singletonList("test1")); writer.close(); assertEquals("a", readLine()); assertEquals("b", readLine()); assertEquals("test1", readLine()); closeReader(); writer.open(executionContext); writer.write(Collections.singletonList("test2")); assertEquals("a", readLine()); assertEquals("b", readLine()); assertEquals("test1", readLine()); assertEquals("test2", readLine()); }