CommitsAnalysis implements Query { @Override public void query() throws QueryException { List<String> commitStatements = new ArrayList<>(); List<String> authorStatements = new ArrayList<>(); List<String> renameStatements = new ArrayList<>(); int commitCount = 0; CommitDetails details; Commit currentCommit; for (String commit : choseCommitsSource()) { currentCommit = fillCommit(commit); logger.debug("[" + projectId + "] => Analyzing commit: " + currentCommit.sha); details = detailsChecker.fetch(currentCommit.sha); authorStatements.addAll(authorStatements(currentCommit.authorEmail)); commitStatements.add(commitStatement(currentCommit, details)); renameStatements.addAll(fileRenameStatements(currentCommit, details)); if (++commitCount % BATCH_SIZE == 0) { logger.info("[" + projectId + "] Persist commit batch of size: " + BATCH_SIZE); persistBatch(commitStatements, authorStatements, renameStatements); authorStatements.clear(); commitStatements.clear(); renameStatements.clear(); } } persistBatch(commitStatements, authorStatements, renameStatements); } CommitsAnalysis(int projectId, Persistence persistence, Repository repository,
                    Iterator<Map<String, Object>> commits,
                    CommitDetailsChecker detailsChecker,
                    DeveloperQueries developerQueries, CommitQueries commitQueries);   CommitsAnalysis(int projectId, Persistence persistence, Repository repository,
                    Iterator<Map<String, Object>> commits,
                    CommitDetailsChecker detailsChecker,
                    DeveloperQueries developerQueries, CommitQueries commitQueries,
                    boolean paprikaOnly); @Override void query(); static final int BATCH_SIZE; }
@Test public void testMergeCommitInserted() throws IOException, QueryException { Commit merged = new Commit("a", 51, DateTime.now(), "message", "first@email.com", new ArrayList<>()); Commit parent = new Commit("b", 53, DateTime.now(), "message", "second@email.com", new ArrayList<>()); ArrayList<Commit> parents = new ArrayList<>(); parents.add(parent); parents.add(merged); Commit merge = new Commit("c", 54, DateTime.now(), "message", "author@email.com", parents); addCommitInPaprika(merged); addCommitInRepository(merged); addCommitInPaprika(parent); addCommitInRepository(parent); addCommitInPaprika(merge); addCommitInRepository(merge); prepareGitLog(merged, parent, merge); getCommitsAnalysis().query(); verify(commitQueries, times(3)).commitInsertionStatement(anyInt(), any(Commit.class), any(GitDiff.class)); verify(commitQueries).commitInsertionStatement(projectId, merged, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, parent, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, merge, dummyDetails.diff); verify(developerQueries, times(3)).developerInsertStatement(anyString()); verify(developerQueries, times(1)).developerInsertStatement(merged.authorEmail); verify(developerQueries, times(1)).developerInsertStatement(parent.authorEmail); verify(developerQueries, times(1)).developerInsertStatement(merge.authorEmail); verify(developerQueries, times(3)).projectDeveloperInsertStatement(eq(projectId), anyString()); verify(developerQueries, times(1)).projectDeveloperInsertStatement(projectId, merged.authorEmail); verify(developerQueries, times(1)).projectDeveloperInsertStatement(projectId, parent.authorEmail); verify(developerQueries, times(1)).projectDeveloperInsertStatement(projectId, merge.authorEmail); verify(commitQueries, times(0)).fileRenameInsertionStatement(eq(projectId), anyString(), any(GitRename.class)); }
@Test public void testInsertCommit() throws Exception { addCommitInPaprika(A); addCommitInRepository(A); addCommitInPaprika(B); addCommitInRepository(B); addCommitInPaprika(C); addCommitInRepository(C); addCommitInPaprika(D); addCommitInRepository(D); prepareGitLog(A, B, C, D); getCommitsAnalysis().query(); verify(commitQueries, times(4)).commitInsertionStatement(anyInt(), any(Commit.class), any(GitDiff.class)); verify(commitQueries).commitInsertionStatement(projectId, A, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, B, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, C, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, D, dummyDetails.diff); verify(developerQueries, times(4)).developerInsertStatement(anyString()); verify(developerQueries, times(2)).developerInsertStatement(A.authorEmail); verify(developerQueries, times(2)).developerInsertStatement(C.authorEmail); verify(developerQueries, times(4)).projectDeveloperInsertStatement(eq(projectId), anyString()); verify(developerQueries, times(2)).projectDeveloperInsertStatement(projectId, A.authorEmail); verify(developerQueries, times(2)).projectDeveloperInsertStatement(projectId, C.authorEmail); verify(commitQueries, times(0)).fileRenameInsertionStatement(eq(projectId), anyString(), any(GitRename.class)); }
@Test public void testCommitNotInPaprika() throws Exception { addCommitInPaprika(A); addCommitInRepository(A); addCommitInPaprika(B); addCommitInRepository(B); addCommitInRepository(C); addCommitInPaprika(D); addCommitInRepository(D); prepareGitLog(A, B, C, D); getCommitsAnalysis().query(); verify(commitQueries, times(4)).commitInsertionStatement(anyInt(), any(Commit.class), any(GitDiff.class)); verify(commitQueries).commitInsertionStatement(projectId, A, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, B, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, C, dummyDetails.diff); verify(commitQueries).commitInsertionStatement(projectId, D, dummyDetails.diff); verify(developerQueries, times(4)).developerInsertStatement(anyString()); verify(developerQueries, times(2)).developerInsertStatement(A.authorEmail); verify(developerQueries, times(2)).developerInsertStatement(C.authorEmail); verify(developerQueries, times(4)).projectDeveloperInsertStatement(eq(projectId), anyString()); verify(developerQueries, times(2)).projectDeveloperInsertStatement(projectId, A.authorEmail); verify(developerQueries, times(2)).projectDeveloperInsertStatement(projectId, C.authorEmail); verify(commitQueries, times(0)).fileRenameInsertionStatement(eq(projectId), anyString(), any(GitRename.class)); }
@Test public void testCommitWitDetails() throws Exception { GitRename notJavaRename = new GitRename("old", "new", 97); GitRename actualRename = new GitRename("another.java", "anotherNew.java", 100); GitRename renameB = new GitRename("oldB.java", "newB.java", 50); CommitDetails details = new CommitDetails( new GitDiff(1, 2, 4), Arrays.asList(notJavaRename, actualRename)); CommitDetails otherDetails = new CommitDetails( new GitDiff(0, 135, 20), Collections.singletonList(renameB)); addCommitInPaprika(A); addCommitInRepository(A, details); addCommitInPaprika(B); addCommitInRepository(B, otherDetails); prepareGitLog(A, B); getCommitsAnalysis().query(); verify(commitQueries).commitInsertionStatement(projectId, A, details.diff); verify(commitQueries, times(0)).fileRenameInsertionStatement(projectId, A.sha, notJavaRename); verify(commitQueries).fileRenameInsertionStatement(projectId, A.sha, actualRename); verify(commitQueries).commitInsertionStatement(projectId, B, otherDetails.diff); verify(commitQueries).fileRenameInsertionStatement(projectId, B.sha, renameB); verify(developerQueries, times(2)).developerInsertStatement(A.authorEmail); verify(developerQueries, times(2)).projectDeveloperInsertStatement(projectId, A.authorEmail); }