Skip to content

Commit

Permalink
add UT with timeout for Text#find and fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xinqiu.hu committed Aug 8, 2022
1 parent 86bfbe6 commit 49ae6cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public int find(String what, int start) {
while (tgt.hasRemaining()) {
if (!src.hasRemaining()) { // src expired first
// the remaining bytes in src will always smaller than tgt,
// so we can return -1 directory
// so we can return -1 directly
return -1;
}
if (!(tgt.get() == src.get())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.util.Arrays;
import java.util.Random;
import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
import org.apache.hadoop.thirdparty.com.google.common.primitives.Bytes;
Expand Down Expand Up @@ -241,6 +242,17 @@ public void testFind() throws Exception {
assertThat(text.find("cd\u20acq")).isEqualTo(-1);
}

@Test(timeout = 10000)
public void testFindWithTimeout() throws Exception {
byte[] bytes = new byte[1000000];
Arrays.fill(bytes, (byte) 97);
String what = new String(bytes);
bytes[0] = (byte) 98;
Text text = new Text(bytes);

assertThat(text.find(what)).isEqualTo(-1);
}

@Test
public void testFindAfterUpdatingContents() throws Exception {
Text text = new Text("abcd");
Expand Down

0 comments on commit 49ae6cd

Please sign in to comment.