/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of characters whose * ASCII value is between {@code 32} and {@code 126} (inclusive).</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomAscii(final int minLengthInclusive, final int maxLengthExclusive) { return randomAscii(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
public Label[] getLabels() { int randomLabelValue = ThreadLocalRandom.current().nextInt( 2 ) + 1; Label[] labels = new Label[randomLabelValue]; for ( int i = 0; i < labels.length; i++ ) { labels[i] = Label.label( RandomStringUtils.randomAscii( randomLabelValue ) ); } return labels; }
public synchronized void recalculateChecksum() { List<IpAddress> ips = allIPs(); StringBuilder ipsString = new StringBuilder(); ipsString.append(getDomString()); Loggers.SRV_LOG.debug("dom to json: " + getDomString()); if (!CollectionUtils.isEmpty(ips)) { Collections.sort(ips); } for (IpAddress ip : ips) { String string = ip.getIp() + ":" + ip.getPort() + "_" + ip.getWeight() + "_" + ip.isValid() + "_" + ip.getClusterName(); ipsString.append(string); ipsString.append(","); } try { String result; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); result = new BigInteger(1, md5.digest((ipsString.toString()).getBytes(Charset.forName("UTF-8")))).toString(16); } catch (Exception e) { Loggers.SRV_LOG.error("[NACOS-DOM] error while calculating checksum(md5)", e); result = RandomStringUtils.randomAscii(32); } checksum = result; } catch (Exception e) { Loggers.SRV_LOG.error("[NACOS-DOM] error while calculating checksum(md5)", e); checksum = RandomStringUtils.randomAscii(32); } }
@Override protected boolean doAction() throws Exception { Put p = new Put(Bytes.toBytes(RandomStringUtils.randomAlphanumeric(5))); p.addColumn(FAMILY, Bytes.toBytes("\0"), Bytes.toBytes(RandomStringUtils.randomAscii(5))); table.put(p); return true; }
/** * Make sure 32 and 127 are generated by randomNumeric * This test will fail randomly with probability = 2*(95/96)**1000 ~ 5.7E-5 */ @Test public void testRandomAscii() { final char[] testChars = {(char) 32, (char) 126}; final boolean[] found = {false, false}; for (int i = 0; i < 100; i++) { final String randString = RandomStringUtils.randomAscii(10); for (int j = 0; j < testChars.length; j++) { if (randString.indexOf(testChars[j]) > 0) { found[j] = true; } } } for (int i = 0; i < testChars.length; i++) { if (!found[i]) { fail("ascii character not generated in 1000 attempts: " + (int) testChars[i] + " -- repeated failures indicate a problem"); } } }
@Test public void testRandomAsciiRange() { final int expectedMinLengthInclusive = 1; final int expectedMaxLengthExclusive = 11; final String pattern = "^\\p{ASCII}{" + expectedMinLengthInclusive + ',' + expectedMaxLengthExclusive + "}$"; int maxCreatedLength = expectedMinLengthInclusive; int minCreatedLength = expectedMaxLengthExclusive - 1; for (int i = 0; i < 1000; i++) { final String s = RandomStringUtils.randomAscii(expectedMinLengthInclusive, expectedMaxLengthExclusive); assertThat("within range", s.length(), allOf(greaterThanOrEqualTo(expectedMinLengthInclusive), lessThanOrEqualTo(expectedMaxLengthExclusive - 1))); assertTrue(s, s.matches(pattern)); if (s.length() < minCreatedLength) { minCreatedLength = s.length(); } if (s.length() > maxCreatedLength) { maxCreatedLength = s.length(); } } assertThat("min generated, may fail randomly rarely", minCreatedLength, is(expectedMinLengthInclusive)); assertThat("max generated, may fail randomly rarely", maxCreatedLength, is(expectedMaxLengthExclusive - 1)); }
assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAscii(50); assertEquals("randomAscii(50) length", 50, r1.length()); for(int i = 0; i < r1.length(); i++) { assertTrue("char between 32 and 127", r1.charAt(i) >= 32 && r1.charAt(i) <= 127); r2 = RandomStringUtils.randomAscii(50); assertTrue("!r1.equals(r2)", !r1.equals(r2));
@Test void stringWithMaximumLengthShouldBeAllowed() { String longestString = RandomStringUtils.randomAscii( IndexWriter.MAX_TERM_LENGTH ); Document document = documentRepresentingProperties( (long) 123, longestString ); assertEquals( longestString, document.getField( String.key( 0 ) ).stringValue() ); }
@Test public void takeLabelLockForQueryWithIndexUsages() throws Exception { String labelName = "Human"; Label human = Label.label( labelName ); String propertyKey = "name"; createIndex( human, propertyKey ); try ( Transaction transaction = databaseRule.beginTx() ) { Node node = databaseRule.createNode( human ); node.setProperty( propertyKey, RandomStringUtils.randomAscii( 10 ) ); transaction.success(); } String query = "MATCH (n:" + labelName + ") where n." + propertyKey + " = \"Fry\" RETURN n "; List<LockOperationRecord> lockOperationRecords = traceQueryLocks( query ); assertThat( "Observed list of lock operations is: " + lockOperationRecords, lockOperationRecords, hasSize( 1 ) ); LockOperationRecord operationRecord = lockOperationRecords.get( 0 ); assertTrue( operationRecord.acquisition ); assertFalse( operationRecord.exclusive ); assertEquals( ResourceTypes.LABEL, operationRecord.resourceType ); }
node.setProperty( propertyKey, RandomStringUtils.randomAscii( 10 ) ); transaction.success();
String propertyValue = RandomStringUtils.randomAscii( 255 );
String propertyValue = RandomStringUtils.randomAscii( 255 );
public FunctionTransformationContainer(Class<? extends V> clazz, V inst) { this.key = RandomStringUtils.randomAscii(10); this.clazz = clazz; this.inst = inst; }
@Override public void run() { OrangeContext context = new OrangeContext(); Sleeper sleeper = new Sleeper(); try { while (produceMessages.get()) { String key = RandomStringUtils.randomAscii(5); SayHelloToCmd payload = SayHelloToCmd.newBuilder().setName(key).build(); Message request = Messages.requestFor(ping, pong, key, payload, context); producer.send(request); sentMessages.incrementAndGet(); sleeper.sleepNoException(250); } } catch (Throwable t) { logger.error("Exception in producer loop", t); } } });
@Override public String next() { int size = rand.nextInt(maxLength - minLength + 1) + minLength; return RandomStringUtils.randomAscii(size); }
for (int i = 0; i < N; i++) { SayHelloToCmd cmd = SayHelloToCmd.newBuilder().setName(Integer.toString(i)).build(); Message request = Messages.requestFor(ping, pong, RandomStringUtils.randomAscii(5), cmd, new OrangeContext()); producer.send(request);
String key = RandomStringUtils.randomAscii(5); SayHelloToCmd payload = SayHelloToCmd.newBuilder().setName(key).build();
SearchThread(Set<String> needles, int numHaystack, ValueFilterContains filter) { this.needles = needles; this.filter = filter; this.haystack = new ArrayList<>(needles); for (int i = needles.size(); i < numHaystack; i++) { String candidate = RandomStringUtils.randomAscii(20); if (!needles.contains(candidate)) { haystack.add(candidate); } } Collections.shuffle(haystack); }
@Ignore @Test public void producerSendsToNonExistingTopic() { ServiceProperties serviceProperties = fillServiceProperties(); Topic cruft = new Topic("cruft"); Topic lard = new Topic("lard"); Producer producer = new ProducerFactory(serviceProperties).createProducer(); String key = RandomStringUtils.randomAscii(5); SayHelloToCmd payload = SayHelloToCmd.newBuilder().setName(key).build(); Message request = Messages.requestFor(cruft, lard, key, payload, new OrangeContext()); producer.send(request); // Results: // 1.) NO topic auto creation i.e. KAFKA_AUTO_CREATE_TOPICS_ENABLE = false // 2017-04-12 18:14:41,239 [Time-limited test] DEBUG c.s.s.f.kafka.messaging.Producer - Sending message com.sixt.service.framework.kafka.messaging.SayHelloToCmd with key O+oRQ to topic cruft // loads of: 2017-04-12 18:14:41,340 [kafka-producer-network-thread | producer-2] WARN o.apache.kafka.clients.NetworkClient - Error while fetching metadata with correlation id 0 : {cruft=UNKNOWN_TOPIC_OR_PARTITION} // and finally: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms. // 2.) WITH topic auto creation i.e. KAFKA_AUTO_CREATE_TOPICS_ENABLE = true // 2017-04-12 18:18:24,488 [Time-limited test] DEBUG c.s.s.f.kafka.messaging.Producer - Sending message com.sixt.service.framework.kafka.messaging.SayHelloToCmd with key uXdJ~ to topic cruft // one: 2017-04-12 18:18:24,638 [kafka-producer-network-thread | producer-2] WARN o.apache.kafka.clients.NetworkClient - Error while fetching metadata with correlation id 0 : {cruft=LEADER_NOT_AVAILABLE // and finally: success }
public Customer createAnonymousCustomer() throws DataAccessException { Customer customer = customerService.createNewCustomer(); customer.setUsername(String.valueOf(customer.getId())); customer.setPassword(RandomStringUtils.randomAscii(8)); return customerService.saveCustomer(customer); }