package com.cloudera.data.hdfs;

import java.io.File;
import java.io.IOException;

import org.apache.avro.Schema;
import org.apache.avro.Schema.Type;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.common.io.Files;

public class TestHDFSDatasetWriter {

  private File testDirectory;
  private FileSystem fileSystem;

  @Before
  public void setUp() throws IOException {
    testDirectory = Files.createTempDir();

    Configuration conf = new Configuration();

    conf.set("fs.default.name", "file:///");
    fileSystem = FileSystem.get(conf);
  }

  @After
  public void tearDown() throws IOException {
    fileSystem.delete(new Path(testDirectory.getAbsolutePath()), true);
  }

  @Test
  public void testWrite() throws IOException {
    HDFSDatasetWriter<String> writer = new HDFSDatasetWriter<String>(
        fileSystem, new Path(testDirectory.getAbsolutePath(), "write-1.avro"),
        Schema.create(Type.STRING));

    writer.open();

    for (int i = 0; i < 10; i++) {
      writer.write("entry " + i);
    }

    writer.close();
  }

}

@@ -1126,16 +1126,17 @@
 ; i %3C 10
+0
 ; i++) %7B
@@ -1169,16 +1169,74 @@
  %22 + i);
+%0A%0A      if (i %25 10 == 0) %7B%0A        writer.flush();%0A      %7D
 %0A    %7D%0A%0A

Write 100 records and flush every 10 during HDFSDatasetWriter write test.