Search in sources :

Example 1 with MavenIndexerWrapper

use of org.jetbrains.idea.maven.server.MavenIndexerWrapper in project intellij-community by JetBrains.

the class MavenIndicesStressTest method test1.

public void test1() throws Exception {
    MavenCustomRepositoryHelper helper;
    helper = new MavenCustomRepositoryHelper(myDir, "plugins", "local1", "local2");
    helper.copy("plugins", "local1");
    helper.copy("local2", "local1");
    //setRepositoryPath(fixture.getTestDataPath("local1"));
    final MavenIndexerWrapper indexer = MavenServerManager.getInstance().createIndexer();
    File indicesDir = new File(myDir, "indices");
    final MavenIndices indices = new MavenIndices(indexer, indicesDir, this);
    final MavenIndex index = indices.add("id", getRepositoryPath(), MavenIndex.Kind.LOCAL);
    final AtomicBoolean isFinished = new AtomicBoolean(false);
    Thread t1 = new Thread(() -> {
        try {
            for (int i = 0; i < 3; i++) {
                System.out.println("INDEXING #" + i);
                indices.updateOrRepair(index, true, getMavenGeneralSettings(), EMPTY_MAVEN_PROCESS);
            }
        } catch (MavenProcessCanceledException e) {
            throw new RuntimeException(e);
        } finally {
            isFinished.set(true);
        }
    }, "maven index 1");
    Thread t2 = new Thread(() -> {
        Random random = new Random();
        while (!isFinished.get()) {
            int i = random.nextInt(100);
            System.out.println("Adding artifact #" + i);
            //index.addArtifact(new MavenId("group" + i, "artifact" + i, "" + i));
            fail();
        }
    }, "maven index 2");
    t1.start();
    t2.start();
    do {
        t1.join(100);
        t2.join(100);
    } while (!isFinished.get());
    t1.join(100);
    t2.join(100);
    indices.close();
    t1.join();
    t2.join();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenCustomRepositoryHelper(org.jetbrains.idea.maven.MavenCustomRepositoryHelper) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) Random(java.util.Random) MavenIndexerWrapper(org.jetbrains.idea.maven.server.MavenIndexerWrapper) File(java.io.File)

Example 2 with MavenIndexerWrapper

use of org.jetbrains.idea.maven.server.MavenIndexerWrapper in project intellij-community by JetBrains.

the class MavenIndicesStressTest method test2.

public void test2() throws Exception {
    MavenCustomRepositoryHelper helper;
    helper = new MavenCustomRepositoryHelper(myDir, "plugins", "local1", "local2");
    helper.copy("plugins", "local1");
    helper.copy("local2", "local1");
    setRepositoryPath(helper.getTestDataPath("local1"));
    final MavenIndexerWrapper indexer = MavenServerManager.getInstance().createIndexer();
    File indicesDir = new File(myDir, "indices");
    MavenIndices indices = new MavenIndices(indexer, indicesDir, this);
    MavenIndex index = indices.add("id", getRepositoryPath(), MavenIndex.Kind.LOCAL);
    //index.addArtifact(new MavenId("group1", "artifact1", "1"));
    fail();
    indices.close();
    MavenIndices indices1 = new MavenIndices(indexer, indicesDir, this);
    MavenIndices indices2 = new MavenIndices(indexer, indicesDir, this);
    AtomicInteger finishedCount = new AtomicInteger(0);
    Thread t1 = createThread(indices1.getIndices().get(0), finishedCount);
    Thread t2 = createThread(indices2.getIndices().get(0), finishedCount);
    t1.start();
    t2.start();
    do {
        t1.join(100);
        t2.join(100);
    } while (finishedCount.get() < 2);
    t1.join(100);
    t2.join(100);
    indices.close();
    indices1.close();
    indices2.close();
    t1.join();
    t2.join();
}
Also used : MavenCustomRepositoryHelper(org.jetbrains.idea.maven.MavenCustomRepositoryHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MavenIndexerWrapper(org.jetbrains.idea.maven.server.MavenIndexerWrapper) File(java.io.File)

Aggregations

File (java.io.File)2 MavenCustomRepositoryHelper (org.jetbrains.idea.maven.MavenCustomRepositoryHelper)2 MavenIndexerWrapper (org.jetbrains.idea.maven.server.MavenIndexerWrapper)2 Random (java.util.Random)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MavenProcessCanceledException (org.jetbrains.idea.maven.utils.MavenProcessCanceledException)1