test random strings in CompressedStringTests

This commit is contained in:
Robert Muir 2014-08-07 15:44:36 -04:00
parent 700e50fc6c
commit 197ef0b205
1 changed files with 13 additions and 1 deletions

View File

@ -19,13 +19,14 @@
package org.elasticsearch.common.compress;
import org.apache.lucene.util.TestUtil;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.junit.Test;
import java.io.IOException;
import java.util.Random;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@ -52,4 +53,15 @@ public class CompressedStringTests extends ElasticsearchTestCase {
assertThat(new CompressedString(str2), not(equalTo(cstr)));
assertThat(new CompressedString(str2), equalTo(cstr2));
}
public void testRandom() throws IOException {
String compressor = "lzf";
CompressorFactory.configure(ImmutableSettings.settingsBuilder().put("compress.default.type", compressor).build());
Random r = getRandom();
for (int i = 0; i < 2000; i++) {
String string = TestUtil.randomUnicodeString(r, 10000);
CompressedString compressedString = new CompressedString(string);
assertThat(compressedString.string(), equalTo(string));
}
}
}