@@ -383,4 +383,50 @@ public void testRenamedFile() throws Exception {
383
383
updatedHistory = cache .get (reposRoot , repo , true );
384
384
assertEquals (14 , updatedHistory .getHistoryEntries ().size ());
385
385
}
386
+
387
+ private void checkNoHistoryFetchRepo (String reponame , String filename ,
388
+ boolean hasHistory , boolean historyFileExists ) throws Exception {
389
+
390
+ File reposRoot = new File (repositories .getSourceRoot (), reponame );
391
+ Repository repo = RepositoryFactory .getRepository (reposRoot );
392
+
393
+ // Make sure the file exists in the repository.
394
+ File repoFile = new File (reposRoot , filename );
395
+ assertTrue (repoFile .exists ());
396
+
397
+ // Try to fetch the history for given file. With default setting of
398
+ // FetchHistoryWhenNotInCache this should create corresponding file
399
+ // in history cache.
400
+ History retrievedHistory = cache .get (repoFile , repo , true );
401
+ assertEquals (hasHistory , retrievedHistory == null ? false : true );
402
+
403
+ // The file in history cache should not exist since
404
+ // FetchHistoryWhenNotInCache is set to false.
405
+ File dataRoot = new File (repositories .getDataRoot (),
406
+ "historycache" + File .separatorChar + reponame );
407
+ File fileHistory = new File (dataRoot , filename + ".gz" );
408
+ assertEquals (historyFileExists , fileHistory .exists ());
409
+ }
410
+
411
+ /*
412
+ * Functional test for the FetchHistoryWhenNotInCache configuration option.
413
+ */
414
+ public void testNoHistoryFetch () throws Exception {
415
+ // Do not create history cache for files which do not have it cached.
416
+ RuntimeEnvironment .getInstance ().setFetchHistoryWhenNotInCache (false );
417
+
418
+ // Make cache.get() predictable. Normally when the retrieval of
419
+ // history of given file is faster than the limit, the history of this
420
+ // file is not stored. For the sake of this test we want the history
421
+ // to be always stored.
422
+ RuntimeEnvironment .getInstance ().setHistoryReaderTimeLimit (0 );
423
+
424
+ // Pretend we are done with first phase of indexing.
425
+ cache .setHistoryIndexDone ();
426
+
427
+ // First try repo with ability to fetch history for directories.
428
+ checkNoHistoryFetchRepo ("mercurial" , "main.c" , false , false );
429
+ // Second try repo which can fetch history of individual files only.
430
+ checkNoHistoryFetchRepo ("teamware" , "header.h" , true , true );
431
+ }
386
432
}
0 commit comments