View Javadoc
1   package org.apache.maven.lifecycle.internal.builder.multithreaded;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
4    * agreements. See the NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
6    * "License"); you may not use this file except in compliance with the License. You may obtain a
7    * copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software distributed under the License
12   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13   * or implied. See the License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  
17  import junit.framework.TestCase;
18  import org.apache.maven.execution.ProjectDependencyGraph;
19  import org.apache.maven.lifecycle.internal.ProjectBuildList;
20  import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
21  import org.apache.maven.project.MavenProject;
22  
23  import java.util.List;
24  import java.util.Set;
25  
26  public class ConcurrencyDependencyGraphTest extends TestCase {
27  
28      public void testGraph() throws Exception {
29  
30          ProjectBuildList projectBuildList = ProjectDependencyGraphStub.getProjectBuildList(
31                  ProjectDependencyGraphStub.getMavenSession() );
32  
33          ProjectDependencyGraph projectDependencyGraph = new ProjectDependencyGraphStub();
34  
35          ConcurrencyDependencyGraph graph = new ConcurrencyDependencyGraph( projectBuildList, projectDependencyGraph );
36  
37          // start
38          assertEquals( 0, graph.getFinishedProjects().size() );
39          assertEquals( 6, graph.getNumberOfBuilds() );
40  
41          List<MavenProject> rootSchedulableBuilds = graph.getRootSchedulableBuilds();
42          // only Project.A has no dependences
43          assertEquals( 1, rootSchedulableBuilds.size() );
44          assertEquals( ProjectDependencyGraphStub.A, rootSchedulableBuilds.iterator().next() );
45          // double check A deps
46          List<MavenProject> dependenciesA = graph.getDependencies( ProjectDependencyGraphStub.A );
47          assertEquals( 0, dependenciesA.size() );
48  
49          assertEquals( 6, graph.getUnfinishedProjects().size() );
50  
51          List<MavenProject> schedulableNewProcesses = graph.markAsFinished( ProjectDependencyGraphStub.A );
52          // expect Project B, C
53          assertEquals( 2, schedulableNewProcesses.size() );
54          assertEquals( 1, graph.getFinishedProjects().size() );
55  
56          graph.markAsFinished( ProjectDependencyGraphStub.A );
57          // still only  A
58          assertEquals( 1, graph.getFinishedProjects().size() );
59  
60          Set<MavenProject> unfinishedProjects = graph.getUnfinishedProjects();
61          assertEquals( 5, unfinishedProjects.size() );
62  
63          graph.markAsFinished( schedulableNewProcesses.get( 0 ) );
64          assertEquals( 2, graph.getFinishedProjects().size() );
65          assertEquals( 4, graph.getUnfinishedProjects().size() );
66  
67          List<MavenProject> dependenciesC = graph.getDependencies( ProjectDependencyGraphStub.C );
68          // C depends only on A
69          assertEquals( 1, dependenciesC.size() );
70  
71          List<MavenProject> dependenciesX = graph.getDependencies( ProjectDependencyGraphStub.X );
72          // X depends only on B and C
73          assertEquals( 2, dependenciesX.size() );
74  
75          List<MavenProject> activeDependenciesC = graph.getActiveDependencies( ProjectDependencyGraphStub.C );
76          // A already finished
77          assertEquals( 0, activeDependenciesC.size() );
78  
79          List<MavenProject> activeDependenciesX = graph.getActiveDependencies( ProjectDependencyGraphStub.X );
80          // waiting for C
81          assertEquals( 1, activeDependenciesX.size() );
82      }
83  }