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:com.xtructure.xevolution.operator.impl.UTestCopyCrossoverOperator.java

License:asdf

public void crossoverReturnsExpectedGenome() throws OperationFailedException {
    Genome<String> g1 = new GenomeImpl(1, RandomStringUtils.randomAlphanumeric(10));
    Genome<String> g2 = new GenomeImpl(2, RandomStringUtils.randomAlphanumeric(10));

    Genome<String> child = new CopyCrossoverOperator<String>(GENETICS_FACTORY, 1.0).crossover(99, g1, g2);
    assertThat("", //
            child.getId(), isEqualTo(g1.getBaseId().createChild(99)));
    assertThat("", //
            child.getData(), isEqualTo(g1.getData()));

    child = new CopyCrossoverOperator<String>(GENETICS_FACTORY, 0.0).crossover(88, g1, g2);
    assertThat("", //
            child.getId(), isEqualTo(g1.getBaseId().createChild(88)));
    assertThat("", //
            child.getData(), isEqualTo(g2.getData()));
}

From source file:com.example.bigtable.simpleperf.WritePerfTest.java

protected static void runMutationTests(Connection conn, TableName tableName, long rowCount, int valueSize)
        throws IOException {
    System.out.println("starting mutations");
    Stopwatch uberStopwatch = new Stopwatch();
    Stopwatch incrementalStopwatch = new Stopwatch();
    try (BufferedMutator mutator = conn.getBufferedMutator(tableName)) {
        // Use the same value over and over again. Creating new random data takes time. Don't count
        // creating a large array towards Bigtable performance
        byte[] value = Bytes.toBytes(RandomStringUtils.randomAlphanumeric(valueSize));
        incrementalStopwatch.start();//from   w  ww.j a v  a2 s  .  c o  m
        for (long i = 1; i < 10; i++) {
            // The first few writes are slow.
            doPut(mutator, value);
        }
        mutator.flush();
        BigtableUtilities.printPerformance("starter batch", incrementalStopwatch, 10);

        uberStopwatch.reset();
        incrementalStopwatch.reset();
        uberStopwatch.start();
        incrementalStopwatch.start();
        for (int i = 0; i < rowCount - 10; i++) {
            doPut(mutator, value);
            if (i > 0 && i % PRINT_COUNT == 0) {
                BigtableUtilities.printPerformance("one batch", incrementalStopwatch, PRINT_COUNT);
                BigtableUtilities.printPerformance("average so far", uberStopwatch, i);
                incrementalStopwatch.reset();
                incrementalStopwatch.start();
            }
        }
        incrementalStopwatch.reset();
        incrementalStopwatch.start();
        System.out.println("Flushing");
        mutator.flush();
        System.out.println(String.format("Flush took %d ms.", incrementalStopwatch.elapsedMillis()));
        BigtableUtilities.printPerformance("full batch", uberStopwatch, PRINT_COUNT);
    } catch (RetriesExhaustedWithDetailsException e) {
        logExceptions(e);
    }
}

From source file:alluxio.master.meta.checkconf.ServerConfigurationStoreTest.java

@Before
public void before() {
    PropertyKey keyEnforce = PropertyKey.NETWORK_NETTY_HEARTBEAT_TIMEOUT_MS;
    PropertyKey keyWarn = PropertyKey.WORKER_FREE_SPACE_TIMEOUT;
    mConfigListOne = Arrays.asList(
            new ConfigProperty().setName(keyEnforce.getName()).setSource("Test").setValue("Value"),
            new ConfigProperty().setName(keyWarn.getName()).setSource("Test").setValue("Value2"));
    mConfigListTwo = Arrays.asList(
            new ConfigProperty().setName(keyEnforce.getName()).setSource("Test").setValue("Value3"),
            new ConfigProperty().setName(keyWarn.getName()).setSource("Test").setValue("Value4"));
    Random random = new Random();
    mAddressOne = new Address(RandomStringUtils.randomAlphanumeric(10), random.nextInt());
    mAddressTwo = new Address(RandomStringUtils.randomAlphanumeric(10), random.nextInt());
}

From source file:net.nelz.simplesm.aop.ReadThroughMultiCacheTest.java

@Test
public void testConvertIdObject() throws Exception {
    final AnnotationData data = new AnnotationData();
    data.setNamespace(RandomStringUtils.randomAlphanumeric(6));
    final Map<String, Object> expectedString2Object = new HashMap<String, Object>();
    final Map<Object, String> expectedObject2String = new HashMap<Object, String>();
    final List<Object> idObjects = new ArrayList<Object>();
    final int length = 10;
    for (int ix = 0; ix < length; ix++) {
        final String object = RandomStringUtils.randomAlphanumeric(2 + ix);
        final String key = cut.buildCacheKey(object, data);
        idObjects.add(object);/*from   www.  j  a  v  a  2s.  co m*/
        expectedObject2String.put(object, key);
        expectedString2Object.put(key, object);
    }

    cut.setMethodStore(new CacheKeyMethodStoreImpl());
    final List<Object> exceptionObjects = new ArrayList<Object>(idObjects);
    exceptionObjects.add(null);
    try {
        cut.convertIdObjectsToKeyMap(exceptionObjects, data);
        fail("Expected Exception");
    } catch (InvalidParameterException ex) {
    }

    for (int ix = 0; ix < length; ix++) {
        if (ix % 2 == 0) {
            idObjects.add(idObjects.get(ix));
        }
    }
    assertTrue(idObjects.size() > length);

    final ReadThroughMultiCacheAdvice.MapHolder holder = cut.convertIdObjectsToKeyMap(idObjects, data);

    assertEquals(length, holder.getKey2Obj().size());
    assertEquals(length, holder.getObj2Key().size());

    assertEquals(expectedObject2String, holder.getObj2Key());
    assertEquals(expectedString2Object, holder.getKey2Obj());

    coord.setHolder(holder);

    assertEquals(expectedObject2String, coord.getObj2Key());
    assertEquals(expectedString2Object, coord.getKey2Obj());

}

From source file:com.splunk.shuttl.testutil.TUtilsFile.java

/**
 * Writes random alphanumeric content to specified file.
 * /*  w  ww  .j a va  2 s . co m*/
 * @param file
 */
public static void populateFileWithRandomContent(File file) {
    PrintStream printStream = null;
    try {
        printStream = new PrintStream(file);
        printStream.println(RandomStringUtils.randomAlphanumeric(1000));
        printStream.flush();
    } catch (FileNotFoundException e) {
        TUtilsTestNG.failForException("Failed to write random content", e);
    } finally {
        IOUtils.closeQuietly(printStream);
    }
}

From source file:com.cws.esolutions.security.dao.audit.impl.AuditDAOImplTest.java

@Test
public void auditRequestedOperation() {
    for (int x = 0; x < 50; x++) {
        List<String> auditList = new ArrayList<String>(Arrays.asList(RandomStringUtils.randomAlphanumeric(32),
                "junit", "f42fb0ba-4d1e-1126-986f-800cd2650000", "6236B840-88B0-4230-BCBC-8EC33EE837D9",
                "eSolutions-" + x, AuditType.JUNIT.name(), "junit", "junit"));

        try {//from  w w w .  ja  v  a  2 s.  c o m

            auditDAO.auditRequestedOperation(auditList);
        } catch (SQLException sqx) {
            Assert.fail(sqx.getMessage());
        }
    }
}

From source file:acromusashi.stream.example.topology.config.ConfigReloadSpout.java

/**
 * {@inheritDoc}/* w ww  .  ja  v a 2 s.c o m*/
 */
@Override
public void onNextTuple() {
    try {
        TimeUnit.MILLISECONDS.sleep(this.interval);
    } catch (InterruptedException ex) {
        return;
    }

    String key = RandomStringUtils.randomAlphanumeric(10);
    String message = RandomStringUtils.randomAlphanumeric(10);

    StreamMessage streamMessage = new StreamMessage();
    streamMessage.addField("Message", message);

    emit(streamMessage, key, key);
}

From source file:com.bstek.dorado.util.StringAliasUtils.java

/**
 * ???/*ww w.j  a  v  a  2s . c  o  m*/
 */
public static String getUniqueAlias(String s) {
    if (StringUtils.isEmpty(s)) {
        return "";
    }

    if (Configure.getBoolean("view.useStringAlias", false)) {
        String alias = stringMap.get(s);
        if (alias == null) {
            if (Configure.getBoolean("view.useRandomStringAlias", true)) {
                do {
                    alias = RandomStringUtils.randomAlphanumeric(10);
                } while (aliasMap.containsKey(alias));
            } else {
                alias = generateOrganizedAlias(s);
            }
            aliasMap.put(alias, s);
            stringMap.put(s, alias);
        }
        return alias;
    } else {
        return s;
    }
}

From source file:com.netflix.ndbench.core.generators.StringDataGenerator.java

@Override
public String getRandomString() {
    return RandomStringUtils.randomAlphanumeric(config.getDataSize());
}

From source file:com.xtructure.xutil.opt.UTestXOption.java

License:asdf

public void getNameReturnsExpectedObject() {
    String name = RandomStringUtils.randomAlphanumeric(10);
    assertThat("", //
            new DummyXOption(name, "opt", "longOpt", true, "description").getName(), //
            isEqualTo(name));/*from  w w w . j  a v  a  2 s  .c o  m*/
}