/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z).</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomAlphabetic(final int minLengthInclusive, final int maxLengthExclusive) { return randomAlphabetic(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
/** * Adds a branch to the alternation (...|pattern). Order is important. * * @param cssClass css class that the matching regions should bear * @param regex Regex pattern * * @return The same builder */ public RegexHighlightGrammarBuilder or(Collection<String> cssClass, String regex) { String groupName = RandomStringUtils.randomAlphabetic(8); groupNameToRegex.put(groupName, regex); groupNameToCssClasses.put(groupName, new HashSet<>(cssClass)); return this; }
private String getString( int byteArraySize ) { return RandomStringUtils.randomAlphabetic( byteArraySize ); }
public static JavassistDynamicBean html() { return new JavassistDynamicBean("com.geccocrawler.gecco.dynamic.HtlmBean"+RandomStringUtils.randomAlphabetic(6)+System.nanoTime(), JavassistDynamicBean.HtmlBean); }
@Test public void testGeneratePartitionAssignment() { RandomStringUtils.randomAlphabetic(10); for (int i = 0; i < 20; i++) { String tableName = RandomStringUtils.randomAlphabetic(10) + "_REALTIME"; testGeneratePartitionAssignmentForTable(tableName); } }
private Value string( int length ) { return stringValue( RandomStringUtils.randomAlphabetic( length ) ); } }
@Test void shortStringIsValidValue() { INSTANCE.validate( RandomStringUtils.randomAlphabetic( 5 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( 10 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( 250 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( 450 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( MAX_TERM_LENGTH ) ); } }
private static Object generateSingleValue(Random random, FieldSpec.DataType dataType) { switch (dataType) { case INT: return Math.abs(random.nextInt()); case LONG: return Math.abs(random.nextLong()); case FLOAT: return Math.abs(random.nextFloat()); case DOUBLE: return Math.abs(random.nextDouble()); case STRING: return RandomStringUtils.randomAlphabetic(DEFAULT_STRING_VALUE_LENGTH); default: throw new IllegalStateException("Illegal data type"); } }
private String randomString( int size ) { return ThreadLocalRandom.current().nextBoolean() ? RandomStringUtils.random( size ) : RandomStringUtils.randomAlphabetic( size ); }
@Test void stringOverExceedLimitNotAllowed() { int length = MAX_TERM_LENGTH * 2; IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> INSTANCE.validate( RandomStringUtils.randomAlphabetic( length ) ) ); assertThat( iae.getMessage(), containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); }
@Test void stringOverExceedLimitNotAllowed() { int length = MAX_TERM_LENGTH * 2; IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> getValidator().validate( RandomStringUtils.randomAlphabetic( length ) ) ); assertThat( iae.getMessage(), containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); }
@Test void shortStringIsValidValue() { getValidator().validate( RandomStringUtils.randomAlphabetic( 5 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( 10 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( 250 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( 450 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( MAX_TERM_LENGTH ) ); }
/** * Make sure boundary alpha characters are generated by randomAlphabetic * This test will fail randomly with probability = 4 * (51/52)**1000 ~ 1.58E-8 */ @Test public void testRandomAlphabetic() { final char[] testChars = {'a', 'z', 'A', 'Z'}; final boolean[] found = {false, false, false, false}; for (int i = 0; i < 100; i++) { final String randString = RandomStringUtils.randomAlphabetic(10); for (int j = 0; j < testChars.length; j++) { if (randString.indexOf(testChars[j]) > 0) { found[j] = true; } } } for (int i = 0; i < testChars.length; i++) { if (!found[i]) { fail("alphanumeric character not generated in 1000 attempts: " + testChars[i] +" -- repeated failures indicate a problem "); } } }
private List<StoreFileInfo> mockStoreFiles(Path regionStoreDir, int howMany, long timestamp) throws IOException { List<StoreFileInfo> infos = Lists.newArrayList(); int i = 0; while (i < howMany) { StoreFileInfo storeFileInfo = mock(StoreFileInfo.class); doReturn(timestamp).doReturn(timestamp).when(storeFileInfo).getModificationTime(); doReturn(new Path(regionStoreDir, RandomStringUtils.randomAlphabetic(10))).when(storeFileInfo) .getPath(); infos.add(storeFileInfo); i++; } return infos; }
@Test public void testRandomAlphabeticRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{Alpha}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomAlphabetic(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
private static ScimUser[] makeTwoIdenticalUsers() { String email = "user@" + RandomStringUtils.randomAlphabetic(5) + ".com"; String givenName = "givenName"; String familyName = "familyName"; ScimUser scimUserToStoreInDB = new ScimUser(null, email, givenName, familyName); scimUserToStoreInDB.addEmail(email); ScimUser scimUserToUseInRequest = new ScimUser(null, email, givenName, familyName); return new ScimUser[]{scimUserToStoreInDB, scimUserToUseInRequest}; }
@Before public void prepareRegion() throws IOException { region = TEST_UTIL.createTestRegion("TestTimestampFilterSeekHint" + regionCount++, new HColumnDescriptor(FAMILY) .setBlocksize(1024) .setMaxVersions(MAX_VERSIONS) ); for (long i = 0; i <MAX_VERSIONS - 2; i++) { Put p = new Put(RK_BYTES, i); p.addColumn(FAMILY_BYTES, QUAL_BYTES, Bytes.toBytes(RandomStringUtils.randomAlphabetic(255))); region.put(p); } region.flush(true); } }
@Test public void testCreateAndImmediateGet() throws Exception { String random = RandomStringUtils.randomAlphabetic(10); String orgName = "org_" + random; String appName = "app_" + random; String orgAppName = orgName + "/" + appName; UUID appId = setup.createApplication(orgName, appName); UUID lookedUpId = setup.getEmf().lookupApplication( orgAppName ); Assert.assertEquals(appId, lookedUpId); }
@Override public void perform() throws Exception { TableDescriptor tableDescriptor = admin.getDescriptor(tableName); ColumnFamilyDescriptor columnDescriptor = null; while (columnDescriptor == null || tableDescriptor.getColumnFamily(columnDescriptor.getName()) != null) { columnDescriptor = ColumnFamilyDescriptorBuilder.of(RandomStringUtils.randomAlphabetic(5)); } // Don't try the modify if we're stopping if (context.isStopping()) { return; } LOG.debug("Performing action: Adding " + columnDescriptor + " to " + tableName); TableDescriptor modifiedTable = TableDescriptorBuilder.newBuilder(tableDescriptor) .setColumnFamily(columnDescriptor).build(); admin.modifyTable(modifiedTable); } }
@Test public void tooLongValuesAreNotAllowedInNodeIndex() { Index<Node> index = nodeIndex( EXACT_CONFIG ); String tooLongValue = RandomStringUtils.randomAlphabetic( 36000 ); try { index.add( graphDb.createNode(), "key", tooLongValue ); fail( "Validation exception expected. Such long values are not allowed in the index." ); } catch ( IllegalArgumentException e ) { // expected } try { index.add( graphDb.createNode(), "key", new String[] {"a", tooLongValue, "c"} ); fail( "Validation exception expected. Such long values are not allowed in the index." ); } catch ( IllegalArgumentException e ) { // expected } }