Search in sources :

Example 1 with RepositoryRevisionCache

use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.

the class RevisionsCacheTest method test_equals.

public void test_equals() throws Exception {
    RepositoryRevisionCache cache1 = new RepositoryRevisionCache(myConfig, repository("1"), RevisionCacheType.COMMIT_CACHE, 100);
    RepositoryRevisionCache cache2 = new RepositoryRevisionCache(myConfig, repository("1"), RevisionCacheType.COMMIT_CACHE, 100);
    RepositoryRevisionCache cache3 = new RepositoryRevisionCache(myConfig, repository("1"), RevisionCacheType.HINT_CACHE, 100);
    then(cache1).isEqualTo(cache2);
    then(cache1).isNotEqualTo(cache3);
    cache1.saveRevision("v1", true, cache1.getResetCounter());
    cache1.saveRevision("v2", false, cache1.getResetCounter());
    cache2.saveRevision("v1", true, cache2.getResetCounter());
    cache2.saveRevision("v2", false, cache2.getResetCounter());
    then(cache1).isEqualTo(cache2);
    cache1.saveRevision("v3", true, cache1.getResetCounter());
    then(cache1).isNotEqualTo(cache2);
    cache2.saveRevision("v3", true, cache2.getResetCounter());
    cache2.saveRevision("v4", false, cache2.getResetCounter());
    then(cache1).isNotEqualTo(cache2);
}
Also used : RepositoryRevisionCache(jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache)

Example 2 with RepositoryRevisionCache

use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.

the class RevisionsCacheTest method disable_persist.

public void disable_persist() throws Exception {
    myConfigBuilder.setPersistentCacheEnabled(false);
    File repo = repository("1");
    RepositoryRevisionCache repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
    repoCache.saveRevision("v1", false, repoCache.getResetCounter());
    then(RepositoryRevisionCache.getCacheFile(repo, RevisionCacheType.COMMIT_CACHE)).doesNotExist();
    myConfigBuilder.setPersistentCacheEnabled(true);
    repoCache.saveRevision("v1", false, repoCache.getResetCounter());
    repoCache.saveRevision("v2", false, repoCache.getResetCounter());
    then(RepositoryRevisionCache.getCacheFile(repo, RevisionCacheType.COMMIT_CACHE)).exists();
}
Also used : RepositoryRevisionCache(jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache) File(java.io.File)

Example 3 with RepositoryRevisionCache

use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.

the class RevisionsCacheTest method should_not_save_revision_if_there_was_reset.

@TestFor(issues = { "TW-23460" })
@Test(dataProvider = "reset")
public void should_not_save_revision_if_there_was_reset(@NotNull BiConsumer<RevisionsCache, File> reset) throws Exception {
    File repo = repository("1");
    Semaphore s1 = new Semaphore(1);
    s1.acquire();
    Semaphore s2 = new Semaphore(1);
    s2.acquire();
    Thread mapFullPath = new Thread(() -> {
        try {
            RepositoryRevisionCache repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
            long resetCounter = repoCache.getResetCounter();
            if (repoCache.hasRevision("v1") == null) {
                s1.release();
                // long commit lookup (we didn't find it)
                s2.acquire();
                repoCache.saveRevision("v1", false, resetCounter);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    });
    mapFullPath.start();
    // collect changes which resets cache:
    s1.acquire();
    reset.accept(myCache, repo);
    s2.release();
    mapFullPath.join();
    then(myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE).hasRevision("v1")).isNull();
}
Also used : Semaphore(java.util.concurrent.Semaphore) RepositoryRevisionCache(jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache) File(java.io.File) IOException(java.io.IOException) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 4 with RepositoryRevisionCache

use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.

the class RevisionsCacheTest method disabled_persist_remove_cache_file.

public void disabled_persist_remove_cache_file() throws Exception {
    // in order to not load stale data after restart
    File repo = repository("1");
    RepositoryRevisionCache repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
    repoCache.saveRevision("v1", false, repoCache.getResetCounter());
    myConfigBuilder.setPersistentCacheEnabled(false);
    repoCache.saveRevision("v1", true, repoCache.getResetCounter());
    myConfigBuilder.setPersistentCacheEnabled(true);
    RepositoryRevisionCache repoCache2 = new RevisionsCache(myConfig).getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
    // should have no information on v1 after restart, especially 'false'
    then(repoCache2.hasRevision("v1")).isNull();
}
Also used : RepositoryRevisionCache(jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache) RevisionsCache(jetbrains.buildServer.buildTriggers.vcs.git.RevisionsCache) File(java.io.File)

Example 5 with RepositoryRevisionCache

use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.

the class RevisionsCacheTest method reset_negative_entries_with_new_commits.

public void reset_negative_entries_with_new_commits() throws Exception {
    File repo = repository("1");
    RepositoryRevisionCache repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
    repoCache.saveRevision("v1", false, repoCache.getResetCounter());
    repoCache.saveRevision("v2", true, repoCache.getResetCounter());
    repoCache.saveRevision("v3", false, repoCache.getResetCounter());
    myCache.resetNegativeEntries(repo, setOf("v3", "v4"));
    then(repoCache.hasRevision("v1")).isFalse();
    then(repoCache.hasRevision("v2")).isTrue();
    then(repoCache.hasRevision("v3")).isTrue();
    then(repoCache).isEqualTo(new RevisionsCache(myConfig).getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE));
}
Also used : RepositoryRevisionCache(jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache) RevisionsCache(jetbrains.buildServer.buildTriggers.vcs.git.RevisionsCache) File(java.io.File)

Aggregations

RepositoryRevisionCache (jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache)17 File (java.io.File)15 RevisionsCache (jetbrains.buildServer.buildTriggers.vcs.git.RevisionsCache)9 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 RevisionCacheType (jetbrains.buildServer.buildTriggers.vcs.git.RevisionCacheType)2 Test (org.testng.annotations.Test)2 Semaphore (java.util.concurrent.Semaphore)1 ServerPluginConfig (jetbrains.buildServer.buildTriggers.vcs.git.ServerPluginConfig)1 TestFor (jetbrains.buildServer.util.TestFor)1