/** * <p>Returns the next pseudorandom, uniformly distributed int value * from the Math.random() sequence.</p> * <b>N.B. All values are >= 0.<b> * @return the random int */ public static int nextInt() { return nextInt(JVM_RANDOM); }
/** * <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); }
private RuleType randomRuleTypeExceptHotspot() { return RULE_TYPES_EXCEPT_HOTSPOT[nextInt(RULE_TYPES_EXCEPT_HOTSPOT.length)]; } }
private static RuleType randomRuleTypeExceptHotspot() { return RULE_TYPES_EXCEPT_HOTSPOT[nextInt(RULE_TYPES_EXCEPT_HOTSPOT.length)]; } }
@Override public void start() { long delayInMs = getSetting(PROPERTY_DELAY, DEFAULT_DELAY_IN_MS); // in the cluster mode, avoid (but not prevent!) simultaneous executions of recovery // indexers so that a document is not handled multiple times. long initialDelayInMs = getSetting(PROPERTY_INITIAL_DELAY, RandomUtils.nextInt(1 + (int) (delayInMs / 2))); executorService.scheduleAtFixedRate( this::recover, initialDelayInMs, delayInMs, TimeUnit.MILLISECONDS); }
private long insertPersonMeasure(String componentUuid, String analysisUuid) { long id = GENERATOR.incrementAndGet(); db.executeInsert("PROJECT_MEASURES", "ID", id, "METRIC_ID", "42", "COMPONENT_UUID", componentUuid, "ANALYSIS_UUID", analysisUuid, "PERSON_ID", RandomUtils.nextInt(100)); return id; } }
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 PermissionTemplateUserDto newPermissionTemplateUserDto() { return new PermissionTemplateUserDto() .setPermission(PermissionsTestHelper.ALL_PERMISSIONS.toArray(new String[0])[RandomUtils.nextInt(PermissionsTestHelper.ALL_PERMISSIONS.size())]) .setCreatedAt(new Date()) .setUpdatedAt(new Date()); }
public static ProjectLinkDto newProvidedLinkDto() { return newCommonLinkDto() .setName(null) .setType(ProjectLinkDto.PROVIDED_TYPES.get(RandomUtils.nextInt(ProjectLinkDto.PROVIDED_TYPES.size() - 1))); }
public static PermissionTemplateGroupDto newPermissionTemplateGroupDto() { return new PermissionTemplateGroupDto() .setPermission(PermissionsTestHelper.ALL_PERMISSIONS.toArray(new String[0])[RandomUtils.nextInt(PermissionsTestHelper.ALL_PERMISSIONS.size())]) .setCreatedAt(new Date()) .setUpdatedAt(new Date()); }
public static PermissionTemplateCharacteristicDto newPermissionTemplateCharacteristicDto() { return new PermissionTemplateCharacteristicDto() .setPermission(PermissionsTestHelper.ALL_PERMISSIONS.toArray(new String[0])[RandomUtils.nextInt(PermissionsTestHelper.ALL_PERMISSIONS.size())]) .setWithProjectCreator(RandomUtils.nextBoolean()) .setCreatedAt(System.currentTimeMillis()) .setUpdatedAt(System.currentTimeMillis()); }
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 insertWebhookDelivery(String uuid, @Nullable String analysisUuid, String ceTaskUuid) { db.executeInsert(TABLE_WEBHOOK_DELIVERY, "UUID", uuid, "COMPONENT_UUID", randomAlphanumeric(30), "ANALYSIS_UUID", analysisUuid, "CE_TASK_UUID", ceTaskUuid, "NAME", randomAlphanumeric(15), "URL", randomAlphanumeric(15), "SUCCESS", RandomUtils.nextBoolean(), "PAYLOAD", randomAlphanumeric(200), "CREATED_AT", RandomUtils.nextInt() ); } }
@Test public void test_creation_from_DeprecatedRuleKeyDto() { // Creation from DeprecatedRuleKeyDto DeprecatedRuleKeyDto deprecatedRuleKeyDto = new DeprecatedRuleKeyDto() .setOldRuleKey(randomAlphanumeric(50)) .setOldRepositoryKey(randomAlphanumeric(50)) .setRuleId(nextInt(1000)) .setUuid(randomAlphanumeric(40)); SingleDeprecatedRuleKey singleDeprecatedRuleKey = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto); assertThat(singleDeprecatedRuleKey.getOldRepositoryKey()).isEqualTo(deprecatedRuleKeyDto.getOldRepositoryKey()); assertThat(singleDeprecatedRuleKey.getOldRuleKey()).isEqualTo(deprecatedRuleKeyDto.getOldRuleKey()); assertThat(singleDeprecatedRuleKey.getNewRepositoryKey()).isEqualTo(deprecatedRuleKeyDto.getNewRepositoryKey()); assertThat(singleDeprecatedRuleKey.getNewRuleKey()).isEqualTo(deprecatedRuleKeyDto.getNewRuleKey()); assertThat(singleDeprecatedRuleKey.getUuid()).isEqualTo(deprecatedRuleKeyDto.getUuid()); assertThat(singleDeprecatedRuleKey.getRuleId()).isEqualTo(deprecatedRuleKeyDto.getRuleId()); assertThat(singleDeprecatedRuleKey.getOldRuleKeyAsRuleKey()) .isEqualTo(RuleKey.of(deprecatedRuleKeyDto.getOldRepositoryKey(), deprecatedRuleKeyDto.getOldRuleKey())); }
public static GroupDto newGroupDto() { GroupDto group = new GroupDto() .setId(nextInt()) .setOrganizationUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(255)) .setDescription(randomAlphanumeric(200)) .setCreatedAt(new Date(nextLong())) .setUpdatedAt(new Date(nextLong())); return group; } }
@Test public void verify_notification_on_branch() { RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto file = db.components().insertComponent(newFileDto(branch)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file) .setType(randomTypeExceptHotspot)).setSeverity(MAJOR).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, "increase severity"); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey()); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name()); assertThat(issueChangeNotification.getFieldValue("branch")).isEqualTo(branch.getBranch()); }
@Test public void verify_notification_when_issue_is_linked_on_removed_rule() { RuleDto rule = db.rules().insertRule(r -> r.setStatus(RuleStatus.REMOVED)); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)).setSeverity(MAJOR).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, null); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); assertThat(notificationArgumentCaptor.getValue().getFieldValue("ruleName")).isNull(); }
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()); } }
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()); }