Java Code Examples for org.apache.commons.lang3.RandomUtils#nextLong()
The following examples show how to use
org.apache.commons.lang3.RandomUtils#nextLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwtClientServiceTest.java From devicehive-java-server with Apache License 2.0 | 6 votes |
@Test(expected = MalformedJwtException.class) public void should_throw_MalformedJwtException_whet_pass_token_without_expiration_and_type() throws Exception { // Create payload Long userId = RandomUtils.nextLong(10, 1000); Set<Integer> actions = new HashSet<>(); actions.add(0); Set<String> networkIds = new HashSet<>(); networkIds.add("string"); Set<String> deviceTypeIds = new HashSet<>(); deviceTypeIds.add("string"); Set<String> deviceIds = new HashSet<>(); deviceIds.add("string"); JwtUserPayload.JwtUserPayloadBuilder jwtUserPayloadBuilder = new JwtUserPayload.JwtUserPayloadBuilder(); JwtUserPayload payload = jwtUserPayloadBuilder.withPublicClaims(userId, actions, networkIds, deviceTypeIds).buildPayload(); // Generate key without expiration date and token type Map<String, Object> jwtMap = new HashMap<>(); jwtMap.put(JwtUserPayload.JWT_CLAIM_KEY, payload); Claims claims = Jwts.claims(jwtMap); String malformedToken = Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS256, jwtSecretService.getJwtSecret()) .compact(); jwtClientService.getUserPayload(malformedToken); }
Example 2
Source File: MybatisTest.java From azeroth with Apache License 2.0 | 6 votes |
@Test public void testInsert() { for (int i = 0; i < mobiles.length; i++) { if (StringUtils.isBlank(mobiles[i])) { mobiles[i] = "13800" + RandomUtils.nextLong(100000, 999999); } UserEntity entity = new UserEntity(); entity.setCreatedAt(new Date()); entity.setEmail(mobiles[i] + "@163.com"); entity.setMobile(mobiles[i]); entity.setType((short) (i % 2 == 0 ? 1 : 2)); entity.setStatus((short) (i % 3 == 0 ? 1 : 2)); mapper.insert(entity); } }
Example 3
Source File: GraphInferenceGrpcClientTest.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void testSimpleGraph_2() throws Exception { val exp = Nd4j.create(new double[] {-0.95938617, -1.20301781, 1.22260064, 0.50172403, 0.59972949, 0.78568028, 0.31609724, 1.51674747, 0.68013491, -0.05227458, 0.25903158,1.13243439}, new long[]{3, 1, 4}); // configuring client val client = new GraphInferenceGrpcClient("127.0.0.1", 40123); val graphId = RandomUtils.nextLong(0, Long.MAX_VALUE); // preparing and registering graph (it's optional, and graph might be embedded into Docker image val tg = TFGraphMapper.importGraph(new ClassPathResource("tf_graphs/examples/expand_dim/frozen_model.pb").getInputStream()); assertNotNull(tg); client.registerGraph(graphId, tg, ExecutorConfiguration.builder().outputMode(OutputMode.IMPLICIT).build()); //defining input val input0 = Nd4j.create(new double[] {0.09753360, 0.76124972, 0.24693797, 0.13813169, 0.33144656, 0.08299957, 0.67197708, 0.80659380, 0.98274191, 0.63566073, 0.21592326, 0.54902743}, new int[] {3, 4}); val operands = new Operands().addArgument(1, 0, input0); // sending request and getting result val result = client.output(graphId, operands); assertEquals(exp, result.getById("output")); }
Example 4
Source File: JwtClientServiceTest.java From devicehive-java-server with Apache License 2.0 | 5 votes |
@Test public void should_generate_jwt_token_with_refresh_type() throws Exception { // Create payload Long userId = RandomUtils.nextLong(10, 1000); Set<Integer> actions = new HashSet<>(); actions.add(0); Set<String> networkIds = new HashSet<>(); networkIds.add("string"); Set<String> deviceTypeIds = new HashSet<>(); deviceTypeIds.add("string"); Set<String> deviceIds = new HashSet<>(); deviceIds.add("string"); JwtUserPayload.JwtUserPayloadBuilder jwtUserPayloadBuilder = new JwtUserPayload.JwtUserPayloadBuilder(); JwtUserPayload payload = jwtUserPayloadBuilder.withPublicClaims(userId, actions, networkIds, deviceTypeIds).buildPayload(); String token = jwtClientService.generateJwtRefreshToken(payload, true); JwtUserPayload resultPayload = jwtClientService.getUserPayload(token); assertEquals(resultPayload.getTokenType(), TokenType.REFRESH.getId()); }
Example 5
Source File: HttpClientTest.java From onetwo with Apache License 2.0 | 5 votes |
public static void main(String[] args) { BasicClientCookie cookie = new BasicClientCookie("xx", "yyy"); cookie.setDomain("www.test.com"); cookie.setPath("/"); cookieStore.addCookie(cookie); while(true){ draw(); long delay = RandomUtils.nextLong(100, 1000); try { Thread.sleep(delay); } catch (InterruptedException e) { System.err.println("sleep error:"+e.getMessage()); } } }
Example 6
Source File: RandomConnoteGenerator.java From resilient-transport-service with Apache License 2.0 | 5 votes |
public long randomNumber() { startRange.get(); endRange.get(); return RandomUtils.nextLong(connoteStart, connoteEnd); //return RandomUtils.nextLong(startRange.get(), endRange.get()); }
Example 7
Source File: Core.java From DataDefender with Apache License 2.0 | 5 votes |
/** * Generates a random date between the passed start and end dates, and using * the passed format to parse the dates passed, and to format the return * value. * * @param start * @param end * @param format * @return */ public String randomDate( @NamedParameter("start") String start, @NamedParameter("end") String end, @NamedParameter("format") String format ) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern(format); LocalDate ds = LocalDate.parse(start, fmt); LocalDate de = LocalDate.parse(end, fmt); long day = RandomUtils.nextLong(0, de.toEpochDay() - ds.toEpochDay()) + ds.toEpochDay(); return LocalDate.ofEpochDay(day).format(fmt); }
Example 8
Source File: DataSourceConnectionUsageRateCheckerTest.java From pinpoint with Apache License 2.0 | 5 votes |
private List<Long> createIncreasingValues(Long minValue, Long maxValue, Long minIncrement, Long maxIncrement, int numValues) { List<Long> values = new ArrayList<Long>(numValues); long value = RandomUtils.nextLong(minValue, maxValue); values.add(value); for (int i = 0; i < numValues - 1; i++) { long increment = RandomUtils.nextLong(minIncrement, maxIncrement); value = value + increment; values.add(value); } return values; }
Example 9
Source File: SnowflakeIdWorker.java From match-trade with Apache License 2.0 | 5 votes |
private static Long getWorkId(){ try { String hostAddress = Inet4Address.getLocalHost().getHostAddress(); int[] ints = StringUtils.toCodePoints(hostAddress); int sums = 0; for(int b : ints){ sums += b; } return (long)(sums % 32); } catch (UnknownHostException e) { // 如果获取失败,则使用随机数备用 return RandomUtils.nextLong(0,31); } }
Example 10
Source File: SpanEncoderTest.java From pinpoint with Apache License 2.0 | 4 votes |
private long getCollectorAcceptTime() { long currentTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30); long randomSeed = RandomUtils.nextLong(0, TimeUnit.DAYS.toMillis(60)); return currentTime - randomSeed; }
Example 11
Source File: Request.java From NetDiscovery with Apache License 2.0 | 4 votes |
/** * 每次下载时先随机delay一段时间,单位是milliseconds * @return */ public Request autoDownloadDelay() { this.downloadDelay = RandomUtils.nextLong(1000,6000); return this; }
Example 12
Source File: PipelineReportPublisher.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private long getRandomReportDelay() { return RandomUtils.nextLong(0, pipelineReportInterval); }
Example 13
Source File: ImmutableByteSequenceTest.java From onos with Apache License 2.0 | 4 votes |
@Test public void testEndianness() throws Exception { long longValue = RandomUtils.nextLong(); // creates a new sequence from a big-endian buffer ByteBuffer bbBigEndian = ByteBuffer .allocate(8) .order(ByteOrder.BIG_ENDIAN) .putLong(longValue); ImmutableByteSequence bsBufferCopyBigEndian = ImmutableByteSequence.copyFrom(bbBigEndian); // creates a new sequence from a little-endian buffer ByteBuffer bbLittleEndian = ByteBuffer .allocate(8) .order(ByteOrder.LITTLE_ENDIAN) .putLong(longValue); ImmutableByteSequence bsBufferCopyLittleEndian = ImmutableByteSequence.copyFrom(bbLittleEndian); // creates a new sequence from primitive type ImmutableByteSequence bsLongCopy = ImmutableByteSequence.copyFrom(longValue); new EqualsTester() // big-endian byte array cannot be equal to little-endian array .addEqualityGroup(bbBigEndian.array()) .addEqualityGroup(bbLittleEndian.array()) // all byte sequences must be equal .addEqualityGroup(bsBufferCopyBigEndian, bsBufferCopyLittleEndian, bsLongCopy) // byte buffer views of all sequences must be equal .addEqualityGroup(bsBufferCopyBigEndian.asReadOnlyBuffer(), bsBufferCopyLittleEndian.asReadOnlyBuffer(), bsLongCopy.asReadOnlyBuffer()) // byte buffer orders of all sequences must be ByteOrder.BIG_ENDIAN .addEqualityGroup(bsBufferCopyBigEndian.asReadOnlyBuffer().order(), bsBufferCopyLittleEndian.asReadOnlyBuffer().order(), bsLongCopy.asReadOnlyBuffer().order(), ByteOrder.BIG_ENDIAN) .testEquals(); }
Example 14
Source File: CacheHandler.java From azeroth with Apache License 2.0 | 4 votes |
public long getExpire() { long rnd = RandomUtils.nextLong(0, expire / 3); return expire + (rnd > IN_1HOUR ? IN_1HOUR : rnd); }
Example 15
Source File: DeadlockCheckerTest.java From pinpoint with Apache License 2.0 | 4 votes |
private long createEventTimestamp() { return RandomUtils.nextLong(START_TIME_MILLIS, CURRENT_TIME_MILLIS); }
Example 16
Source File: TestCachingSpaceUsageSource.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private static long validInitialValue() { return RandomUtils.nextLong(1, 100); }
Example 17
Source File: IdRandomizer.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Long getRandomValue() { return RandomUtils.nextLong( 1, 100000 ); }
Example 18
Source File: ContainerReportPublisher.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private long getRandomReportDelay() { return RandomUtils.nextLong(0, containerReportInterval); }
Example 19
Source File: RedisBase.java From azeroth with Apache License 2.0 | 2 votes |
/** * 默认过期时间 * @return */ public static long getDefaultExpireSeconds() { return CacheExpires.IN_1WEEK + RandomUtils.nextLong(1, CacheExpires.IN_1DAY); }
Example 20
Source File: RedisBase.java From jeesuite-libs with Apache License 2.0 | 2 votes |
/** * 默认过期时间 * @return */ public static long getDefaultExpireSeconds(){ return CacheExpires.IN_1WEEK + RandomUtils.nextLong(1, CacheExpires.IN_1DAY); }