List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric
public static String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters.
From source file:org.apache.hadoop.fs.FSTestWrapper.java
public FSTestWrapper(String testRootDir) { // Use default test dir if not provided if (testRootDir == null || testRootDir.isEmpty()) { testRootDir = GenericTestUtils.getTestDir().getAbsolutePath(); }//from w w w.j a va 2s . c om // salt test dir with some random digits for safe parallel runs this.testRootDir = testRootDir + "/" + RandomStringUtils.randomAlphanumeric(10); }
From source file:org.apache.hadoop.fs.TestWebHdfsFileContextMainOperations.java
@Before public void setUp() throws Exception { URI webhdfsUrlReal = getWebhdfsUrl(); Path testBuildData = new Path( webhdfsUrlReal + "/build/test/data/" + RandomStringUtils.randomAlphanumeric(10)); Path rootPath = new Path(testBuildData, "root-uri"); localFsRootPath = rootPath.makeQualified(webhdfsUrlReal, null); fc.mkdir(getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true); }
From source file:org.apache.hadoop.hdfs.TestDFSUtil.java
@Test public void testUTFconversion() throws Exception { Random r = new Random(System.currentTimeMillis()); for (int i = 0; i < 100000; i++) { // create random length string int len = r.nextInt(50) + 1; // full unicode string validateStringConversion(RandomStringUtils.random(len)); // only ascii characters validateStringConversion(RandomStringUtils.randomAscii(len)); // only alphanumeric characters validateStringConversion(RandomStringUtils.randomAlphanumeric(len)); // validate singe-character, which translates to 1,2,3 bytes validateStringConversion(generateOneCharString(1)); validateStringConversion(generateOneCharString(2)); validateStringConversion(generateOneCharString(3)); }/*from w w w .j a va 2 s . co m*/ }
From source file:org.apache.hadoop.hdfs.util.TestPosixUserNameChecker.java
@Test public void test() { check("abc", true); check("a_bc", true); check("a1234bc", true); check("a1234bc45", true); check("_a1234bc45$", true); check("_a123-4bc45$", true); check("abc_", true); check("ab-c_$", true); check("_abc", true); check("ab-c$", true); check("-abc", false); check("-abc_", false); check("a$bc", false); check("9abc", false); check("-abc", false); check("$abc", false); check("", false); check(null, false);//w w w .jav a 2 s . co m check(RandomStringUtils.randomAlphabetic(100).toLowerCase(), true); check(RandomStringUtils.randomNumeric(100), false); check("a" + RandomStringUtils.randomNumeric(100), true); check("_" + RandomStringUtils.randomNumeric(100), true); check("a" + RandomStringUtils.randomAlphanumeric(100).toLowerCase(), true); check("_" + RandomStringUtils.randomAlphanumeric(100).toLowerCase(), true); check(RandomStringUtils.random(1000), false); //unicode }
From source file:org.apache.hadoop.mapreduce.checkpoint.RandomNameCNS.java
@Override public String getNewName() { return "checkpoint_" + RandomStringUtils.randomAlphanumeric(8); }
From source file:org.apache.hadoop.test.GenericTestUtils.java
/** * Get a temp path. This may or may not be relative; it depends on what the * {@link #SYSPROP_TEST_DATA_DIR} is set to. If unset, it returns a path * under the relative path {@link #DEFAULT_TEST_DATA_PATH} * @param subpath sub path, with no leading "/" character * @return a string to use in paths//www .j av a2s . c o m */ public static String getRandomizedTempPath() { return getTempPath(RandomStringUtils.randomAlphanumeric(10)); }
From source file:org.apache.hadoop.test.PathUtils.java
public static File getTestDir(Class<?> caller, boolean create) { File dir = new File(System.getProperty("test.build.data", "target/test/data") + "/" + RandomStringUtils.randomAlphanumeric(10), caller.getSimpleName()); if (create) { dir.mkdirs();//w w w .j av a2s. c o m } return dir; }
From source file:org.apache.hadoop.yarn.server.nodemanager.DirectoryCollection.java
/** * Function to test whether a dir is working correctly by actually creating a * random directory./*from ww w . j ava2 s.c om*/ * * @param dir * the dir to test */ private void verifyDirUsingMkdir(File dir) throws IOException { String randomDirName = RandomStringUtils.randomAlphanumeric(5); File target = new File(dir, randomDirName); int i = 0; while (target.exists()) { randomDirName = RandomStringUtils.randomAlphanumeric(5) + i; target = new File(dir, randomDirName); i++; } try { DiskChecker.checkDir(target); } finally { FileUtils.deleteQuietly(target); } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestingRMAppSecurityActions.java
@Override public String generateJWT(JWTSecurityHandler.JWTMaterialParameter jwtParameter) throws URISyntaxException, IOException { return RandomStringUtils.randomAlphanumeric(16); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestingRMAppSecurityActions.java
@Override public String renewJWT(JWTSecurityHandler.JWTMaterialParameter jwtParameter) throws URISyntaxException, IOException { // Nothing to do LOG.info("Renewing JWT " + jwtParameter.getAppUser() + "/" + jwtParameter.getApplicationId()); return RandomStringUtils.randomAlphanumeric(16); }