[tests] non-blocking data reader doesn't guarantee lines integrity

This commit is contained in:
Roman Shevchenko
2016-03-15 16:34:39 +01:00
parent 59f9aaf8ca
commit 61d717d774
@@ -30,6 +30,7 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -61,12 +62,12 @@ public class BaseOutputReaderTest {
@Test(timeout = 30000)
public void testBlockingRead() throws Exception {
doReadTest(BaseDataReader.SleepingPolicy.BLOCKING);
doReadTest(BaseDataReader.SleepingPolicy.BLOCKING, true);
}
@Test(timeout = 30000)
public void testNonBlockingRead() throws Exception {
doReadTest(BaseDataReader.SleepingPolicy.SIMPLE);
doReadTest(BaseDataReader.SleepingPolicy.SIMPLE, false);
}
@Test(timeout = 30000)
@@ -79,7 +80,7 @@ public class BaseOutputReaderTest {
doStopTest(BaseDataReader.SleepingPolicy.SIMPLE);
}
private void doReadTest(BaseDataReader.SleepingPolicy policy) throws Exception {
private void doReadTest(BaseDataReader.SleepingPolicy policy, boolean checkLines) throws Exception {
Process process = launchTest("data");
TestOutputReader reader = new TestOutputReader(process.getInputStream(), policy);
@@ -88,7 +89,13 @@ public class BaseOutputReaderTest {
reader.waitFor();
assertEquals(0, process.exitValue());
assertEquals(Arrays.asList(TEST_DATA), reader.myLines);
if (checkLines) {
assertEquals(Arrays.asList(TEST_DATA), reader.myLines);
}
else {
assertThat(reader.myLines.size()).isGreaterThanOrEqualTo(TEST_DATA.length);
assertThat(StringUtil.join(reader.myLines, "/")).isEqualTo(StringUtil.join(Arrays.asList(TEST_DATA), "/"));
}
}
private void doStopTest(BaseDataReader.SleepingPolicy policy) throws Exception {