List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphabetic
public static String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alphabetic characters.
From source file:org.apache.hadoop.hdfs.util.TestPosixUserNameChecker.java
@Test public void test() { check("abc", true); check("a_bc", true); check("a1234bc", true); check("a1234bc45", true); check("_a1234bc45$", true); check("_a123-4bc45$", true); check("abc_", true); check("ab-c_$", true); check("_abc", true); check("ab-c$", true); check("-abc", false); check("-abc_", false); check("a$bc", false); check("9abc", false); check("-abc", false); check("$abc", false); check("", false); check(null, false);/*from ww w . ja v a 2s . c o m*/ check(RandomStringUtils.randomAlphabetic(100).toLowerCase(), true); check(RandomStringUtils.randomNumeric(100), false); check("a" + RandomStringUtils.randomNumeric(100), true); check("_" + RandomStringUtils.randomNumeric(100), true); check("a" + RandomStringUtils.randomAlphanumeric(100).toLowerCase(), true); check("_" + RandomStringUtils.randomAlphanumeric(100).toLowerCase(), true); check(RandomStringUtils.random(1000), false); //unicode }
From source file:org.apache.hadoop.tracing.TestTracing.java
private void writeTestFile(String testFileName) throws Exception { Path filePath = new Path(testFileName); FSDataOutputStream stream = dfs.create(filePath); for (int i = 0; i < 10; i++) { byte[] data = RandomStringUtils.randomAlphabetic(102400).getBytes(); stream.write(data);//from w w w. jav a 2 s .c o m } stream.hsync(); stream.close(); }
From source file:org.apache.kylin.measure.topn.TopNCounterTest.java
protected String prepareTestDate() throws IOException { String[] allKeys = new String[KEY_SPACE]; for (int i = 0; i < KEY_SPACE; i++) { allKeys[i] = RandomStringUtils.randomAlphabetic(10); }/*from w ww.ja v a 2 s . c o m*/ outputMsg("Start to create test random data..."); long startTime = System.currentTimeMillis(); ZipfDistribution zipf = new ZipfDistribution(KEY_SPACE, 0.5); int keyIndex; File tempFile = File.createTempFile("ZipfDistribution", ".txt"); if (tempFile.exists()) FileUtils.forceDelete(tempFile); FileWriter fw = new FileWriter(tempFile); try { for (int i = 0; i < TOTAL_RECORDS; i++) { keyIndex = zipf.sample() - 1; fw.write(allKeys[keyIndex]); fw.write('\n'); } } finally { if (fw != null) fw.close(); } outputMsg("Create test data takes : " + (System.currentTimeMillis() - startTime) / 1000 + " seconds."); outputMsg("Test data in : " + tempFile.getAbsolutePath()); return tempFile.getAbsolutePath(); }
From source file:org.apache.phoenix.query.BaseTest.java
protected static String generateRandomString() { return RandomStringUtils.randomAlphabetic(20).toUpperCase(); }
From source file:org.apache.sling.models.impl.ResourceModelClassesTest.java
@Test public void testChildModel() { Object firstValue = RandomStringUtils.randomAlphabetic(10); ValueMap firstMap = new ValueMapDecorator(Collections.singletonMap("property", firstValue)); final Resource firstChild = mock(Resource.class); when(firstChild.adaptTo(ValueMap.class)).thenReturn(firstMap); when(firstChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); Object firstGrandChildValue = RandomStringUtils.randomAlphabetic(10); ValueMap firstGrandChildMap = new ValueMapDecorator( Collections.singletonMap("property", firstGrandChildValue)); Object secondGrandChildValue = RandomStringUtils.randomAlphabetic(10); ValueMap secondGrandChildMap = new ValueMapDecorator( Collections.singletonMap("property", secondGrandChildValue)); final Resource firstGrandChild = mock(Resource.class); when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap); when(firstGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); final Resource secondGrandChild = mock(Resource.class); when(secondGrandChild.adaptTo(ValueMap.class)).thenReturn(secondGrandChildMap); when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); Resource secondChild = mock(Resource.class); when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator()); Resource emptyChild = mock(Resource.class); when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator()); Resource res = mock(Resource.class); when(res.getChild("firstChild")).thenReturn(firstChild); when(res.getChild("secondChild")).thenReturn(secondChild); when(res.getChild("emptyChild")).thenReturn(emptyChild); ParentModel model = factory.getAdapter(res, ParentModel.class); assertNotNull(model);// w ww . j a v a 2 s.co m ChildModel childModel = model.getFirstChild(); assertNotNull(childModel); assertEquals(firstValue, childModel.getProperty()); assertEquals(2, model.getGrandChildren().size()); assertEquals(firstGrandChildValue, model.getGrandChildren().get(0).getProperty()); assertEquals(secondGrandChildValue, model.getGrandChildren().get(1).getProperty()); assertEquals(0, model.getEmptyGrandChildren().size()); }
From source file:org.apache.sling.models.impl.ResourceModelInterfacesTest.java
@Test public void testChildModel() { Object value = RandomStringUtils.randomAlphabetic(10); Map<String, Object> props = Collections.singletonMap("property", value); ValueMap map = new ValueMapDecorator(props); final Resource firstChild = mock(Resource.class); when(firstChild.adaptTo(ValueMap.class)).thenReturn(map); when(firstChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); Object firstGrandChildValue = RandomStringUtils.randomAlphabetic(10); ValueMap firstGrandChildMap = new ValueMapDecorator( Collections.singletonMap("property", firstGrandChildValue)); Object secondGrandChildValue = RandomStringUtils.randomAlphabetic(10); ValueMap secondGrandChildMap = new ValueMapDecorator( Collections.singletonMap("property", secondGrandChildValue)); final Resource firstGrandChild = mock(Resource.class); when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap); when(firstGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); final Resource secondGrandChild = mock(Resource.class); when(secondGrandChild.adaptTo(ValueMap.class)).thenReturn(secondGrandChildMap); when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); Resource secondChild = mock(Resource.class); when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator()); Resource emptyChild = mock(Resource.class); when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator()); Resource res = mock(Resource.class); when(res.getChild("firstChild")).thenReturn(firstChild); when(res.getChild("secondChild")).thenReturn(secondChild); when(res.getChild("emptyChild")).thenReturn(emptyChild); ParentModel model = factory.getAdapter(res, ParentModel.class); assertNotNull(model);//from w w w. j a v a 2 s . c o m ChildModel childModel = model.getFirstChild(); assertNotNull(childModel); assertEquals(value, childModel.getProperty()); assertEquals(2, model.getGrandChildren().size()); assertEquals(firstGrandChildValue, model.getGrandChildren().get(0).getProperty()); assertEquals(secondGrandChildValue, model.getGrandChildren().get(1).getProperty()); assertEquals(0, model.getEmptyGrandChildren().size()); }
From source file:org.apache.usergrid.chop.webapp.ChopUiTestUtils.java
static void testRunnerRegistrySequence(TestParams testParams) { /*//from w w w .j a v a 2 s.c o m * ------------------------------------------------------------ * Let's register a runner first before we query for it * ------------------------------------------------------------ */ String commitId = UUID.randomUUID().toString(); String hostname = RandomStringUtils.randomAlphabetic(8); RunnerBuilder builder = new RunnerBuilder(); builder.setTempDir(".").setServerPort(19023).setUrl("https://localhost:19023").setHostname(hostname) .setIpv4Address("127.0.0.1"); Boolean result = testParams.addQueryParameters(QUERY_PARAMS).setEndpoint(RunnerRegistryResource.ENDPOINT) .newWebResource(null).queryParam(RestParams.COMMIT_ID, commitId).path("/register") .type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE) .post(Boolean.class, builder.getRunner()); assertTrue(result); /* * ------------------------------------------------------------ * Let's see if we can get the runner back from the registry * ------------------------------------------------------------ */ List<Runner> runnerList = testParams.setEndpoint(RunnerRegistryResource.ENDPOINT).newWebResource(null) .queryParam(RestParams.COMMIT_ID, commitId).path("/list").type(MediaType.APPLICATION_JSON_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE).get(new GenericType<List<Runner>>() { }); assertNotNull(runnerList); assertEquals(1, runnerList.size()); Runner runner = runnerList.get(0); assertEquals(19023, runner.getServerPort()); assertEquals("https://localhost:19023", runner.getUrl()); assertEquals(hostname, runner.getHostname()); assertEquals("127.0.0.1", runner.getIpv4Address()); assertEquals(".", runner.getTempDir()); /* * ------------------------------------------------------------ * Let's unregister the runner from the registry and check * ------------------------------------------------------------ */ result = testParams.newWebResource(null).queryParam(RestParams.RUNNER_URL, runner.getUrl()) .path("/unregister").type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE) .post(Boolean.class); assertTrue(result); /* * ------------------------------------------------------------ * Let's make sure we do NOT get the runner from the registry * ------------------------------------------------------------ */ runnerList.clear(); runnerList = testParams.setEndpoint(RunnerRegistryResource.ENDPOINT).newWebResource(null) .queryParam(RestParams.COMMIT_ID, commitId).path("/list").type(MediaType.APPLICATION_JSON_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE).get(new GenericType<List<Runner>>() { }); assertNotNull(runnerList); assertEquals(0, runnerList.size()); }
From source file:org.apache.usergrid.management.importer.S3ImportImpl.java
public File copyFileFromBucket(String blobFileName, String bucketName, String accessId, String secretKey) throws Exception { // setup to use JCloud BlobStore interface to AWS S3 Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); final Iterable<? extends Module> MODULES = ImmutableSet.of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES) .overrides(overrides).buildView(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); // get file from configured bucket, copy it to local temp file Blob blob = blobStore.getBlob(bucketName, blobFileName); if (blob == null) { throw new RuntimeException("Blob file name " + blobFileName + " not found in bucket " + bucketName); }/*from w w w. ja v a 2 s. c o m*/ FileOutputStream fop = null; File tempFile; try { tempFile = File.createTempFile(bucketName, RandomStringUtils.randomAlphabetic(10)); tempFile.deleteOnExit(); fop = new FileOutputStream(tempFile); InputStream is = blob.getPayload().openStream(); IOUtils.copyLarge(is, fop); return tempFile; } finally { if (fop != null) { fop.close(); } } }
From source file:org.apache.usergrid.persistence.index.impl.EsProvider.java
/** * Create the transport client/*from w w w . ja v a 2 s. c o m*/ * @return */ private Client createTransportClient() { final String clusterName = indexFig.getClusterName(); final int port = indexFig.getPort(); ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName) .put("client.transport.sniff", true); String nodeName = indexFig.getNodeName(); if ("default".equals(nodeName)) { // no nodeName was specified, use hostname try { nodeName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex) { nodeName = "client-" + RandomStringUtils.randomAlphabetic(8); logger.warn("Couldn't get hostname to use as ES node name, using {}", nodeName); } } settings.put("node.name", nodeName); TransportClient transportClient = new TransportClient(settings.build()); // we will connect to ES on all configured hosts for (String host : indexFig.getHosts().split(",")) { transportClient.addTransportAddress(new InetSocketTransportAddress(host, port)); } return transportClient; }
From source file:org.apache.usergrid.rest.applications.queries.SelectMappingsQueryTest.java
/** * When entity posted with two duplicate names with different cases, last one wins. *//*ww w . jav a 2s . co m*/ @Test public void testMixedCaseDupField() throws Exception { String collectionName = "things"; String value = RandomStringUtils.randomAlphabetic(20); String otherValue = RandomStringUtils.randomAlphabetic(20); // create entity with testProp=value Entity entity = new Entity().withProp("testProp", value).withProp("TESTPROP", otherValue); app().collection(collectionName).post(entity); refreshIndex(); // testProp and TESTPROP should now have otherValue QueryParameters params = new QueryParameters().setQuery("select * where testProp='" + otherValue + "'"); Collection things = this.app().collection("things").get(params); assertEquals(1, things.getNumOfEntities()); params = new QueryParameters().setQuery("select * where TESTPROP='" + otherValue + "'"); things = app().collection("things").get(params); assertEquals(1, things.getNumOfEntities()); }