@@ -58,14 +58,18 @@ public class TestSnapshotFileCache {
5858
5959  private  static  final  Logger  LOG  = LoggerFactory .getLogger (TestSnapshotFileCache .class );
6060  private  static  final  HBaseTestingUtility  UTIL  = new  HBaseTestingUtility ();
61+   // don't refresh the cache unless we tell it to 
62+   private  static  final  long  PERIOD  = Long .MAX_VALUE ;
6163  private  static  FileSystem  fs ;
6264  private  static  Path  rootDir ;
65+   private  static  Path  snapshotDir ;
6366
6467  @ BeforeClass 
6568  public  static  void  startCluster () throws  Exception  {
6669    UTIL .startMiniDFSCluster (1 );
6770    fs  = UTIL .getDFSCluster ().getFileSystem ();
6871    rootDir  = UTIL .getDefaultRootDirPath ();
72+     snapshotDir  = SnapshotDescriptionUtils .getSnapshotsDir (rootDir );
6973  }
7074
7175  @ AfterClass 
@@ -76,48 +80,57 @@ public static void stopCluster() throws Exception {
7680  @ After 
7781  public  void  cleanupFiles () throws  Exception  {
7882    // cleanup the snapshot directory 
79-     Path  snapshotDir  = SnapshotDescriptionUtils .getSnapshotsDir (rootDir );
8083    fs .delete (snapshotDir , true );
8184  }
8285
8386  @ Test 
8487  public  void  testLoadAndDelete () throws  IOException  {
85-     // don't refresh the cache unless we tell it to 
86-     long  period  = Long .MAX_VALUE ;
87-     SnapshotFileCache  cache  = new  SnapshotFileCache (fs , rootDir , period , 10000000 ,
88+     SnapshotFileCache  cache  = new  SnapshotFileCache (fs , rootDir , PERIOD , 10000000 ,
8889        "test-snapshot-file-cache-refresh" , new  SnapshotFiles ());
8990
90-     createAndTestSnapshotV1 (cache , "snapshot1a" , false , true );
91+     createAndTestSnapshotV1 (cache , "snapshot1a" , false , true ,  false );
9192
92-     createAndTestSnapshotV2 (cache , "snapshot2a" , false , true );
93+     createAndTestSnapshotV2 (cache , "snapshot2a" , false , true ,  false );
9394  }
9495
9596  @ Test 
9697  public  void  testReloadModifiedDirectory () throws  IOException  {
97-     // don't refresh the cache unless we tell it to 
98-     long  period  = Long .MAX_VALUE ;
99-     SnapshotFileCache  cache  = new  SnapshotFileCache (fs , rootDir , period , 10000000 ,
98+     SnapshotFileCache  cache  = new  SnapshotFileCache (fs , rootDir , PERIOD , 10000000 ,
10099        "test-snapshot-file-cache-refresh" , new  SnapshotFiles ());
101100
102-     createAndTestSnapshotV1 (cache , "snapshot1" , false , true );
101+     createAndTestSnapshotV1 (cache , "snapshot1" , false , true ,  false );
103102    // now delete the snapshot and add a file with a different name 
104-     createAndTestSnapshotV1 (cache , "snapshot1" , false , false );
103+     createAndTestSnapshotV1 (cache , "snapshot1" , false , false ,  false );
105104
106-     createAndTestSnapshotV2 (cache , "snapshot2" , false , true );
105+     createAndTestSnapshotV2 (cache , "snapshot2" , false , true ,  false );
107106    // now delete the snapshot and add a file with a different name 
108-     createAndTestSnapshotV2 (cache , "snapshot2" , false , false );
107+     createAndTestSnapshotV2 (cache , "snapshot2" , false , false ,  false );
109108  }
110109
111110  @ Test 
112111  public  void  testSnapshotTempDirReload () throws  IOException  {
113-     long  period  = Long .MAX_VALUE ;
114-     // This doesn't refresh cache until we invoke it explicitly 
115-     SnapshotFileCache  cache  = new  SnapshotFileCache (fs , rootDir , period , 10000000 ,
112+     SnapshotFileCache  cache  =
113+         new  SnapshotFileCache (fs , rootDir , PERIOD , 10000000 , "test-snapshot-file-cache-refresh" , new  SnapshotFiles ());
114+ 
115+     // Add a new non-tmp snapshot 
116+     createAndTestSnapshotV1 (cache , "snapshot0v1" , false , false , false );
117+     createAndTestSnapshotV1 (cache , "snapshot0v2" , false , false , false );
118+   }
119+ 
120+   @ Test 
121+   public  void  testCacheUpdatedWhenLastModifiedOfSnapDirNotUpdated () throws  IOException  {
122+     SnapshotFileCache  cache  = new  SnapshotFileCache (fs , rootDir , PERIOD , 10000000 ,
116123        "test-snapshot-file-cache-refresh" , new  SnapshotFiles ());
117124
118125    // Add a new non-tmp snapshot 
119-     createAndTestSnapshotV1 (cache , "snapshot0v1" , false , false );
120-     createAndTestSnapshotV1 (cache , "snapshot0v2" , false , false );
126+     createAndTestSnapshotV1 (cache , "snapshot1v1" , false , false , true );
127+     createAndTestSnapshotV1 (cache , "snapshot1v2" , false , false , true );
128+ 
129+     // Add a new tmp snapshot 
130+     createAndTestSnapshotV2 (cache , "snapshot2v1" , true , false , true );
131+ 
132+     // Add another tmp snapshot 
133+     createAndTestSnapshotV2 (cache , "snapshot2v2" , true , false , true );
121134  }
122135
123136  class  SnapshotFiles  implements  SnapshotFileCache .SnapshotFileInspector  {
@@ -130,23 +143,24 @@ public Collection<String> filesUnderSnapshot(final Path snapshotDir) throws IOEx
130143  }
131144
132145  private  SnapshotMock .SnapshotBuilder  createAndTestSnapshotV1 (final  SnapshotFileCache  cache ,
133-       final  String  name , final  boolean  tmp , final  boolean  removeOnExit ) throws  IOException  {
146+       final  String  name , final  boolean  tmp , final  boolean  removeOnExit , boolean  setFolderTime )
147+       throws  IOException  {
134148    SnapshotMock  snapshotMock  = new  SnapshotMock (UTIL .getConfiguration (), fs , rootDir );
135149    SnapshotMock .SnapshotBuilder  builder  = snapshotMock .createSnapshotV1 (name , name );
136-     createAndTestSnapshot (cache , builder , tmp , removeOnExit );
150+     createAndTestSnapshot (cache , builder , tmp , removeOnExit ,  setFolderTime );
137151    return  builder ;
138152  }
139153
140154  private  void  createAndTestSnapshotV2 (final  SnapshotFileCache  cache , final  String  name ,
141-       final  boolean  tmp , final  boolean  removeOnExit ) throws  IOException  {
155+       final  boolean  tmp , final  boolean  removeOnExit ,  boolean   setFolderTime ) throws  IOException  {
142156    SnapshotMock  snapshotMock  = new  SnapshotMock (UTIL .getConfiguration (), fs , rootDir );
143157    SnapshotMock .SnapshotBuilder  builder  = snapshotMock .createSnapshotV2 (name , name );
144-     createAndTestSnapshot (cache , builder , tmp , removeOnExit );
158+     createAndTestSnapshot (cache , builder , tmp , removeOnExit ,  setFolderTime );
145159  }
146160
147161  private  void  createAndTestSnapshot (final  SnapshotFileCache  cache ,
148162      final  SnapshotMock .SnapshotBuilder  builder ,
149-       final  boolean  tmp , final  boolean  removeOnExit ) throws  IOException  {
163+       final  boolean  tmp , final  boolean  removeOnExit ,  boolean   setFolderTime ) throws  IOException  {
150164    List <Path > files  = new  ArrayList <>();
151165    for  (int  i  = 0 ; i  < 3 ; ++i ) {
152166      for  (Path  filePath : builder .addRegion ()) {
@@ -157,6 +171,10 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,
157171    // Finalize the snapshot 
158172    builder .commit ();
159173
174+     if  (setFolderTime ) {
175+       fs .setTimes (snapshotDir , cache .getLastModifiedTime (), -1 );
176+     }
177+ 
160178    // Make sure that all files are still present 
161179    for  (Path  path : files ) {
162180      assertFalse ("Cache didn't find "  + path , contains (getNonSnapshotFiles (cache , path ), path ));
0 commit comments