1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle.internal;
20
21 import java.util.List;
22
23 import org.apache.maven.execution.MavenSession;
24 import org.apache.maven.execution.ProjectDependencyGraph;
25 import org.apache.maven.lifecycle.LifecycleNotFoundException;
26 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
27 import org.apache.maven.lifecycle.internal.builder.multithreaded.ConcurrencyDependencyGraph;
28 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
29 import org.apache.maven.plugin.InvalidPluginDescriptorException;
30 import org.apache.maven.plugin.MojoNotFoundException;
31 import org.apache.maven.plugin.PluginDescriptorParsingException;
32 import org.apache.maven.plugin.PluginNotFoundException;
33 import org.apache.maven.plugin.PluginResolutionException;
34 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
35 import org.apache.maven.plugin.version.PluginVersionResolutionException;
36 import org.apache.maven.project.MavenProject;
37
38 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.A;
39 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.B;
40 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.C;
41 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.X;
42 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Y;
43 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Z;
44 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.getProjectBuildList;
45
46
47
48
49 public class ConcurrencyDependencyGraphTest extends junit.framework.TestCase {
50 public void testConcurrencyGraphPrimaryVersion()
51 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
52 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException,
53 PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException {
54 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
55 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
56
57 ConcurrencyDependencyGraph graph =
58 new ConcurrencyDependencyGraph(getProjectBuildList(session), dependencyGraph);
59
60 final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds();
61 assertEquals(1, projectBuilds.size());
62 assertEquals(A, projectBuilds.iterator().next());
63
64 final List<MavenProject> subsequent = graph.markAsFinished(A);
65 assertEquals(2, subsequent.size());
66 assertEquals(B, subsequent.get(0));
67 assertEquals(C, subsequent.get(1));
68
69 final List<MavenProject> bDescendants = graph.markAsFinished(B);
70 assertEquals(1, bDescendants.size());
71 assertEquals(Y, bDescendants.get(0));
72
73 final List<MavenProject> cDescendants = graph.markAsFinished(C);
74 assertEquals(2, cDescendants.size());
75 assertEquals(X, cDescendants.get(0));
76 assertEquals(Z, cDescendants.get(1));
77 }
78
79 public void testConcurrencyGraphDifferentCompletionOrder()
80 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
81 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException,
82 PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException {
83 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
84 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
85 ConcurrencyDependencyGraph graph =
86 new ConcurrencyDependencyGraph(getProjectBuildList(session), dependencyGraph);
87
88 graph.markAsFinished(A);
89 final List<MavenProject> cDescendants = graph.markAsFinished(C);
90 assertEquals(1, cDescendants.size());
91 assertEquals(Z, cDescendants.get(0));
92
93 final List<MavenProject> bDescendants = graph.markAsFinished(B);
94 assertEquals(2, bDescendants.size());
95 assertEquals(X, bDescendants.get(0));
96 assertEquals(Y, bDescendants.get(1));
97 }
98 }