summaryrefslogtreecommitdiff
path: root/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/MavenPerformanceTest.java
blob: e98fe82ec4b845f5eec22282a00cf45a24107b95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.idea.maven.importing;

import com.intellij.idea.Bombed;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.maven.MavenImportingTestCase;
import org.jetbrains.idea.maven.project.MavenProject;

import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

// do not run on build server
@Bombed(year = 3000, month = Calendar.FEBRUARY, day = 1)
public abstract class MavenPerformanceTest extends MavenImportingTestCase {
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath("C:\\projects\\mvn\\_projects\\geronimo\\pom.xml");
    initProjectsManager(false);
    myProjectsManager.resetManagedFilesAndProfilesInTests(Collections.singletonList(file), Collections.<String>emptyList());
  }

  public void testReading() throws Exception {
    measure(4000, new Runnable() {
      @Override
      public void run() {
        waitForReadingCompletion();
      }
    });
  }

  public void testImporting() throws Exception {
    waitForReadingCompletion();
    measure(8, new Runnable() {
      @Override
      public void run() {
        myProjectsManager.importProjects();
      }
    });
  }

  public void testReImporting() throws Exception {
    waitForReadingCompletion();
    myProjectsManager.importProjects();
    measure(2, new Runnable() {
      @Override
      public void run() {
        myProjectsManager.importProjects();
      }
    });
  }

  public void testResolving() throws Exception {
    waitForReadingCompletion();
    List<MavenProject> mavenProjects = myProjectsManager.getProjects();
    Collections.sort(mavenProjects, new Comparator<MavenProject>() {
      @Override
      public int compare(MavenProject o1, MavenProject o2) {
        return o1.getPath().compareToIgnoreCase(o2.getPath());
      }
    });

    myProjectsManager.unscheduleAllTasksInTests();

    myProjectsManager.scheduleResolveInTests(mavenProjects.subList(0, 100));
    measure(50000, new Runnable() {
      @Override
      public void run() {
        myProjectsManager.waitForResolvingCompletion();
      }
    });
  }

  private static void measure(long expected, Runnable r) {
    //ProfilingUtil.startCPUProfiling();
    long before = System.currentTimeMillis();
    r.run();
    long after = System.currentTimeMillis();
    long timing = after - before;
    //System.out.println(getName() + ": " + timing + " ->" + ProfilingUtil.captureCPUSnapshot());
    //ProfilingUtil.stopCPUProfiling();
    assertTrue(timing < expected);
  }
}