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.google.cloud.bigtable.hbase.ManyThreadDriver.java

private static void runTest(String projectId, String instanceId, final String tableName) throws Exception {
    Configuration configuration = new Configuration();
    configuration.set("hbase.client.connection.impl", "com.google.cloud.bigtable.hbase1_0.BigtableConnection");
    configuration.set("google.bigtable.project.id", projectId);
    configuration.set("google.bigtable.instance.id", instanceId);
    try (Connection connection = ConnectionFactory.createConnection(configuration)) {
        Admin admin = connection.getAdmin();

        HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(tableName));
        descriptor.addFamily(new HColumnDescriptor("cf"));
        try {//from  w  w  w  .  j a  va  2 s .c  o  m
            admin.createTable(descriptor);
        } catch (IOException ignore) {
            // Soldier on, maybe the table already exists.
        }

        final byte[] value = Bytes.toBytes(RandomStringUtils
                .randomAlphanumeric(Integer.parseInt(System.getProperty("valueSize", "1024"))));

        int numThreads = Integer.parseInt(System.getProperty("numThreads", "1000"));
        ExecutorService executor = Executors.newFixedThreadPool(numThreads);
        for (int i = 0; i < numThreads; i++) {
            Runnable r = new Runnable() {
                @Override
                public void run() {
                    try {
                        final Table table = connection.getTable(TableName.valueOf(tableName));

                        while (true) {
                            // Workload: two reads and a write.
                            table.get(new Get(Bytes.toBytes(key())));
                            table.get(new Get(Bytes.toBytes(key())));
                            Put p = new Put(Bytes.toBytes(key()));
                            p.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("col"), value);
                            table.put(p);
                        }
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                }
            };
            executor.execute(r);
        }

        // TODO Make a parameter
        executor.awaitTermination(48, TimeUnit.HOURS);
    }
}

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

/**
 * Generates a token.//w  w w. ja  v  a 2  s  .co m
 *
 * @return the generated user token
 */
public static String generateToken() {
    return RandomStringUtils.randomAlphanumeric(USER_TOKEN_COUNT);
}

From source file:com.google.cloud.bigtable.hbase.DataGenerationHelper.java

public byte[][] randomData(String prefix, int count) {
    byte[][] result = new byte[count][];
    for (int i = 0; i < count; ++i) {
        result[i] = Bytes.toBytes(prefix + RandomStringUtils.randomAlphanumeric(8));
    }/*from  www  .java 2  s .  c o m*/
    return result;
}

From source file:com.sun.syndication.propono.atom.server.impl.FileStore.java

public String getNextId() {
    //return UUID.randomUUID().toString(); // requires JDK 1.5
    return RandomStringUtils.randomAlphanumeric(20);
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.ValidationTest.java

@Test
public void randomProjectName() {
    Validation.validateProjectName(RandomStringUtils.randomAlphanumeric(Validation.MAX_PROJECT_NAME_LENGTH),
            null);
}

From source file:com.sun.identity.saml2.common.SAML2UtilsTest.java

@Test
public void encodeDecodeTest() {

    // the max length of each random String to encode
    int maxStringLength = 300;
    // the number of encode/decode iterations we want to test
    int randomStringsCount = 3000;
    Random R = new Random();

    int i = 0;/*from   ww  w.j a va 2s  . c om*/
    while (i < randomStringsCount) {
        int size = R.nextInt(maxStringLength);
        // We don't want any 0 length arrays
        while (size == 0) {
            size = R.nextInt(maxStringLength);
        }
        i++;
        String randomString = RandomStringUtils.randomAlphanumeric(size);
        String encoded = SAML2Utils.encodeForRedirect(randomString);
        String decoded = SAML2Utils.decodeFromRedirect(URLEncDec.decode(encoded));
        Assert.assertEquals(decoded, randomString);
    }
}

From source file:com.vaadin.tests.components.textfield.InputPromptGetTextTest.java

private String getRandomString() {
    String string = RandomStringUtils.randomAlphanumeric(3);
    return string;
}

From source file:com.xtructure.xutil.coll.UTestSetBuilder.java

public void getImmutableCollectionReturnsExpectedObject() {
    Set<String> set = new HashSet<String>();
    for (int i = 0; i < 10; i++) {
        set.add(RandomStringUtils.randomAlphanumeric(10));
    }// w  w  w  .ja v  a  2  s .  com
    Set<String> newSet = new SetBuilder<String>(set).newImmutableInstance();
    assertThat("", //
            set, isNotSameAs(newSet));
    assertThat("", //
            set, isEqualTo(newSet));
}

From source file:com.cloud.vm.dao.UserVmDaoImplTest.java

public void makeAndVerifyEntry(Long vmId, String instanceName, String displayName, long templateId,
        boolean userdataFlag, Hypervisor.HypervisorType hypervisor, long guestOsId, boolean haEnabled,
        boolean limitCpuUse, long domainId, long accountId, long serviceOfferingId, String name,
        Long diskOfferingId) {//from  www  . ja  v a 2  s.  c  o m

    dao.expunge(vmId);
    String userdata;

    if (userdataFlag) {
        // Generate large userdata to simulate 32k of random string data for userdata submitted through HTTP POST requests.
        userdata = RandomStringUtils.randomAlphanumeric(32 * 1024);
    } else {
        // Generate normal sized userdata to simulate 2k of random string data.
        userdata = RandomStringUtils.randomAlphanumeric(2 * 1024);
    }

    // Persist the data.
    UserVmVO vo = new UserVmVO(vmId, instanceName, displayName, templateId, hypervisor, guestOsId, haEnabled,
            limitCpuUse, domainId, accountId, 1, serviceOfferingId, userdata, name, diskOfferingId);
    dao.persist(vo);

    vo = dao.findById(vmId);
    assert (vo.getType() == VirtualMachine.Type.User) : "Incorrect type " + vo.getType();

    // Check whether the userdata matches what we generated.
    assert (vo.getUserData()
            .equals(userdata)) : "User data retrieved does not match userdata generated as input";

}

From source file:ca.quadrilateral.btester.propertygenerator.RandomStringPropertyGenerator.java

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