test_class.file: smart-hadoop-support/smart-hadoop/src/test/java/org/smartdata/hdfs/action/TestWriteFileAction.java
test_class.identifier: TestWriteFileAction
test_class.superclass: extends MiniClusterHarness
test_case.body: @Test
    public void testExecute() throws Exception {
      String filePath = "/testWriteFile/fadsfa/213";
      long size = 10000;
      writeFile(filePath, size);
      HdfsFileStatus fileStatus = dfs.getClient().getFileInfo(filePath);
      Assert.assertTrue(fileStatus.getLen() == size);
    }
test_case.class_method_signature: TestWriteFileAction.testExecute()
test_case.full_signature: @Test public void testExecute()
test_case.identifier: testExecute
test_case.invocations: writeFile getFileInfo getClient assertTrue getLen
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testExecute()
focal_class.declarator: LENGTH = "-length"
focal_class.modifier: public static final
focal_class.original_string: public static final String LENGTH = "-length";
focal_class.type: String
focal_class.var_name: LENGTH
focal_class.declarator: BUF_SIZE = "-bufSize"
focal_class.modifier: public static final
focal_class.original_string: public static final String BUF_SIZE = "-bufSize";
focal_class.type: String
focal_class.var_name: BUF_SIZE
focal_class.declarator: filePath
focal_class.modifier: private
focal_class.original_string: private String filePath;
focal_class.type: String
focal_class.var_name: filePath
focal_class.declarator: length = -1
focal_class.modifier: private
focal_class.original_string: private long length = -1;
focal_class.type: long
focal_class.var_name: length
focal_class.declarator: bufferSize = 64 * 1024
focal_class.modifier: private
focal_class.original_string: private int bufferSize = 64 * 1024;
focal_class.type: int
focal_class.var_name: bufferSize
focal_class.declarator: conf
focal_class.modifier: private
focal_class.original_string: private Configuration conf;
focal_class.type: Configuration
focal_class.var_name: conf
focal_class.file: smart-hadoop-support/smart-hadoop/src/main/java/org/smartdata/hdfs/action/WriteFileAction.java
focal_class.identifier: WriteFileAction
focal_class.class_method_signature: WriteFileAction.init(Map<String, String> args)
focal_class.full_signature: @Override public void init(Map<String, String> args)
focal_class.identifier: init
focal_class.modifiers: @Override public
focal_class.parameters: (Map<String, String> args)
focal_class.return: void
focal_class.signature: void init(Map<String, String> args)
focal_class.class_method_signature: WriteFileAction.execute()
focal_class.full_signature: @Override protected void execute()
focal_class.identifier: execute
focal_class.modifiers: @Override protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void execute()
focal_class.superclass: extends HdfsAction
focal_method.body: @Override
    protected void execute() throws Exception {
      if (filePath == null) {
        throw new IllegalArgumentException("File parameter is missing! ");
      }
      if (length == -1) {
        throw new IllegalArgumentException("Write Action provides wrong length! ");
      }
      appendLog(
          String.format(
              "Action starts at %s : Write %s with length %s",
              Utils.getFormatedCurrentTime(), filePath, length));
  
      Path path = new Path(filePath);
      FileSystem fileSystem = path.getFileSystem(conf);
      int replication = fileSystem.getServerDefaults(new Path(filePath)).getReplication();
      final FSDataOutputStream out = fileSystem.create(path, true, replication);
      // generate random data with given length
      byte[] buffer = new byte[bufferSize];
      new Random().nextBytes(buffer);
      appendLog(String.format("Generate random data with length %d", length));
      for (long pos = 0; pos < length; pos += bufferSize) {
        long writeLength = pos + bufferSize < length ? bufferSize : length - pos;
        out.write(buffer, 0, (int) writeLength);
      }
      out.close();
      appendLog("Write Successfully!");
    }
focal_method.class_method_signature: WriteFileAction.execute()
focal_method.full_signature: @Override protected void execute()
focal_method.identifier: execute
focal_method.invocations: appendLog format getFormatedCurrentTime getFileSystem getReplication getServerDefaults create nextBytes appendLog format write close appendLog
focal_method.modifiers: @Override protected
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void execute()