List of usage examples for java.util Random nextLong
public long nextLong()
From source file:com.luorrak.ouroboros.catalog.CatalogActivity.java
private void initPostPassword() { if (SettingsHelper.getPostPassword(getApplicationContext()).equals("")) { Random random = new Random(); SettingsHelper.setPostPassword(getApplicationContext(), Long.toHexString(random.nextLong())); }/* w ww . j a v a 2 s. c om*/ }
From source file:org.apache.hadoop.security.Krb5AndCertsSslSocketConnector.java
private void setPasswords() { if (!useCerts) { Random r = new Random(); System.setProperty("jetty.ssl.password", String.valueOf(r.nextLong())); System.setProperty("jetty.ssl.keypassword", String.valueOf(r.nextLong())); }/*from w w w .ja v a 2 s. co m*/ }
From source file:org.apache.hadoop.hbase.master.procedure.TestProcedureAdmin.java
@Test(timeout = 60000) public void testAbortNonExistProcedure() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); Random randomGenerator = new Random(); long procId;//from w w w. j a v a 2 s . c om // Generate a non-existing procedure do { procId = randomGenerator.nextLong(); } while (procExec.getResult(procId) != null); boolean abortResult = procExec.abort(procId, true); assertFalse(abortResult); }
From source file:org.apache.hadoop.mapred.TestCombineTextInputFormat.java
@Test(timeout = 10000) public void testFormat() throws Exception { JobConf job = new JobConf(defaultConf); Random random = new Random(); long seed = random.nextLong(); LOG.info("seed = " + seed); random.setSeed(seed);//w ww. j a v a2s . c om localFs.delete(workDir, true); FileInputFormat.setInputPaths(job, workDir); final int length = 10000; final int numFiles = 10; createFiles(length, numFiles, random); // create a combined split for the files CombineTextInputFormat format = new CombineTextInputFormat(); LongWritable key = new LongWritable(); Text value = new Text(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(length / 20) + 1; LOG.info("splitting: requesting = " + numSplits); InputSplit[] splits = format.getSplits(job, numSplits); LOG.info("splitting: got = " + splits.length); // we should have a single split as the length is comfortably smaller than // the block size assertEquals("We got more than one splits!", 1, splits.length); InputSplit split = splits[0]; assertEquals("It should be CombineFileSplit", CombineFileSplit.class, split.getClass()); // check the split BitSet bits = new BitSet(length); LOG.debug("split= " + split); RecordReader<LongWritable, Text> reader = format.getRecordReader(split, job, voidReporter); try { int count = 0; while (reader.next(key, value)) { int v = Integer.parseInt(value.toString()); LOG.debug("read " + v); if (bits.get(v)) { LOG.warn("conflict with " + v + " at position " + reader.getPos()); } assertFalse("Key in multiple partitions.", bits.get(v)); bits.set(v); count++; } LOG.info("splits=" + split + " count=" + count); } finally { reader.close(); } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }
From source file:com.moz.fiji.mapreduce.IntegrationTestFijiBulkLoad.java
/** * Generates a random HDFS path.//ww w . j a va 2 s . c om * * @param prefix Prefix for the random file name. * @return a random HDFS path. * @throws Exception on error. */ private Path makeRandomPath(String prefix) throws Exception { Preconditions.checkNotNull(mFS); final Path base = new Path(FileSystem.getDefaultUri(mConf)); final Random random = new Random(System.nanoTime()); return new Path(base, String.format("/%s-%s", prefix, random.nextLong())); }
From source file:org.drools.util.BinaryHeapPriorityQueueTest.java
public void xxxtestBasic() { final Random random = new Random(); final List items = new LinkedList(); final BinaryHeap queue = new BinaryHeap(); for (int i = 0; i < 100000; ++i) { items.add(new LongQueueable(random.nextLong())); }/*from ww w . jav a 2s . co m*/ final long startEnqueue = System.currentTimeMillis(); for (final Iterator i = items.iterator(); i.hasNext();) { queue.add(i.next()); } final long elapsedEnqueue = System.currentTimeMillis() - startEnqueue; final long startDequeue = System.currentTimeMillis(); for (final Iterator i = items.iterator(); i.hasNext();) { queue.remove(i.next()); } // while (!queue.isEmpty()) { // queue.pop(); // } final long elapsedDequeue = System.currentTimeMillis() - startDequeue; System.out.println("elapsedEnqueue = " + elapsedEnqueue); System.out.println("elapsedDequeue = " + elapsedDequeue); }
From source file:org.sakaiproject.kernel.test.ObservationKernelUnitT.java
/** * @param request/*from www .j av a 2s . co m*/ * @param response * @param session */ private void setupRequest(HttpServletRequest request, HttpServletResponse response, HttpSession session, String userName) { Random r = new Random(); long sessionID = r.nextLong(); User u = new InternalUser(userName); expect(request.getRemoteUser()).andReturn(userName).anyTimes(); expect(request.getSession()).andReturn(session).anyTimes(); expect(request.getSession(true)).andReturn(session).anyTimes(); expect(request.getSession(false)).andReturn(session).anyTimes(); expect(session.getId()).andReturn(userName + "SESSIONID-123" + sessionID).anyTimes(); expect(request.getRequestedSessionId()).andReturn(userName + "SESSIONID-123" + sessionID).anyTimes(); Cookie cookie = new Cookie("SAKAIID", "SESSIONID-123" + sessionID); expect(request.getCookies()).andReturn(new Cookie[] { cookie }).anyTimes(); expect(session.getAttribute(SessionImpl.USER)).andReturn(u).anyTimes(); response.addCookie((Cookie) anyObject()); expectLastCall().anyTimes(); expect(request.getAttribute("_uuid")).andReturn(null).anyTimes(); expect(request.getAttribute("_no_session")).andReturn(null).anyTimes(); }
From source file:org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet.java
private void evaluateSaslResponse(final HttpServletRequest request, final HttpServletResponse response, final HttpSession session, final String saslResponse, final SaslServer saslServer, SubjectCreator subjectCreator) throws IOException { final String id; byte[] challenge; try {//from w ww . ja v a 2 s. c o m challenge = saslServer.evaluateResponse( saslResponse == null ? new byte[0] : Base64.decodeBase64(saslResponse.getBytes())); } catch (SaslException e) { session.removeAttribute(ATTR_ID); session.removeAttribute(ATTR_SASL_SERVER); session.removeAttribute(ATTR_EXPIRY); response.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } if (saslServer.isComplete()) { Subject subject = subjectCreator.createSubjectWithGroups(saslServer.getAuthorizationID()); try { authoriseManagement(request, subject); } catch (AccessControlException ace) { sendError(response, HttpServletResponse.SC_FORBIDDEN); return; } setAuthorisedSubjectInSession(subject, request, session); session.removeAttribute(ATTR_ID); session.removeAttribute(ATTR_SASL_SERVER); session.removeAttribute(ATTR_EXPIRY); response.setStatus(HttpServletResponse.SC_OK); } else { Random rand = getRandom(session); id = String.valueOf(rand.nextLong()); session.setAttribute(ATTR_ID, id); session.setAttribute(ATTR_SASL_SERVER, saslServer); session.setAttribute(ATTR_EXPIRY, System.currentTimeMillis() + SASL_EXCHANGE_EXPIRY); response.setStatus(HttpServletResponse.SC_OK); Map<String, Object> outputObject = new LinkedHashMap<String, Object>(); outputObject.put("id", id); outputObject.put("challenge", new String(Base64.encodeBase64(challenge))); final PrintWriter writer = response.getWriter(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); mapper.writeValue(writer, outputObject); } }
From source file:org.apache.hadoop.hive.ql.exec.vector.VectorRandomRowSource.java
public static Object randomObject(int column, Random r, PrimitiveCategory[] primitiveCategories, PrimitiveTypeInfo[] primitiveTypeInfos, String[] alphabets, boolean addEscapables, String needsEscapeStr) {//from ww w . j av a 2 s . c o m PrimitiveCategory primitiveCategory = primitiveCategories[column]; PrimitiveTypeInfo primitiveTypeInfo = primitiveTypeInfos[column]; try { switch (primitiveCategory) { case BOOLEAN: return Boolean.valueOf(r.nextInt(1) == 1); case BYTE: return Byte.valueOf((byte) r.nextInt()); case SHORT: return Short.valueOf((short) r.nextInt()); case INT: return Integer.valueOf(r.nextInt()); case LONG: return Long.valueOf(r.nextLong()); case DATE: return RandomTypeUtil.getRandDate(r); case FLOAT: return Float.valueOf(r.nextFloat() * 10 - 5); case DOUBLE: return Double.valueOf(r.nextDouble() * 10 - 5); case STRING: case CHAR: case VARCHAR: { String result; if (alphabets != null && alphabets[column] != null) { result = RandomTypeUtil.getRandString(r, alphabets[column], r.nextInt(10)); } else { result = RandomTypeUtil.getRandString(r); } if (addEscapables && result.length() > 0) { int escapeCount = 1 + r.nextInt(2); for (int i = 0; i < escapeCount; i++) { int index = r.nextInt(result.length()); String begin = result.substring(0, index); String end = result.substring(index); Character needsEscapeChar = needsEscapeStr.charAt(r.nextInt(needsEscapeStr.length())); result = begin + needsEscapeChar + end; } } switch (primitiveCategory) { case STRING: return result; case CHAR: return new HiveChar(result, ((CharTypeInfo) primitiveTypeInfo).getLength()); case VARCHAR: return new HiveChar(result, ((VarcharTypeInfo) primitiveTypeInfo).getLength()); default: throw new Error("Unknown primitive category " + primitiveCategory); } } case BINARY: return getRandBinary(r, 1 + r.nextInt(100)); case TIMESTAMP: return RandomTypeUtil.getRandTimestamp(r); case INTERVAL_YEAR_MONTH: return getRandIntervalYearMonth(r); case INTERVAL_DAY_TIME: return getRandIntervalDayTime(r); case DECIMAL: return getRandHiveDecimal(r, (DecimalTypeInfo) primitiveTypeInfo); default: throw new Error("Unknown primitive category " + primitiveCategory); } } catch (Exception e) { throw new RuntimeException("randomObject failed on column " + column + " type " + primitiveCategory, e); } }
From source file:org.sakaiproject.kernel.test.AuthZServiceKernelUnitT.java
/** * @param request/*from w ww . j a v a 2s . com*/ * @param response * @param session */ private void setupRequest(HttpServletRequest request, HttpServletResponse response, HttpSession session, String userName) { User u = new InternalUser(userName); Random r = new Random(); long sessionID = r.nextLong(); expect(request.getRemoteUser()).andReturn(userName).anyTimes(); expect(request.getSession()).andReturn(session).anyTimes(); expect(request.getSession(true)).andReturn(session).anyTimes(); expect(request.getSession(false)).andReturn(session).anyTimes(); expect(session.getId()).andReturn(userName + "SESSIONID-123-A" + sessionID).anyTimes(); expect(request.getRequestedSessionId()).andReturn(userName + "SESSIONID-123-A" + sessionID).anyTimes(); Cookie cookie = new Cookie("SAKAIID", "SESSIONID-123-A" + sessionID); expect(request.getCookies()).andReturn(new Cookie[] { cookie }).anyTimes(); expect(session.getAttribute("check-valid")).andReturn(null).anyTimes(); response.addCookie((Cookie) anyObject()); expectLastCall().anyTimes(); expect(session.getAttribute(SessionImpl.USER)).andReturn(u).anyTimes(); expect(request.getAttribute("_uuid")).andReturn(null).anyTimes(); expect(request.getAttribute("_no_session")).andReturn(null).anyTimes(); }