Skip to content

Commit 49ae6cd

Browse files
author
xinqiu.hu
committed
add UT with timeout for Text#find and fix comments
1 parent 86bfbe6 commit 49ae6cd

File tree

2 files changed

+13
-1
lines changed
  • hadoop-common-project/hadoop-common/src

2 files changed

+13
-1
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public int find(String what, int start) {
200200
while (tgt.hasRemaining()) {
201201
if (!src.hasRemaining()) { // src expired first
202202
// the remaining bytes in src will always smaller than tgt,
203-
// so we can return -1 directory
203+
// so we can return -1 directly
204204
return -1;
205205
}
206206
if (!(tgt.get() == src.get())) {

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestText.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.BufferUnderflowException;
2323
import java.nio.ByteBuffer;
2424
import java.nio.charset.CharacterCodingException;
25+
import java.util.Arrays;
2526
import java.util.Random;
2627
import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
2728
import org.apache.hadoop.thirdparty.com.google.common.primitives.Bytes;
@@ -241,6 +242,17 @@ public void testFind() throws Exception {
241242
assertThat(text.find("cd\u20acq")).isEqualTo(-1);
242243
}
243244

245+
@Test(timeout = 10000)
246+
public void testFindWithTimeout() throws Exception {
247+
byte[] bytes = new byte[1000000];
248+
Arrays.fill(bytes, (byte) 97);
249+
String what = new String(bytes);
250+
bytes[0] = (byte) 98;
251+
Text text = new Text(bytes);
252+
253+
assertThat(text.find(what)).isEqualTo(-1);
254+
}
255+
244256
@Test
245257
public void testFindAfterUpdatingContents() throws Exception {
246258
Text text = new Text("abcd");

0 commit comments

Comments
 (0)