Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sakama committed Mar 18, 2016
1 parent c51907c commit fd632bc
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id "com.github.jruby-gradle.base" version "0.1.5"
id "java"
id "checkstyle"
id "jacoco"
}
import com.github.jrubygradle.JRubyExec
repositories {
Expand Down
88 changes: 84 additions & 4 deletions src/test/java/org/embulk/input/sftp/TestFileList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,87 @@
package org.embulk.input.sftp;

/**
* Created by satoshi on 2016/03/17.
*/
public class TestFileList {
import org.embulk.EmbulkTestRuntime;
import org.embulk.config.ConfigSource;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TestFileList
{
@Rule
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();

private ConfigSource config;

@Before
public void createConfigSource()
{
config = runtime.getExec().newConfigSource();
}

@Test
public void checkMinTaskSize()
throws Exception
{
{ // not specify min_task_size
FileList fileList = newFileList(config.deepCopy(),
"sample_00", 100L,
"sample_01", 150L,
"sample_02", 350L);

assertEquals(3, fileList.getTaskCount());
assertEquals("sample_00", fileList.get(0).get(0));
assertEquals("sample_01", fileList.get(1).get(0));
assertEquals("sample_02", fileList.get(2).get(0));
}

{
FileList fileList = newFileList(config.deepCopy().set("min_task_size", 100),
"sample_00", 100L,
"sample_01", 150L,
"sample_02", 350L);

assertEquals(3, fileList.getTaskCount());
assertEquals("sample_00", fileList.get(0).get(0));
assertEquals("sample_01", fileList.get(1).get(0));
assertEquals("sample_02", fileList.get(2).get(0));
}

{
FileList fileList = newFileList(config.deepCopy().set("min_task_size", 200),
"sample_00", 100L,
"sample_01", 150L,
"sample_02", 350L);

assertEquals(2, fileList.getTaskCount());
assertEquals("sample_00", fileList.get(0).get(0));
assertEquals("sample_01", fileList.get(0).get(1));
assertEquals("sample_02", fileList.get(1).get(0));
}

{
FileList fileList = newFileList(config.deepCopy().set("min_task_size", 700),
"sample_00", 100L,
"sample_01", 150L,
"sample_02", 350L);

assertEquals(1, fileList.getTaskCount());
assertEquals("sample_00", fileList.get(0).get(0));
assertEquals("sample_01", fileList.get(0).get(1));
assertEquals("sample_02", fileList.get(0).get(2));
}
}

private static FileList newFileList(ConfigSource config, Object... nameAndSize)
{
FileList.Builder builder = new FileList.Builder(config);

for (int i = 0; i < nameAndSize.length; i += 2) {
builder.add((String) nameAndSize[i], (long) nameAndSize[i + 1]);
}

return builder.build();
}
}
Loading

0 comments on commit fd632bc

Please sign in to comment.