List of usage examples for org.apache.commons.lang3 RandomStringUtils randomAscii
public static String randomAscii(final int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of characters whose ASCII value is between 32 and 126 (inclusive).
From source file:com.blacklocus.qs.worker.RandomStdoutTasksExample.java
public static void main(String[] args) { // Mock our source of tasks. final BlockingQueue<QSTaskModel> workQueue = new SynchronousQueue<QSTaskModel>(); // Generates tasks new Thread(new ExceptingRunnable() { @Override//from ww w .j ava 2 s . c o m protected void go() throws Exception { while (true) { workQueue.put(new QSTaskModel(null, "" + RandomUtils.nextInt(), "stdout", 1, new Params(RandomStringUtils.randomAscii(RandomUtils.nextInt(32))))); } } }).start(); // All this worker does is log an extra message describing the length of the "message" param. QSWorker<Params> worker = new AbstractQSWorker<Params>() { @Override public String getHandlerName() { // This identifies the type of task this worker can handle. In our task generator above, the // tasks are created with the same handler identifier "stdout". return "stdout"; } @Override public TaskKit<Params> convert(TaskKitFactory<Params> factory) throws Exception { return factory.newTaskKit(Params.class); } @Override public Object process(TaskKit<Params> kit) throws Exception { String msg = kit.params().message; kit.log(msg + " is " + msg.length() + " characters long"); return null; } }; QSAssembly.newBuilder() // The source of work. .taskServices(new BlockingQueueQSTaskService(workQueue)) // Logging service which records task start, task-specific logging, task end. .logService(new SystemOutQSLogService()) // Service that helps identify the machine completing tasks, this machine. .workerIdService(new HostNameQSWorkerIdService()) // The worker logic observed by this instance. .workers(worker) // Run it in the current thread. .build().run(); }
From source file:com.monpie.histogram.RandomizeArray.java
@Override public void run() { try {/*from w w w. j a v a 2s . com*/ //losowanie liczb for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLUMNS; j++) { array[i][j] = RandomStringUtils.randomAscii(1); System.out.println(array[i][j]); fileWriter.write(array[i][j]); } fileWriter.write("\n"); } fileWriter.close(); } catch (IOException ex) { Logger.getLogger(RandomizeArray.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.radai.garbanzo.GarbanzoTest.java
@Test public void testRoundTrip() throws Exception { long seed = System.currentTimeMillis(); Random random = new Random(seed); BeanClass original = new BeanClass(); original.f1 = ""; original.f2 = RandomStringUtils.randomAscii(10); original.f3 = random.nextDouble();//from ww w . j av a2 s. com original.f4 = null; original.f5 = UUID.randomUUID(); original.f6 = new byte[1 + random.nextInt(10)]; random.nextBytes(original.f6); original.f7 = new ArrayList<>(); for (int i = 0; i < 5; i++) { original.f7.add((long) random.nextInt(10)); } original.f8 = new HashMap<>(); original.f8.put(Enum1.V1, (short) 7); original.f8.put(Enum1.V2, null); original.f9 = new ArrayList<>(); for (int i = 0; i < 3; i++) { InnerBeanClass inner = new InnerBeanClass(); inner.f1 = "bob " + i; original.f9.add(inner); } original.f9.add(null); String serialized = Garbanzo.marshal(original); BeanClass deserialized = Garbanzo.unmarshall(BeanClass.class, serialized); Assert.assertEquals(original, deserialized); }
From source file:com.qwazr.externalizor.SimpleCollection.java
public SimpleCollection() { nullList = null;//from ww w .ja v a 2s. c om stringList = new ArrayList<>(); for (int i = 0; i < RandomUtils.nextInt(5, 50); i++) stringList.add(RandomStringUtils.randomAscii(8)); nullSet = null; integerSet = new LinkedHashSet<>(); for (int i = 0; i < RandomUtils.nextInt(5, 50); i++) integerSet.add(RandomUtils.nextInt()); byteList = new Vector<>(); for (int i = 0; i < RandomUtils.nextInt(5, 50); i++) byteList.add((byte) RandomUtils.nextInt(0, 128)); nullMap = null; mapShortLong = new HashMap<>(); for (int i = 0; i < RandomUtils.nextInt(5, 50); i++) mapShortLong.put((short) RandomUtils.nextInt(0, Short.MAX_VALUE), RandomUtils.nextLong()); }
From source file:com.bazaarvoice.jolt.utils.StringToolsTest.java
@DataProvider(parallel = true) public Iterator<Object[]> testCaseGenerator() { List<Object[]> testCases = Lists.newArrayList(); testCases.add(new String[] { null, null }); testCases.add(new String[] { "", "" }); testCases.add(new String[] { null, "" }); testCases.add(new String[] { "", null }); testCases.add(new String[] { RandomStringUtils.randomAscii(1 << 2), null }); testCases.add(new String[] { RandomStringUtils.randomAscii(1 << 2), "" }); testCases.add(new String[] { null, RandomStringUtils.randomAscii(1 << 2) }); testCases.add(new String[] { "", RandomStringUtils.randomAscii(1 << 2) }); int i = 1 << 6; while (i-- > 0) { testCases.add(// w w w. j av a2 s . c o m new String[] { RandomStringUtils.randomAscii(1 << 10), RandomStringUtils.randomAscii(1 << 2) }); testCases.add( new String[] { RandomStringUtils.randomAscii(1 << 2), RandomStringUtils.randomAscii(1 << 10) }); testCases.add(new String[] { RandomStringUtils.randomAlphabetic(1 << 10), RandomStringUtils.randomAlphabetic(1 << 2) }); testCases.add(new String[] { RandomStringUtils.randomAlphabetic(1 << 2), RandomStringUtils.randomAlphabetic(1 << 10) }); testCases.add(new String[] { RandomStringUtils.randomAlphanumeric(1 << 10), RandomStringUtils.randomAlphanumeric(1 << 2) }); testCases.add(new String[] { RandomStringUtils.randomAlphanumeric(1 << 2), RandomStringUtils.randomAlphanumeric(1 << 10) }); } return testCases.iterator(); }
From source file:com.qwazr.externalizor.ComplexExample.java
public ComplexExample() { nullObject = null;//from ww w.j a v a 2 s . c o m collection = new SimpleCollection(); abstractCollection = new AbstractCollection(); mapObject = new HashMap<>(); for (int i = 0; i < RandomUtils.nextInt(2, 5); i++) mapObject.put(RandomStringUtils.randomAscii(5), new SimplePrimitive()); noEmptyConstructor = new NoEmptyConstructorSerial(RandomStringUtils.randomAscii(5)); noEmptyConstructorNull = null; timeObject = new SimpleTime(); transientValue = RandomStringUtils.randomAscii(12); }
From source file:com.blacklocus.jres.JresBulkRequestorTest.java
@Test public void testBulkRequestor() throws InterruptedException, ExecutionException, IOException { // best for this to be a multiple of 4 int batchSize = 4; String index = "JresBulkRequestorTest.testBulkRequestor".toLowerCase(); String type = "test"; // Specify default index, but not default type. JresBulkRequestor bulkRequestor = new JresBulkRequestor(batchSize, 1000, 1, index, jres).start(); List<Future<?>> futures = new ArrayList<Future<?>>(); // hang on to some docs so we can issue update operations List<Document> docs = new ArrayList<Document>(batchSize); for (int i = 0; i < batchSize; i++) { Document doc = new Document(); docs.add(doc);/*from www . jav a 2 s . c o m*/ futures.add(bulkRequestor.put(new JresIndexDocument(index, type, doc.id, doc))); } // batch filled, buffer should flush for (int i = 0; i < batchSize; i++) { Document doc = docs.get(i); doc.name = RandomStringUtils.randomAscii(8) + ".mp3"; futures.add(bulkRequestor.put(new JresUpdateDocument(index, type, doc.id, doc, false, 0))); } // batch filled, buffer should flush for (int i = 0; i < batchSize / 4; i++) { // add 2 mixed operations Document newDoc = new Document(); docs.add(newDoc); futures.add(bulkRequestor.put(new JresIndexDocument(index, type, newDoc))); Document updateDoc = docs.get(i); updateDoc.name = "Hi, my name is " + updateDoc.name; // null index for fun, since it was specified in the JresBulkRequestor constructor. This should still work. futures.add(bulkRequestor.put(new JresUpdateDocument(null, type, updateDoc.id, updateDoc))); } // Some broken operations, conflicting schema. for (int i = 0; i < batchSize / 4; i++) { futures.add(bulkRequestor.put(new JresIndexDocument(index, type, new ConflictingDocument()))); } // Batch not filled (actually only 3/4 full). Closing the requestor should block until buffers are flushed. bulkRequestor.close(); jres.quest(new JresRefresh(index)); JresSearchReply searchReply = jres.quest(new JresSearch(index)); Assert.assertEquals(docs.size(), searchReply.getHits().getTotal().intValue()); int validFutures = futures.size() - batchSize / 4; int failedFutures = batchSize / 4; Assert.assertEquals("All futures accounted for (test logic itself)", futures.size(), validFutures + failedFutures); for (int i = 0; i < validFutures; i++) { futures.get(i).get(); // successful } for (int i = validFutures; i < futures.size(); i++) { try { futures.get(i).get(); Assert.fail("Future should have excepted"); } catch (Exception e) { // good LOG.debug("Failed future was expected and had this exception", e); } } }
From source file:gov.va.chir.tagline.dao.FileDao.java
public static void createSyntheticTrainingDataset(final File file, final int nDocs, final int maxLinesPerDoc, final int maxLineLength, final int nClasses, final long seed) throws IOException { final String[] classes = new String[nClasses]; for (int i = 0; i < classes.length; i++) { classes[i] = String.format("%s%d", "class", i); }/*from w w w .ja v a2 s. c o m*/ final Random random = new Random(seed); final List<String> lines = new ArrayList<String>(); lines.add((nClasses > 0 ? "note_id\tline_id\tclass\ttext" : "note_id\tline_id\ttext")); for (int i = 0; i < nDocs; i++) { // How many lines in this doc final int lineNum = random.nextInt(maxLinesPerDoc) + 1; for (int j = 0; j < lineNum; j++) { final String text = RandomStringUtils.randomAscii(random.nextInt(maxLineLength) + 1); if (nClasses > 0) { lines.add(String.format("%d\t%d\t%s\t%s", i, j, classes[random.nextInt(classes.length)], text.replace("\\", " "))); } else { lines.add(String.format("%d\t%d\t%s", i, j, text.replace("\\", " "))); } } } FileUtils.writeLines(file, lines, false); }
From source file:com.dlej.Main.java
private static List<Character> randomRepresentation(int length) { return asList(RandomStringUtils.randomAscii(length)); }
From source file:com.qwazr.externalizor.SimpleLang.java
public SimpleLang() { emptyString = StringUtils.EMPTY;/* ww w. j av a 2 s. co m*/ stringValue = RandomStringUtils.randomAscii(8); stringNullValue = null; stringArray = new String[RandomUtils.nextInt(5, 20)]; stringArray[0] = null; for (int i = 1; i < stringArray.length; i++) stringArray[i] = RandomStringUtils.randomAscii(5); stringList = new ArrayList(Arrays.asList(stringArray)); intLangValue = RandomUtils.nextInt(); intNullValue = null; intArray = new Integer[RandomUtils.nextInt(5, 20)]; intArray[0] = null; for (int i = 1; i < intArray.length; i++) intArray[i] = RandomUtils.nextInt(); intList = new ArrayList(Arrays.asList(intArray)); shortLangValue = (short) RandomUtils.nextInt(0, Short.MAX_VALUE); shortNullValue = null; shortArray = new Short[RandomUtils.nextInt(5, 20)]; shortArray[0] = null; for (int i = 1; i < shortArray.length; i++) shortArray[i] = (short) RandomUtils.nextInt(0, Short.MAX_VALUE); shortList = new ArrayList(Arrays.asList(shortArray)); longLangValue = RandomUtils.nextLong(); longNullValue = null; longArray = new Long[RandomUtils.nextInt(5, 20)]; longArray[0] = null; for (int i = 1; i < longArray.length; i++) longArray[i] = RandomUtils.nextLong(); longList = new ArrayList(Arrays.asList(longArray)); floatLangValue = (float) RandomUtils.nextFloat(); floatNullValue = null; floatArray = new Float[RandomUtils.nextInt(5, 20)]; floatArray[0] = null; for (int i = 1; i < floatArray.length; i++) floatArray[i] = RandomUtils.nextFloat(); floatList = new ArrayList(Arrays.asList(floatArray)); doubleLangValue = RandomUtils.nextDouble(); doubleNullValue = null; doubleArray = new Double[RandomUtils.nextInt(5, 20)]; doubleArray[0] = null; for (int i = 1; i < doubleArray.length; i++) doubleArray[i] = RandomUtils.nextDouble(); doubleList = new ArrayList(Arrays.asList(doubleArray)); booleanLangValue = RandomUtils.nextInt(0, 1) == 0; booleanNullValue = null; booleanArray = new Boolean[RandomUtils.nextInt(5, 20)]; booleanArray[0] = null; for (int i = 1; i < booleanArray.length; i++) booleanArray[i] = RandomUtils.nextBoolean(); booleanList = new ArrayList(Arrays.asList(booleanArray)); byteLangValue = (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE); byteNullValue = null; byteArray = new Byte[RandomUtils.nextInt(5, 20)]; byteArray[0] = null; for (int i = 1; i < byteArray.length; i++) byteArray[i] = (byte) RandomUtils.nextInt(0, Byte.MAX_VALUE); byteList = new ArrayList(Arrays.asList(byteArray)); charLangValue = (char) RandomUtils.nextInt(0, Character.MAX_VALUE); charNullValue = null; charArray = new Character[RandomUtils.nextInt(5, 20)]; charArray[0] = null; for (int i = 1; i < charArray.length; i++) charArray[i] = (char) RandomUtils.nextInt(0, Character.MAX_VALUE); charList = new ArrayList(Arrays.asList(charArray)); enumNull = null; enumValue = RandomUtils.nextInt(0, 1) == 0 ? EnumType.on : EnumType.off; enumArray = new EnumType[RandomUtils.nextInt(5, 20)]; enumArray[0] = null; for (int i = 1; i < enumArray.length; i++) enumArray[i] = RandomUtils.nextInt(0, 1) == 0 ? EnumType.on : EnumType.off; enumList = new ArrayList(Arrays.asList(enumArray)); }