/** * <p>Returns a pseudorandom, uniformly distributed int value * between <code>0</code> (inclusive) and the specified value * (exclusive), from the Math.random() sequence.</p> * * @param n the specified exclusive max-value * @return the random int */ public static int nextInt(int n) { return nextInt(JVM_RANDOM, n); }
public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto> consumer) { ActiveRuleDto activeRule = createFor(profile, rule) .setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) .setCreatedAt(nextLong()) .setUpdatedAt(nextLong()); consumer.accept(activeRule); dbClient.activeRuleDao().insert(dbSession, activeRule); dbSession.commit(); return activeRule; }
private void insertCeActivity(String uuid, String analysisUuid) { db.executeInsert(TABLE_CE_ACTIVITIY, "UUID", uuid, "TASK_TYPE", randomAlphanumeric(5), "ANALYSIS_UUID", analysisUuid, "STATUS", randomAlphanumeric(5), "IS_LAST", RandomUtils.nextBoolean(), "IS_LAST_KEY", randomAlphanumeric(50), "EXECUTION_COUNT", RandomUtils.nextInt(10), "SUBMITTED_AT", RandomUtils.nextInt(), "CREATED_AT", RandomUtils.nextInt(), "UPDATED_AT", RandomUtils.nextInt() ); }
public static MetricDto newMetricDto() { Metric.ValueType[] metricTypes = Metric.ValueType.values(); return new MetricDto() .setId(RandomUtils.nextInt()) .setKey(RandomStringUtils.randomAlphanumeric(64)) .setShortName(RandomStringUtils.randomAlphanumeric(64)) .setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name()) .setDomain(RandomStringUtils.randomAlphanumeric(64)) .setDescription(RandomStringUtils.randomAlphanumeric(250)) .setBestValue(RandomUtils.nextDouble()) .setDeleteHistoricalData(RandomUtils.nextBoolean()) .setDirection(RandomUtils.nextInt()) .setHidden(RandomUtils.nextBoolean()) .setEnabled(true) .setOptimizedBestValue(RandomUtils.nextBoolean()) .setQualitative(RandomUtils.nextBoolean()) .setUserManaged(RandomUtils.nextBoolean()) .setWorstValue(RandomUtils.nextDouble()); } }
private Object getInstanceWithPrimitiveFieldsSet(Class<?> testingClass) throws IllegalArgumentException, IllegalAccessException, InstantiationException { Object object = testingClass.newInstance(); for (Field field : testingClass.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers())) { continue; } field.setAccessible(true); if (field.getType().equals(long.class)) { field.set(object, RandomUtils.nextLong()); } else if (field.getType().equals(int.class)) { field.set(object, RandomUtils.nextInt()); } else if (field.getType().equals(double.class)) { field.set(object, RandomUtils.nextDouble()); } else if (field.getType().equals(boolean.class)) { field.set(object, RandomUtils.nextBoolean()); } else if (field.getType().equals(String.class)) { field.set(object, RandomStringUtils.random(100)); } } return object; }
public static WebhookDeliveryDto newDto() { return new WebhookDeliveryDto() .setUuid(Uuids.createFast()) .setWebhookUuid(randomAlphanumeric(40)) .setComponentUuid(randomAlphanumeric(40)) .setCeTaskUuid(randomAlphanumeric(40)) .setAnalysisUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(10)) .setUrl(randomAlphanumeric(10)) .setDurationMs(nextInt()) .setHttpStatus(nextInt()) .setSuccess(nextBoolean()) .setPayload(randomAlphanumeric(10)) .setCreatedAt(nextLong()); }
public static CustomMeasureDto newCustomMeasureDto() { return new CustomMeasureDto() .setDescription(RandomStringUtils.randomAlphanumeric(255)) .setTextValue(RandomStringUtils.randomAlphanumeric(255)) .setUserUuid("userUuid" + RandomStringUtils.randomAlphanumeric(100)) .setValue(RandomUtils.nextDouble()) .setMetricId(RandomUtils.nextInt()) .setComponentUuid(RandomStringUtils.randomAlphanumeric(50)) .setCreatedAt(System2.INSTANCE.now()) .setUpdatedAt(System2.INSTANCE.now()); } }
/** * <p>Returns the next pseudorandom, uniformly distributed long value * from the Math.random() sequence.</p> * <b>N.B. All values are >= 0.<b> * @return the random long */ public static long nextLong() { return nextLong(JVM_RANDOM); }
/** * <p>Returns the next pseudorandom, uniformly distributed boolean value * from the Math.random() sequence.</p> * * @return the random boolean */ public static boolean nextBoolean() { return nextBoolean(JVM_RANDOM); }
@Test public void noMethodIdent() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getMethodIdentForId(METHOD_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getMethodIdent()).thenReturn(METHOD_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(RandomUtils.nextDouble()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Methods.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Methods.TAG_CLASS_FQN))); assertThat(getTags(pointBuilder), not(hasKey(Series.Methods.TAG_METHOD_NAME))); assertThat(getTags(pointBuilder), not(hasKey(Series.Methods.TAG_METHOD_SIGNATURE))); }
/** * <p>Returns the next pseudorandom, uniformly distributed float value * between <code>0.0</code> and <code>1.0</code> from the Math.random() * sequence.</p> * * @return the random double */ public static double nextDouble() { return nextDouble(JVM_RANDOM); }
/** * <p>Returns the next pseudorandom, uniformly distributed float value * between <code>0.0</code> and <code>1.0</code> from the Math.random() * sequence.</p> * * @return the random float */ public static float nextFloat() { return nextFloat(JVM_RANDOM); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getCount()).thenReturn(5); when(data.getTotalCpuUsage()).thenReturn(RandomUtils.nextFloat()); when(data.getMinCpuUsage()).thenReturn(RandomUtils.nextFloat()); when(data.getMaxCpuUsage()).thenReturn(RandomUtils.nextFloat()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.CpuInformation.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_AVG_CPU_UTIL, (Object) Double.valueOf(data.getTotalCpuUsage() / data.getCount()))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_MAX_CPU_UTIL, (Object) Double.valueOf(data.getMaxCpuUsage()))); assertThat(getFields(pointBuilder), hasEntry(Series.CpuInformation.FIELD_MIN_CPU_UTIL, (Object) Double.valueOf(data.getMinCpuUsage()))); }
private void doWrite(BlockCompressedDataOutputStream outputStream) throws IOException { outputStream.writeFloat(RandomUtils.nextFloat()); outputStream.writeDouble(RandomUtils.nextDouble()); outputStream.writeLong(RandomUtils.nextLong()); outputStream.writeInt(RandomUtils.nextInt()); outputStream.writeShort(0); outputStream.writeBoolean(RandomUtils.nextBoolean()); outputStream.writeBytes("test"); outputStream.writeByte(RandomUtils.nextInt()); outputStream.writeChar(TEST_CHAR_ID); outputStream.writeChars("test"); outputStream.flush(); }
public static UserDto newUserDto() { return new UserDto() .setId(nextInt()) .setUuid(randomAlphanumeric(40)) .setActive(true) .setLocal(nextBoolean()) .setLogin(randomAlphanumeric(30)) .setName(randomAlphanumeric(30)) .setEmail(randomAlphanumeric(30)) .setOnboarded(nextBoolean()) .setScmAccounts(singletonList(randomAlphanumeric(40))) .setExternalId(randomAlphanumeric(40)) .setExternalLogin(randomAlphanumeric(40)) .setExternalIdentityProvider(randomAlphanumeric(40)) .setSalt(randomAlphanumeric(40)) .setCryptedPassword(randomAlphanumeric(40)) .setCreatedAt(nextLong()) .setUpdatedAt(nextLong()); }
public static double randomDouble(int min, int max) { return RandomUtils.nextDouble() + RandomUtils.nextInt(max - min); }
/** * <p>Returns the next pseudorandom, uniformly distributed boolean value * from the Math.random() sequence.</p> * * @return the random boolean */ public static boolean nextBoolean() { return nextBoolean(JVM_RANDOM); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getJmxDefinitionDataIdentForId(JMX_IDENT)).thenReturn(jmxDefinitionDataIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getJmxSensorDefinitionDataIdentId()).thenReturn(JMX_IDENT); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getValueAsDouble()).thenReturn(RandomUtils.nextDouble()); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Jmx.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.Jmx.TAG_JMX_ATTRIBUTE_FULL_NAME, String.valueOf(JMX_ATTR))); assertThat(getFields(pointBuilder), hasEntry(Series.Jmx.FIELD_VALUE, (Object) data.getValueAsDouble())); }