BranchQuery extends PersistenceAnalyzer implements Query { @Override public void query() throws QueryException { logger.info("[" + projectId + "] Starting Branches insertion"); Commit commit = retrieveHeadCommit(); List<Branch> branches = buildBranchTree(null, commit); for (Branch branch : branches) { persistBranch(branch); } persistence.commit(); } BranchQuery(int projectId, Repository repository,
                       Persistence persistence, CommitQueries commitQueries, BranchQueries branchQueries); @Override void query();  }
@Test public void testOverlappingBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Collections.singletonList(D)); Commit F = new Commit("f", 6, Collections.singletonList(D)); Commit G = new Commit("g", 7, Arrays.asList(F, E)); Commit H = new Commit("h", 8, Collections.singletonList(C)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(12)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 4); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, F.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 2); verify(branchQueries).branchInsertionStatement(projectId, 2, D, G); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, E.sha, 0); }
@Test public void testParallelBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Collections.singletonList(A)); Commit F = new Commit("f", 6, Collections.singletonList(D)); Commit G = new Commit("g", 7, Collections.singletonList(F)); Commit H = new Commit("h", 8, Arrays.asList(C, E)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(12)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 4); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, F.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 2); verify(branchQueries).branchInsertionStatement(projectId, 2, A, H); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, E.sha, 0); }
@Test public void testCrossedBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Collections.singletonList(B)); Commit F = new Commit("f", 6, Arrays.asList(C, D)); Commit G = new Commit("g", 7, Collections.singletonList(E)); Commit H = new Commit("h", 8, Arrays.asList(F, G)); initializeHead(H); initializeMocks(A, B, C, D, E, F, G, H); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(11)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 4); verify(branchQueries).branchInsertionStatement(projectId, 1, B, H); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 1); verify(branchQueries).branchInsertionStatement(projectId, 2, A, F); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, D.sha, 0); }
@Test public void testMergeBackAndForth() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Arrays.asList(D, C)); Commit F = new Commit("f", 6, Collections.singletonList(C)); Commit G = new Commit("g", 7, Collections.singletonList(E)); Commit H = new Commit("h", 8, Collections.singletonList(F)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(11)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 4); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 5); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 2); }
@Test public void testMergeNotInDirectParent() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Collections.singletonList(D)); Commit F = new Commit("f", 6, Collections.singletonList(D)); Commit G = new Commit("g", 7, Arrays.asList(C, E)); Commit H = new Commit("h", 8, Collections.singletonList(F)); Commit I = new Commit("i", 9, Arrays.asList(G, H)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(12)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, G.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 4); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, F.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, H.sha, 2); verify(branchQueries).branchInsertionStatement(projectId, 2, D, G); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, E.sha, 0); }
@Test public void testMergeIsLastBranchCommit() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Arrays.asList(B, C)); Commit E = new Commit("e", 4, Arrays.asList(B, D)); Commit F = new Commit("f", 6, Arrays.asList(A, E)); initializeHead(F); initializeMocks(A, B, C, D, E, F); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(10)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 1); verify(branchQueries).branchInsertionStatement(projectId, 1, A, F); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, B.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 1); verify(branchQueries).branchInsertionStatement(projectId, 2, B, E); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, D.sha, 0); verify(branchQueries).branchInsertionStatement(projectId, 3, B, D); verify(branchQueries).branchCommitInsertionQuery(projectId, 3, C.sha, 0); }
@Test public void testNoMerge() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); initializeHead(C); initializeMocks(A, B, C); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(4)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); }
@Test public void testSingleMergeCommit() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Collections.singletonList(D)); Commit F = new Commit("f", 6, Arrays.asList(C, E)); initializeHead(F); initializeMocks(A, B, C, D, E, F); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(8)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchInsertionStatement(projectId, 1, A, F); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 1); }
@Test public void testSuccessiveBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 5, Collections.singletonList(A)); Commit E = new Commit("e", 4, Collections.singletonList(D)); Commit F = new Commit("f", 6, Arrays.asList(C, E)); Commit G = new Commit("g", 7, Collections.singletonList(F)); Commit H = new Commit("h", 8, Collections.singletonList(F)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(12)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 4); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 5); verify(branchQueries).branchInsertionStatement(projectId, 1, F, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 0); verify(branchQueries).branchInsertionStatement(projectId, 2, A, F); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 2, E.sha, 1); }
@Test public void testContinuingBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Collections.singletonList(B)); Commit D = new Commit("d", 4, Collections.singletonList(A)); Commit E = new Commit("e", 5, Collections.singletonList(D)); Commit F = new Commit("f", 6, Arrays.asList(C, E)); Commit G = new Commit("g", 7, Collections.singletonList(E)); Commit H = new Commit("h", 8, Collections.singletonList(F)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(11)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, C.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 4); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 5); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, D.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 2); }
@Test public void testCyclicMergesBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Arrays.asList(A, B)); Commit D = new Commit("d", 4, Arrays.asList(B, C)); Commit E = new Commit("e", 5, Arrays.asList(C, D)); Commit F = new Commit("f", 6, Arrays.asList(D, E)); Commit G = new Commit("g", 7, Arrays.asList(E, F)); Commit H = new Commit("h", 8, Collections.singletonList(F)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(11)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, D.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 4); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 5); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, C.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 2); }
@Test public void testSuccessiveMergesBranches() throws QueryException, IOException { Commit A = new Commit("a", 1); Commit B = new Commit("b", 2, Collections.singletonList(A)); Commit C = new Commit("c", 3, Arrays.asList(A, B)); Commit D = new Commit("d", 4, Collections.singletonList(B)); Commit E = new Commit("e", 5, Arrays.asList(C, D)); Commit F = new Commit("f", 6, Collections.singletonList(D)); Commit G = new Commit("g", 7, Arrays.asList(E, F)); Commit H = new Commit("h", 8, Collections.singletonList(F)); Commit I = new Commit("i", 9, Arrays.asList(H, G)); initializeHead(I); initializeMocks(A, B, C, D, E, F, G, H, I); getQuery().query(); debugBranchCommitInsertions(); verify(persistence, times(11)).addStatements(any()); verify(branchQueries).branchInsertionStatement(projectId, 0, null, null); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, A.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, B.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, D.sha, 2); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, F.sha, 3); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, H.sha, 4); verify(branchQueries).branchCommitInsertionQuery(projectId, 0, I.sha, 5); verify(branchQueries).branchInsertionStatement(projectId, 1, A, I); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, C.sha, 0); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, E.sha, 1); verify(branchQueries).branchCommitInsertionQuery(projectId, 1, G.sha, 2); }