Exemplo n.º 1
0
  private void deleteCommitItems() {

    List<CommitItem> toDelete =
        CollectorApi.getCommitItemContainer()
            .findByCriteria(
                new Criteria<CommitItem>() {

                  @Override
                  public boolean match(CommitItem entity) {
                    // if the item has exceeded the days threshold AND is not in a RUNNING state, it
                    // will be deleted
                    return isExceedThreashold(entity.getCreationTime())
                        && !isRunning(entity.getStatus());
                  }
                });

    CollectorApi.getCommitItemContainer().delete(toDelete);

    for (CommitItem currItem : toDelete) {

      CollectorApi.getCommitItemVerifierManager().remove(currItem.getKey());
    }
  }
Exemplo n.º 2
0
  @Test
  public void testE2EWith2ItemsSeparately() throws Exception {

    JenkinsVerifierMockFactory.setHangMock();
    CommitItem item1 = createItem(TestCollectorConstants.BRANCH_1, true, false, false, true, true);
    // consume
    new ConsumerJob().execute(null);
    CommitItem item2 = createItem(TestCollectorConstants.BRANCH_2, true, false, false, true, true);
    new ConsumerJob().execute(null);
    item2 = CollectorApi.getCommitItemContainer().get(item2.getKey());
    Assert.assertEquals(item2.getParent(), item1);
    // run decision maker again
    // wait for task in queue to finish
    SynchronizeableThreadPoolExecutor executor =
        (SynchronizeableThreadPoolExecutor) ExecutorServiceFactory.getCachedThreadPoolExecutor();
    executor.join();
    new ConsumerJob().execute(null);
    item1 = CollectorApi.getCommitItemContainer().get(item1.getKey());
    item2 = CollectorApi.getCommitItemContainer().get(item2.getKey());
    assertItem(TestCollectorConstants.BRANCH_1, VerificationStatus.TIMEOUT, true);
    assertItem(TestCollectorConstants.BRANCH_2, VerificationStatus.RUNNING, false);
    Assert.assertNull(item2.getParent());
  }
Exemplo n.º 3
0
  private List<String> branchesToBeDelete(List<String> branchesList) {
    List<String> result = new ArrayList<>();
    Repository repo = null;
    Map<String, List<String>> branchesMap = new HashMap<>();
    for (String branch : branchesList) {
      List<String> values = null;
      if (!branchesMap.containsKey(branch.subSequence(0, 10))) {
        values = new ArrayList<>();
        values.add(branch);
        branchesMap.put(branch.subSequence(0, 10).toString(), values);
      } else if (!branchesMap.get(branch.subSequence(0, 10)).contains(branch)) {
        values = branchesMap.get(branch.subSequence(0, 10));
        values.add(branch);
        branchesMap.put(branch.subSequence(0, 10).toString(), values);
      }
    }
    List<CommitItem> allBranches = CollectorApi.getCommitItemContainer().getAll();
    for (CommitItem branch : allBranches) {
      if (branchesMap.containsKey(branch.getBranchDescriptor().getNewBranch().subSequence(0, 10))) {
        branchesMap.remove(branch.getBranchDescriptor().getNewBranch().subSequence(0, 10));
      }
    }
    for (String key : branchesMap.keySet()) {
      result.addAll(branchesMap.get(key));
    }

    try {
      repo =
          new FileRepository(VerigreenNeededLogic.properties.getProperty("git.repositoryLocation"));
      if (result.contains(repo.getBranch())) {
        _jgit.checkout(VerigreenNeededLogic.VerigreenMap.get("_protectedBranches"), false, false);
      }
    } catch (IOException e) {
      VerigreenLogger.get()
          .error(
              getClass().getName(),
              RuntimeUtils.getCurrentMethodName(),
              String.format(
                  "Failed creating git repository for path [%s]",
                  VerigreenNeededLogic.properties.getProperty("git.repositoryLocation")),
              e);
    }

    return result;
  }
Exemplo n.º 4
0
  private void assertItem(final String branch, VerificationStatus status, boolean isDone) {

    CommitItem commitItem1 =
        CollectorApi.getCommitItemContainer()
            .findByCriteria(
                new Criteria<CommitItem>() {

                  @Override
                  public boolean match(CommitItem entity) {

                    return entity.getBranchDescriptor().getNewBranch().equals(branch);
                  }
                })
            .get(0);
    Assert.assertEquals(status, commitItem1.getStatus());
    Assert.assertEquals(isDone, commitItem1.isDone());
    if (isDone) {
      Assert.assertNotNull(commitItem1.getEndTime());
    }
  }