add UT with timeout for Text#find and fix comments

This commit is contained in:
xinqiu.hu 2022-08-08 12:46:16 +08:00
parent 86bfbe69ab
commit 49ae6cd5d8
2 changed files with 13 additions and 1 deletions

View File

@ -200,7 +200,7 @@ public class Text extends BinaryComparable
while (tgt.hasRemaining()) { while (tgt.hasRemaining()) {
if (!src.hasRemaining()) { // src expired first if (!src.hasRemaining()) { // src expired first
// the remaining bytes in src will always smaller than tgt, // the remaining bytes in src will always smaller than tgt,
// so we can return -1 directory // so we can return -1 directly
return -1; return -1;
} }
if (!(tgt.get() == src.get())) { if (!(tgt.get() == src.get())) {

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException; import java.nio.charset.CharacterCodingException;
import java.util.Arrays;
import java.util.Random; import java.util.Random;
import org.apache.hadoop.thirdparty.com.google.common.base.Charsets; import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
import org.apache.hadoop.thirdparty.com.google.common.primitives.Bytes; import org.apache.hadoop.thirdparty.com.google.common.primitives.Bytes;
@ -241,6 +242,17 @@ public class TestText {
assertThat(text.find("cd\u20acq")).isEqualTo(-1); 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 @Test
public void testFindAfterUpdatingContents() throws Exception { public void testFindAfterUpdatingContents() throws Exception {
Text text = new Text("abcd"); Text text = new Text("abcd");