use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.
the class RevisionsCacheTest method hint_cache_size_should_be_enough_to_keep_all_repositories.
public void hint_cache_size_should_be_enough_to_keep_all_repositories() throws Exception {
// create more repositories than configured cache size
myConfigBuilder.setMapFullPathRevisionCacheSize(2);
List<File> repositories = new ArrayList<>();
for (int i = 0; i < 4; i++) {
repositories.add(repository(String.valueOf(i)));
}
myCache = new RevisionsCache(myConfig);
// and doesn't contain revisions from other repositories
for (File repo : repositories) {
RepositoryRevisionCache cache = myCache.getRepositoryCache(repo, RevisionCacheType.HINT_CACHE);
int repoNum = Integer.parseInt(repo.getName());
for (int i = 0; i < 4; i++) {
boolean contains = repoNum == i;
cache.saveRevision("v" + i, contains, cache.getResetCounter());
}
}
// check that all revisions are in cache
for (File repo : repositories) {
int repoNum = Integer.parseInt(repo.getName());
RepositoryRevisionCache cache = myCache.getRepositoryCache(repo, RevisionCacheType.HINT_CACHE);
for (int i = 0; i < 4; i++) {
boolean contains = repoNum == i;
then(cache.hasRevision("v" + i)).isEqualTo(contains);
}
}
RepositoryRevisionCache cache5 = myCache.getRepositoryCache(repository("5"), RevisionCacheType.HINT_CACHE);
cache5.saveRevision("v1", false, cache5.getResetCounter());
cache5.saveRevision("v2", false, cache5.getResetCounter());
cache5.saveRevision("v3", false, cache5.getResetCounter());
then(cache5.hasRevision("v1")).isFalse();
then(cache5.hasRevision("v2")).isFalse();
then(cache5.hasRevision("v3")).isFalse();
}
use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.
the class RevisionsCacheTest method should_detect_broken_cache.
public void should_detect_broken_cache() 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());
FileUtil.writeFile(RepositoryRevisionCache.getCacheFile(repo, RevisionCacheType.COMMIT_CACHE), "broken\n+data");
try {
RepositoryRevisionCache.read(myConfig, repo, RevisionCacheType.COMMIT_CACHE, 100);
fail("Should fail to read broken cache");
} catch (IOException e) {
then(e.getMessage()).isEqualTo("Bad cache line 'broken'");
}
}
use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.
the class RevisionsCacheTest method reset_cache.
public void reset_cache() throws Exception {
File repo = repository("1");
RepositoryRevisionCache repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
long resetCounter = repoCache.getResetCounter();
repoCache.saveRevision("v1", true, resetCounter);
repoCache.reset();
then(repoCache.hasRevision("v1")).isNull();
then(RepositoryRevisionCache.getCacheFile(repo, RevisionCacheType.COMMIT_CACHE)).doesNotExist();
repoCache.saveRevision("v2", false, resetCounter);
then(repoCache.hasRevision("v2")).isNull();
}
use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.
the class RevisionsCacheTest method should_contain_last_n_revisions.
@Test(dataProvider = "true,false")
public void should_contain_last_n_revisions(boolean afterRestart) throws Exception {
int cacheSize = 10;
myConfigBuilder.setMapFullPathRevisionCacheSize(cacheSize);
ServerPluginConfig config = myConfigBuilder.build();
myCache = new RevisionsCache(config);
File repo = repository("1");
RepositoryRevisionCache repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
for (int i = 0; i < 100; i++) {
repoCache.saveRevision("v" + i, true, repoCache.getResetCounter());
}
if (afterRestart) {
myCache = new RevisionsCache(config);
repoCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
}
for (int i = 100 - cacheSize; i < 100; i++) {
then(repoCache.hasRevision("v" + i)).overridingErrorMessage("Doesn't contain entry for revision v" + i).isTrue();
}
}
use of jetbrains.buildServer.buildTriggers.vcs.git.RepositoryRevisionCache in project teamcity-git by JetBrains.
the class RevisionsCacheTest method reset_negative_entries_different_types.
public void reset_negative_entries_different_types() throws Exception {
File repo = repository("1");
RepositoryRevisionCache commitCache = myCache.getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE);
commitCache.saveRevision("v1", false, commitCache.getResetCounter());
commitCache.saveRevision("v2", true, commitCache.getResetCounter());
commitCache.saveRevision("v3", false, commitCache.getResetCounter());
RepositoryRevisionCache hintCache = myCache.getRepositoryCache(repo, RevisionCacheType.HINT_CACHE);
hintCache.saveRevision("v4", false, hintCache.getResetCounter());
myCache.resetNegativeEntries(repo);
for (RevisionCacheType type : RevisionCacheType.values()) {
then(myCache.getRepositoryCache(repo, type).hasRevision("v1")).isNull();
then(myCache.getRepositoryCache(repo, type).hasRevision("v3")).isNull();
then(myCache.getRepositoryCache(repo, type).hasRevision("v4")).isNull();
}
then(commitCache).isEqualTo(new RevisionsCache(myConfig).getRepositoryCache(repo, RevisionCacheType.COMMIT_CACHE));
then(hintCache).isEqualTo(new RevisionsCache(myConfig).getRepositoryCache(repo, RevisionCacheType.HINT_CACHE));
}
Aggregations