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 import org.junit.jupiter.api.Test;
38
39 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.A;
40 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.B;
41 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.C;
42 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.X;
43 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Y;
44 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Z;
45 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.getProjectBuildList;
46 import static org.junit.jupiter.api.Assertions.assertEquals;
47
48
49
50
51 class ConcurrencyDependencyGraphTest {
52 @Test
53 void testConcurrencyGraphPrimaryVersion()
54 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
55 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException,
56 PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException {
57 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
58 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
59
60 ConcurrencyDependencyGraph graph =
61 new ConcurrencyDependencyGraph(getProjectBuildList(session), dependencyGraph);
62
63 final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds();
64 assertEquals(1, projectBuilds.size());
65 assertEquals(A, projectBuilds.iterator().next());
66
67 final List<MavenProject> subsequent = graph.markAsFinished(A);
68 assertEquals(2, subsequent.size());
69 assertEquals(ProjectDependencyGraphStub.B, subsequent.get(0));
70 assertEquals(C, subsequent.get(1));
71
72 final List<MavenProject> bDescendants = graph.markAsFinished(B);
73 assertEquals(1, bDescendants.size());
74 assertEquals(Y, bDescendants.get(0));
75
76 final List<MavenProject> cDescendants = graph.markAsFinished(C);
77 assertEquals(2, cDescendants.size());
78 assertEquals(X, cDescendants.get(0));
79 assertEquals(Z, cDescendants.get(1));
80 }
81
82 @Test
83 void testConcurrencyGraphDifferentCompletionOrder()
84 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
85 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException,
86 PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException {
87 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
88 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
89 ConcurrencyDependencyGraph graph =
90 new ConcurrencyDependencyGraph(getProjectBuildList(session), dependencyGraph);
91
92 graph.markAsFinished(A);
93 final List<MavenProject> cDescendants = graph.markAsFinished(C);
94 assertEquals(1, cDescendants.size());
95 assertEquals(Z, cDescendants.get(0));
96
97 final List<MavenProject> bDescendants = graph.markAsFinished(B);
98 assertEquals(2, bDescendants.size());
99 assertEquals(X, bDescendants.get(0));
100 assertEquals(Y, bDescendants.get(1));
101 }
102 }