本文整理汇总了Java中com.carrotsearch.randomizedtesting.RandomizedTest类的典型用法代码示例。如果您正苦于以下问题:Java RandomizedTest类的具体用法?Java RandomizedTest怎么用?Java RandomizedTest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RandomizedTest类属于com.carrotsearch.randomizedtesting包,在下文中一共展示了RandomizedTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileSystem
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
/**
* Returns a new FileSystem to read REST resources, or null if they
* are available from classpath.
*/
@SuppressForbidden(reason = "proper use of URL, hack around a JDK bug")
protected static FileSystem getFileSystem() throws IOException {
// REST suite handling is currently complicated, with lots of filtering and so on
// For now, to work embedded in a jar, return a ZipFileSystem over the jar contents.
URL codeLocation = FileUtils.class.getProtectionDomain().getCodeSource().getLocation();
boolean loadPackaged = RandomizedTest.systemPropertyAsBoolean(REST_LOAD_PACKAGED_TESTS, true);
if (codeLocation.getFile().endsWith(".jar") && loadPackaged) {
try {
// hack around a bug in the zipfilesystem implementation before java 9,
// its checkWritable was incorrect and it won't work without write permissions.
// if we add the permission, it will open jars r/w, which is too scary! so copy to a safe r-w location.
Path tmp = Files.createTempFile(null, ".jar");
try (InputStream in = FileSystemUtils.openFileURLStream(codeLocation)) {
Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
}
return FileSystems.newFileSystem(new URI("jar:" + tmp.toUri()), Collections.emptyMap());
} catch (URISyntaxException e) {
throw new IOException("couldn't open zipfilesystem: ", e);
}
} else {
return null;
}
}
示例2: afterIfSuccessful
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
/**
* We're only interested in failing the suite if it was successful (otherwise
* just propagate the original problem and don't bother doing anything else).
*/
@Override
protected void afterIfSuccessful() throws Throwable {
if (isEnforced()) {
checkCaptureStreams();
// Flush any buffers.
capturedSystemOut.printStream.flush();
capturedSystemErr.printStream.flush();
// Check for offenders, but only if everything was successful so far.
int limit = RandomizedTest.getContext().getTargetClass().getAnnotation(Limit.class).bytes();
if (bytesWritten.get() >= limit && failureMarker.wasSuccessful()) {
throw new AssertionError(String.format(Locale.ENGLISH,
"The test or suite printed %d bytes to stdout and stderr," +
" even though the limit was set to %d bytes. Increase the limit with @%s, ignore it completely" +
" with @%s or run with -Dtests.verbose=true",
bytesWritten.get(),
limit,
Limit.class.getSimpleName(),
SuppressSysoutChecks.class.getSimpleName()));
}
}
}
示例3: before
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
protected void before() throws Throwable {
if (!isPropertyEmpty(SysGlobals.SYSPROP_TESTFILTER()) ||
!isPropertyEmpty(SysGlobals.SYSPROP_TESTCLASS()) ||
!isPropertyEmpty(SysGlobals.SYSPROP_TESTMETHOD()) ||
!isPropertyEmpty(SysGlobals.SYSPROP_ITERATIONS())) {
// We're running with a complex test filter that is properly handled by classes
// which are executed by RandomizedRunner. The "outer" classes testing LuceneTestCase
// itself are executed by the default JUnit runner and would be always executed.
// We thus always skip execution if any filtering is detected.
Assume.assumeTrue(false);
}
// Check zombie threads from previous suites. Don't run if zombies are around.
RandomizedTest.assumeFalse(RandomizedRunner.hasZombieThreads());
TestRuleIgnoreAfterMaxFailures newRule = new TestRuleIgnoreAfterMaxFailures(Integer.MAX_VALUE);
prevRule = LuceneTestCase.replaceMaxFailureRule(newRule);
RandomizedTest.assumeFalse(FailureMarker.hadFailures());
}
示例4: testFailIfUnreferencedFiles
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
@Test
public void testFailIfUnreferencedFiles() {
Result r = JUnitCore.runClasses(Nested1.class);
RandomizedTest.assumeTrue("Ignoring nested test, very likely zombie threads present.",
r.getIgnoreCount() == 0);
// We are suppressing output anyway so dump the failures.
for (Failure f : r.getFailures()) {
System.out.println(f.getTrace());
}
Assert.assertEquals("Expected exactly one failure.",
1, r.getFailureCount());
Assert.assertTrue("Expected unreferenced files assertion.",
r.getFailures().get(0).getTrace().contains("unreferenced files:"));
}
示例5: testSortMultiVal
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
@Test
public void testSortMultiVal() throws Exception {
RandomizedTest.assumeFalse("Multivalue not supported for this field",
fieldName.equals("pointvector") || fieldName.equals("bbox"));
assertU(adoc("id", "100", fieldName, "1,2"));//1 point
assertU(adoc("id", "101", fieldName, "4,-1", fieldName, "3,5"));//2 points, 2nd is pretty close to query point
assertU(commit());
assertJQ(req(
"q", radiusQuery(3, 4, 9, "distance", null),
"fl","id,score",
"sort","score asc")//want ascending due to increasing distance
, 1e-4
, "/response/docs/[0]/id=='101'"
, "/response/docs/[0]/score==0.99862987"//dist to 3,5
);
}
示例6: apply
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
@Override
public Statement apply(final Statement s, final Description d) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (failuresSoFar >= maxFailures) {
RandomizedTest.assumeTrue("Ignored, failures limit reached (" +
failuresSoFar + " >= " + maxFailures + ").", false);
}
try {
s.evaluate();
} catch (Throwable t) {
if (!TestRuleMarkFailure.isAssumption(t)) {
failuresSoFar++;
}
throw t;
}
}
};
}
示例7: testSortMultiVal
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
@Test
public void testSortMultiVal() throws Exception {
RandomizedTest.assumeFalse("Multivalue not supported for this field", fieldName.equals("pointvector"));
assertU(adoc("id", "100", fieldName, "1,2"));//1 point
assertU(adoc("id", "101", fieldName, "4,-1", fieldName, "3,5"));//2 points, 2nd is pretty close to query point
assertU(commit());
assertJQ(req(
"q", "{! score=distance}"+fieldName +":\"Intersects(Circle(3,4 d=9))\"",
"fl","id,score",
"sort","score asc")//want ascending due to increasing distance
, 1e-4
, "/response/docs/[0]/id=='101'"
, "/response/docs/[0]/score==0.99862987"//dist to 3,5
);
}
示例8: clusterName
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
public static String clusterName(String prefix, long clusterSeed) {
StringBuilder builder = new StringBuilder(prefix);
final int childVM = RandomizedTest.systemPropertyAsInt(SysGlobals.CHILDVM_SYSPROP_JVM_ID, 0);
builder.append("-CHILD_VM=[").append(childVM).append(']');
builder.append("-CLUSTER_SEED=[").append(clusterSeed).append(']');
// if multiple maven task run on a single host we better have an identifier that doesn't rely on input params
builder.append("-HASH=[").append(SeedUtils.formatSeed(System.nanoTime())).append(']');
return builder.toString();
}
示例9: randomlyResetClients
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
private void randomlyResetClients() throws IOException {
// only reset the clients on nightly tests, it causes heavy load...
if (RandomizedTest.isNightly() && rarely(random)) {
final Collection<NodeAndClient> nodesAndClients = nodes.values();
for (NodeAndClient nodeAndClient : nodesAndClients) {
nodeAndClient.resetClient();
}
}
}
示例10: getContentType
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
private XContentType getContentType(Map<String, String> headers, XContentType[] supportedContentTypes) {
XContentType xContentType = null;
String contentType = headers.get("Content-Type");
if (contentType != null) {
xContentType = XContentType.fromMediaType(contentType);
}
if (xContentType != null) {
return xContentType;
}
if (randomizeContentType) {
return RandomizedTest.randomFrom(supportedContentTypes);
}
return XContentType.JSON;
}
示例11: sendBodyAsSourceParam
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
private static boolean sendBodyAsSourceParam(List<String> supportedMethods, String contentType) {
if (supportedMethods.contains(HttpGet.METHOD_NAME)) {
if (contentType.startsWith(ContentType.APPLICATION_JSON.getMimeType()) ||
contentType.startsWith(YAML_CONTENT_TYPE.getMimeType())) {
return RandomizedTest.rarely();
}
}
return false;
}
示例12: doUploadMultipart
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
@Override
protected PartETag doUploadMultipart(S3BlobStore blobStore, String bucketName, String blobName, String uploadId, InputStream is, int length, boolean lastPart) throws AmazonS3Exception {
try {
long copied = Streams.copy(is, out);
if (copied != length) {
throw new AmazonS3Exception("Not all the bytes were copied");
}
return new PartETag(numberOfUploadRequests++, RandomizedTest.randomAsciiOfLength(50));
} catch (IOException e) {
throw new AmazonS3Exception(e.getMessage());
}
}
示例13: testTermsByQueryStringField
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
/**
* Tests that the terms by query action returns the correct terms against string fields
*/
@Test
public void testTermsByQueryStringField() throws Exception {
createIndex("test");
int numDocs = RandomizedTest.randomIntBetween(100, 2000);
logger.info("--> indexing [" + numDocs + "] docs");
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "type", "" + i)
.setSource(jsonBuilder().startObject()
.field("str", Integer.toString(i))
.endObject())
.execute().actionGet();
}
client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> lookup terms in field [str]");
TermsByQueryResponse resp = new TermsByQueryRequestBuilder(client(), TermsByQueryAction.INSTANCE).setIndices("test")
.setField("str")
.setQuery(QueryBuilders.matchAllQuery())
.setTermsEncoding(TermsByQueryRequest.TermsEncoding.LONG)
.execute()
.actionGet();
ElasticsearchAssertions.assertNoFailures(resp);
assertThat(resp.getEncodedTermsSet(), notNullValue());
assertThat(resp.getSize(), is(numDocs));
TermsSet lTerms = NumericTermsSet.readFrom(resp.getEncodedTermsSet());
assertThat(lTerms instanceof LongTermsSet, is(true));
for (int i = 0; i < numDocs; i++) {
BytesRef bytesRef = new BytesRef(Integer.toString(i));
long termHash = LongBloomFilter.hash3_x64_128(bytesRef.bytes, bytesRef.offset, bytesRef.length, 0);
assertThat(((LongTermsSet) lTerms).contains(termHash), is(true));
}
}
示例14: testTermsByQueryIntegerField
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
/**
* Tests that the terms by query action returns the correct terms against integer fields
*/
@Test
public void testTermsByQueryIntegerField() throws Exception {
createIndex("test");
int numDocs = RandomizedTest.randomIntBetween(100, 2000);
logger.info("--> indexing [" + numDocs + "] docs");
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "type", "" + i)
.setSource(jsonBuilder().startObject()
.field("int", i)
.endObject())
.execute().actionGet();
}
client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> lookup terms in field [int]");
TermsByQueryResponse resp = new TermsByQueryRequestBuilder(client(), TermsByQueryAction.INSTANCE).setIndices("test")
.setField("int")
.setQuery(QueryBuilders.matchAllQuery())
.setTermsEncoding(TermsByQueryRequest.TermsEncoding.LONG)
.execute()
.actionGet();
ElasticsearchAssertions.assertNoFailures(resp);
assertThat(resp.getEncodedTermsSet(), notNullValue());
assertThat(resp.getSize(), is(numDocs));
TermsSet lTerms = TermsSet.readFrom(resp.getEncodedTermsSet());
assertThat(lTerms instanceof LongTermsSet, is(true));
assertThat(lTerms.size(), is(numDocs));
for (int i = 0; i < numDocs; i++) {
assertThat(((LongTermsSet) lTerms).contains(Long.valueOf(i)), is(true));
}
}
示例15: testTermsByQueryWithLimit
import com.carrotsearch.randomizedtesting.RandomizedTest; //导入依赖的package包/类
/**
* Tests that the limit for the number of terms retrieved is properly applied.
*/
@Test
public void testTermsByQueryWithLimit() throws Exception {
createIndex("test");
int numDocs = RandomizedTest.randomIntBetween(100, 2000);
logger.info("--> indexing [" + numDocs + "] docs");
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "type", "" + i)
.setSource(jsonBuilder().startObject()
.field("int", i)
.endObject())
.execute().actionGet();
}
client().admin().indices().prepareRefresh("test").execute().actionGet();
logger.info("--> lookup terms in field [int]");
TermsByQueryResponse resp = new TermsByQueryRequestBuilder(client(), TermsByQueryAction.INSTANCE).setIndices("test")
.setField("int")
.setQuery(QueryBuilders.matchAllQuery())
.setOrderBy(TermsByQueryRequest.Ordering.DEFAULT)
.setMaxTermsPerShard(50)
.setTermsEncoding(TermsByQueryRequest.TermsEncoding.LONG)
.execute()
.actionGet();
int expectedMaxResultSize = this.getNumShards("test").totalNumShards * 50;
ElasticsearchAssertions.assertNoFailures(resp);
assertThat(resp.getEncodedTermsSet(), notNullValue());
assertThat(resp.getSize(), lessThanOrEqualTo(expectedMaxResultSize));
TermsSet lTerms = TermsSet.readFrom(resp.getEncodedTermsSet());
assertThat(lTerms instanceof LongTermsSet, is(true));
}