Search in sources :

Example 1 with Repeat

use of com.carrotsearch.randomizedtesting.annotations.Repeat in project randomizedtesting by randomizedtesting.

the class TestBiasedNumbers method biasedDoubles.

@Test
@Repeat(iterations = 100)
public void biasedDoubles() {
    Random r = getRandom();
    // Some sanity checks.
    sanityCheck(r, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
    sanityCheck(r, Double.NEGATIVE_INFINITY, 0);
    sanityCheck(r, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    sanityCheck(r, 0, Double.POSITIVE_INFINITY);
    sanityCheck(r, 0d, 0);
    sanityCheck(r, 0d, 1);
    sanityCheck(r, -1d, 1);
    sanityCheck(r, 1d, 2);
}
Also used : Random(java.util.Random) Test(org.junit.Test) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 2 with Repeat

use of com.carrotsearch.randomizedtesting.annotations.Repeat in project randomizedtesting by randomizedtesting.

the class TestHookMethodOrderWithExceptions method checkOrderSameAsJUnit.

@Test
@Repeat(iterations = 20)
public void checkOrderSameAsJUnit() throws Exception {
    long seed = RandomizedContext.current().getRandomness().getSeed();
    callOrder.clear();
    Super.rnd = new Random(seed);
    FullResult r1 = WithNestedTestClass.runTests(WithRegularRunner.class);
    List<String> junitOrder = new ArrayList<String>(callOrder);
    callOrder.clear();
    Super.rnd = new Random(seed);
    FullResult r2 = WithNestedTestClass.runTests(WithRandomizedRunner.class);
    List<String> rrunnerOrder = new ArrayList<String>(callOrder);
    Assert.assertEquals(junitOrder, rrunnerOrder);
    Assertions.assertThat(r1.getRunCount()).isEqualTo(r2.getRunCount());
}
Also used : FullResult(com.carrotsearch.randomizedtesting.WithNestedTestClass.FullResult) Random(java.util.Random) ArrayList(java.util.ArrayList) Test(org.junit.Test) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 3 with Repeat

use of com.carrotsearch.randomizedtesting.annotations.Repeat in project randomizedtesting by randomizedtesting.

the class TestManyThreadsOOM method testSpawnManyThreads.

@Test
@Repeat(iterations = 10)
public void testSpawnManyThreads() throws Exception {
    // touch the context from within a thread and die.
    for (int i = 0; i < 500; i++) {
        final Thread t = new Thread() {

            final byte[] hold = new byte[1024 * 1024 * 10];

            public void run() {
                Random rnd = RandomizedContext.current().getRandom();
                guard += rnd.nextInt() + hold.length;
            }
        };
        t.start();
        t.join();
    }
}
Also used : Random(java.util.Random) Test(org.junit.Test) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 4 with Repeat

use of com.carrotsearch.randomizedtesting.annotations.Repeat in project randomizedtesting by randomizedtesting.

the class TestXmlStringsRoundtrip method testRoundTrip.

@Test
@Repeat(iterations = 100)
public void testRoundTrip() throws Exception {
    char[] chars = new char[randomIntBetween(0, 1024)];
    Random random = getRandom();
    for (int i = 0; i < chars.length; i++) {
        chars[i] = (char) random.nextInt();
    }
    check(chars);
}
Also used : Random(java.util.Random) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 5 with Repeat

use of com.carrotsearch.randomizedtesting.annotations.Repeat in project lucene-solr by apache.

the class TestPullReplica method testCreateDelete.

// 2 times to make sure cleanup is complete and we can create the same collection
@Repeat(iterations = 2)
public void testCreateDelete() throws Exception {
    try {
        switch(random().nextInt(3)) {
            case 0:
                // Sometimes use SolrJ
                CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1, 0, 3).setMaxShardsPerNode(100).process(cluster.getSolrClient());
                break;
            case 1:
                // Sometimes use v1 API
                String url = String.format(Locale.ROOT, "%s/admin/collections?action=CREATE&name=%s&numShards=%s&pullReplicas=%s&maxShardsPerNode=%s", cluster.getRandomJetty(random()).getBaseUrl(), collectionName, // numShards
                2, // pullReplicas
                3, // maxShardsPerNode
                100);
                // These options should all mean the same
                url = url + pickRandom("", "&nrtReplicas=1", "&replicationFactor=1");
                HttpGet createCollectionGet = new HttpGet(url);
                cluster.getSolrClient().getHttpClient().execute(createCollectionGet);
                break;
            case 2:
                // Sometimes use V2 API
                url = cluster.getRandomJetty(random()).getBaseUrl().toString() + "/____v2/c";
                String requestBody = String.format(Locale.ROOT, "{create:{name:%s, numShards:%s, pullReplicas:%s, maxShardsPerNode:%s %s}}", collectionName, // numShards
                2, // pullReplicas
                3, // maxShardsPerNode
                100, // These options should all mean the same
                pickRandom("", ", nrtReplicas:1", ", replicationFactor:1"));
                HttpPost createCollectionPost = new HttpPost(url);
                createCollectionPost.setHeader("Content-type", "application/json");
                createCollectionPost.setEntity(new StringEntity(requestBody));
                HttpResponse httpResponse = cluster.getSolrClient().getHttpClient().execute(createCollectionPost);
                assertEquals(200, httpResponse.getStatusLine().getStatusCode());
                break;
        }
        boolean reloaded = false;
        while (true) {
            DocCollection docCollection = getCollectionState(collectionName);
            assertNotNull(docCollection);
            assertEquals("Expecting 4 relpicas per shard", 8, docCollection.getReplicas().size());
            assertEquals("Expecting 6 pull replicas, 3 per shard", 6, docCollection.getReplicas(EnumSet.of(Replica.Type.PULL)).size());
            assertEquals("Expecting 2 writer replicas, one per shard", 2, docCollection.getReplicas(EnumSet.of(Replica.Type.NRT)).size());
            for (Slice s : docCollection.getSlices()) {
                // read-only replicas can never become leaders
                assertFalse(s.getLeader().getType() == Replica.Type.PULL);
                List<String> shardElectionNodes = cluster.getZkClient().getChildren(ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null, true);
                assertEquals("Unexpected election nodes for Shard: " + s.getName() + ": " + Arrays.toString(shardElectionNodes.toArray()), 1, shardElectionNodes.size());
            }
            assertUlogPresence(docCollection);
            if (reloaded) {
                break;
            } else {
                // reload
                CollectionAdminResponse response = CollectionAdminRequest.reloadCollection(collectionName).process(cluster.getSolrClient());
                assertEquals(0, response.getStatus());
                reloaded = true;
            }
        }
    } finally {
        zkClient().printLayoutToStdOut();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) Slice(org.apache.solr.common.cloud.Slice) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DocCollection(org.apache.solr.common.cloud.DocCollection) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Aggregations

Repeat (com.carrotsearch.randomizedtesting.annotations.Repeat)14 Test (org.junit.Test)11 Random (java.util.Random)5 ArrayList (java.util.ArrayList)4 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 FieldType (org.apache.lucene.document.FieldType)2 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)2 BytesRef (org.apache.lucene.util.BytesRef)2 CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)2 DocCollection (org.apache.solr.common.cloud.DocCollection)2 Slice (org.apache.solr.common.cloud.Slice)2 Shape (org.locationtech.spatial4j.shape.Shape)2 FullResult (com.carrotsearch.randomizedtesting.WithNestedTestClass.FullResult)1 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 ArrayDeque (java.util.ArrayDeque)1