List of usage examples for org.apache.commons.lang.math RandomUtils nextLong
public static long nextLong()
Returns the next pseudorandom, uniformly distributed long value from the Math.random() sequence.
From source file:com.ms.commons.test.tool.UnitTestTools.java
public static Long nextLong() { return Math.abs(RandomUtils.nextLong()); }
From source file:com.github.pmerienne.cf.recommendation.TopKItemsTest.java
@Test public void should_not_exceed_max_size() { // Given/*from www. j a v a2 s . co m*/ int maxSize = 10; TopKItems topKItems = new TopKItems(maxSize); for (int i = 0; i < maxSize * 2; i++) { topKItems.add(new Recommendation(RandomUtils.nextLong(), RandomUtils.nextDouble())); } // When topKItems.ensureSize(); // Then assertThat(topKItems.size()).isLessThanOrEqualTo(maxSize); }
From source file:info.archinnov.achilles.test.builders.UserTestBuilder.java
public UserTestBuilder randomId() { this.id = RandomUtils.nextLong(); return this; }
From source file:info.archinnov.achilles.test.builders.TweetTestBuilder.java
public TweetTestBuilder randomId() { this.id = new UUID(RandomUtils.nextLong(), RandomUtils.nextLong()); return this; }
From source file:com.knewton.mapreduce.util.RandomStudentEventGenerator.java
/** * Generates a random long used in ids./*from ww w . j a v a2 s . c o m*/ * * @return A random ID */ public static long getRandomId() { return RandomUtils.nextLong() + 1; }
From source file:info.archinnov.achilles.test.integration.tests.ValuelessEntityIT.java
@Test public void should_persist_and_find() throws Exception { Long id = RandomUtils.nextLong(); ValuelessEntity entity = new ValuelessEntity(id); manager.persist(entity);//from ww w. j av a2s. com ValuelessEntity found = manager.find(ValuelessEntity.class, id); assertThat(found).isNotNull(); }
From source file:info.archinnov.achilles.junit.AchillesThriftResourceBuilderTest.java
@Test public void should_bootstrap_embedded_server_and_entity_manager() throws Exception { Long id = RandomUtils.nextLong(); manager.persist(new User(id, "fn", "ln")); assertThat(manager.find(User.class, id)).isNotNull(); manager.removeById(User.class, id); assertThat(manager.find(User.class, id)).isNull(); }
From source file:com.github.pmerienne.cf.recommendation.TopKItemsTest.java
@Test public void should_sort_recommendations() { // Given/*from w w w.j a v a2 s .c o m*/ int maxSize = 10; // When TopKItems topKItems = new TopKItems(maxSize); for (int i = 0; i < maxSize; i++) { topKItems.add(new Recommendation(RandomUtils.nextLong(), RandomUtils.nextDouble())); } // Then double previousScore = Double.MAX_VALUE; for (Recommendation recommendation : topKItems) { assertThat(recommendation.getScore()).isLessThan(previousScore); previousScore = recommendation.getScore(); } }
From source file:info.archinnov.achilles.test.integration.tests.SupportedTypesIT.java
@Test public void should_persist_and_find_all_types() throws Exception { // Given//from w w w .j av a2 s .c o m Long id = RandomUtils.nextLong(); byte[] bytes = "toto".getBytes(Charsets.UTF_8); Date now = new Date(); InetAddress inetAddress = InetAddresses.forString("192.168.0.1"); EntityWithAllTypes entity = new EntityWithAllTypes(); entity.setId(id); entity.setPrimitiveByte((byte) 7); entity.setObjectByte((byte) 7); entity.setByteArray(bytes); entity.setByteBuffer(ByteBuffer.wrap(bytes)); entity.setPrimitiveBool(true); entity.setObjectBool(true); entity.setDate(now); entity.setPrimitiveDouble(1.0d); entity.setObjectDouble(1.0d); entity.setBigDecimal(new BigDecimal(1.11)); entity.setPrimitiveFloat(1.0f); entity.setObjectFloat(1.0f); entity.setInetAddress(inetAddress); entity.setBigInt(new BigInteger("10")); entity.setPrimitiveInt(10); entity.setObjectInt(10); entity.setPrimitiveLong(10L); // When manager.persist(entity); EntityWithAllTypes found = manager.find(EntityWithAllTypes.class, id); // Then assertThat(found.getPrimitiveByte()).isEqualTo((byte) 7); assertThat(found.getObjectByte()).isEqualTo((byte) 7); assertThat(found.getByteArray()).isEqualTo(bytes); assertThat(found.getByteBuffer()).isEqualTo(ByteBuffer.wrap(bytes)); assertThat(found.isPrimitiveBool()).isTrue(); assertThat(found.getObjectBool()).isTrue(); assertThat(found.getDate()).isEqualTo(now); assertThat(found.getPrimitiveDouble()).isEqualTo(1.0d); assertThat(found.getObjectDouble()).isEqualTo(1.0d); assertThat(found.getBigDecimal()).isEqualTo(new BigDecimal(1.11)); assertThat(found.getPrimitiveFloat()).isEqualTo(1.0f); assertThat(found.getObjectFloat()).isEqualTo(1.0f); assertThat(found.getInetAddress()).isEqualTo(inetAddress); assertThat(found.getBigInt()).isEqualTo(new BigInteger("10")); assertThat(found.getPrimitiveInt()).isEqualTo(10); assertThat(found.getObjectInt()).isEqualTo(10); assertThat(found.getPrimitiveLong()).isEqualTo(10L); }
From source file:info.archinnov.achilles.junit.AchillesCQLResourceBuilderTest.java
@Test public void should_bootstrap_embedded_server_and_entity_manager() throws Exception { Long id = RandomUtils.nextLong(); manager.persist(new User(id, "fn", "ln")); Row row = session.execute("SELECT * FROM User WHERE id=" + id).one(); assertThat(row).isNotNull();/*from www .j a v a 2 s . c o m*/ assertThat(row.getString("firstname")).isEqualTo("fn"); assertThat(row.getString("lastname")).isEqualTo("ln"); }