Search in sources :

Example 6 with UseRandomizedSchema

use of io.crate.testing.UseRandomizedSchema in project crate by crate.

the class SQLIntegrationTestCase method RandomizedSchema.

/**
 * If the Test class or method contains a @UseRandomizedSchema annotation then,
 * based on the schema argument, a random (unquoted) schema name is returned. The schema name consists
 * of a 1-20 character long ASCII string.
 * For more details on the schema parameter see {@link UseRandomizedSchema}
 * <p>
 * Method annotations have higher priority than class annotations.
 */
private String RandomizedSchema() {
    UseRandomizedSchema annotation = getTestAnnotation(UseRandomizedSchema.class);
    if (annotation == null || annotation.random() == false) {
        return Schemas.DOC_SCHEMA_NAME;
    }
    Random random = RandomizedContext.current().getRandom();
    while (true) {
        String schemaName = RandomStrings.randomAsciiLettersOfLengthBetween(random, 1, 20).toLowerCase();
        if (!Schemas.READ_ONLY_SYSTEM_SCHEMAS.contains(schemaName) && !Identifiers.isKeyWord(schemaName) && !containsExtendedAsciiChars(schemaName)) {
            return schemaName;
        }
    }
}
Also used : Random(java.util.Random) UseRandomizedSchema(io.crate.testing.UseRandomizedSchema)

Aggregations

UseRandomizedSchema (io.crate.testing.UseRandomizedSchema)6 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GetIndexTemplatesRequest (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)2 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)2 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)1 UseJdbc (io.crate.testing.UseJdbc)1 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BackgroundIndexer (org.elasticsearch.test.BackgroundIndexer)1 InternalTestCluster (org.elasticsearch.test.InternalTestCluster)1