Example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric

List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric.

Prototype

public static String randomAlphanumeric(int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters.

Usage

From source file:co.cask.cdap.filetailer.tailer.BaseTailerTest.java

@Test
public void baseReadingLogDirTest() throws ConfigurationLoadingException, InterruptedException {
    FileTailerQueue queue = new FileTailerQueue(1);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    LogTailer tailer = TailerLogUtils.createTailer(queue, flowConfig);
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/"
            + flowConfig.getSourceConfiguration().getFileName();
    Logger logger = TailerLogUtils.getSizeLogger(filePath, LOG_FILE_SIZE);
    RandomStringUtils randomUtils = new RandomStringUtils();
    List<String> logList = new ArrayList<String>(ENTRY_NUMBER);

    for (int i = 0; i < ENTRY_NUMBER; i++) {
        String currLine = randomUtils.randomAlphanumeric(LINE_SIZE);
        logger.debug(currLine);//w w  w. j  ava2 s  .  c  o  m
        logList.add(currLine);
    }
    tailer.startAsync();
    Thread.currentThread().sleep(SLEEP_TIME);
    for (String str : logList) {
        Assert.assertEquals(true, queue.take().getEventData().contains(str));
    }
    tailer.stopAsync();
    Thread.currentThread().sleep(1000);
}

From source file:com.joyfulmongo.db.JFMongoUser.java

public static String generateSessionToken() {
    String sessionToken = RandomStringUtils.randomAlphanumeric(25);
    return sessionToken;
}

From source file:com.lzhao.framework.spring_hibernate.demo.util.RandomUtil.java

public static String randomLocality() {
    return RandomStringUtils.randomAlphanumeric(10);
}

From source file:co.cask.cdap.filetailer.tailer.BaseTailerTest.java

@Test
public void fileTimeRotationTest() throws ConfigurationLoadingException, InterruptedException {
    FileTailerQueue queue = new FileTailerQueue(QUEUE_SIZE);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    LogTailer tailer = TailerLogUtils.createTailer(queue, flowConfig);
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/"
            + flowConfig.getSourceConfiguration().getFileName();
    Logger logger = TailerLogUtils.getTimeLogger(filePath);
    RandomStringUtils randomUtils = new RandomStringUtils();
    List<String> logList = new ArrayList<String>(ENTRY_NUMBER);
    tailer.startAsync();/* www  .  jav a  2 s .  c  om*/
    for (int i = 0; i < ENTRY_NUMBER; i++) {
        String currLine = randomUtils.randomAlphanumeric(LINE_SIZE);
        logger.debug(currLine);
        logList.add(currLine);
        Thread.currentThread().sleep(WRITING_INTERVAL);
    }
    Thread.currentThread().sleep(SLEEP_TIME);
    tailer.stopAsync();
    for (String str : logList) {
        Assert.assertEquals(true, queue.take().getEventData().contains(str));
    }
}

From source file:com.gtwm.pb.util.RandomString.java

/**
 * Creates a new random lowercase alphanumeric string. This can be used to
 * generate random passwords, internal table names etc. It will be a valid
 * Postgres object name so can be used for any database object.
 *///w  w w.j  a  v  a 2 s  .  c om
public static String generate() {
    if (!AppProperties.testMode) {
        return (RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomAlphanumeric(16)).toLowerCase();
    }
    rand++;
    return String.valueOf(rand);
    // For testing, use deterministic results - seed the random generator
    // with a constant
    /*      if (random == null) {
             random = new Random(42);
          }
          return RandomStringUtils.random(1, 0, 0, true, false, null, random)
    + RandomStringUtils.random(16, 0, 0, true, true, null, random);
    */ }

From source file:co.cask.cdap.filetailer.tailer.SizeBasedRotationTest.java

@Test
public void fileRotationTest() throws ConfigurationLoadingException, InterruptedException {
    FileTailerQueue queue = new FileTailerQueue(QUEUE_SIZE);
    PipeConfiguration flowConfig = TailerLogUtils.loadConfig();
    FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(flowConfig.getDaemonDir(),
            flowConfig.getStateFile());//from www .j a  v  a 2s  .  c  o m
    FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(flowConfig.getDaemonDir(),
            flowConfig.getStatisticsFile(), flowConfig.getStatisticsSleepInterval(), flowConfig.getPipeName(),
            flowConfig.getSourceConfiguration().getFileName());
    LogTailer tailer = new LogTailer(TailerLogUtils.loadConfig(), queue, stateProcessor, metricsProcessor,
            null);
    String filePath = flowConfig.getSourceConfiguration().getWorkDir().getAbsolutePath() + "/"
            + flowConfig.getSourceConfiguration().getFileName();

    List<String> logList = new ArrayList<String>(ENTRY_WRITE_NUMBER);
    RandomStringUtils randomUtils = new RandomStringUtils();
    Logger logger = TailerLogUtils.getSizeLogger(filePath, LOG_FILE_SIZE);
    tailer.startAsync();
    for (int i = 0; i < ENTRY_WRITE_NUMBER; i++) {
        String currLine = randomUtils.randomAlphanumeric(LINE_SIZE);
        logger.debug(currLine);
        logList.add(currLine);
        if (i % 50 == 0) {
            Thread.currentThread().sleep(300);
        }
    }
    Thread.currentThread().sleep(SLEEP_TIME);

    for (int i = 0; i < logList.size(); i++) {
        Assert.assertEquals(true, queue.take().getEventData().contains(logList.get(i)));
    }
    tailer.stopAsync();
}

From source file:de.innovationgate.utils.UIDGenerator.java

/**
 * Generate a unique ID/*from  ww w.j  a  va2 s  .co  m*/
 */
public static String generateUID() {
    String randomString = RandomStringUtils.randomAlphanumeric(64);
    String hashString = randomString + System.currentTimeMillis();
    return generateMD5Hash(hashString);
}

From source file:lifetime.backend.util.TestHelper.java

/**
 * Returns a random string./*from www .ja v  a 2  s .c om*/
 *
 * @return A random string.
 */
public static String getRandomString() {
    return RandomStringUtils.randomAlphanumeric(20);
}

From source file:com.yolodata.tbana.testutils.FileTestUtils.java

public static String getRandomFilename(String extension) {
    return RandomStringUtils.randomAlphanumeric(25).concat("." + extension);
}

From source file:com.boyuanitsm.fort.service.util.RandomUtil.java

/**
 * Generates a password./*from   w  w w.ja  va 2s.com*/
 *
 * @return the generated password
 */
public static String generatePassword() {
    return RandomStringUtils.randomAlphanumeric(DEF_COUNT);
}