11package gov .nist .oar .distrib .cachemgr ;
22
3- import static org .junit .jupiter .api .Assertions .assertThrows ;
43import static org .mockito .ArgumentMatchers .anyString ;
54import static org .mockito .Mockito .never ;
65import static org .mockito .Mockito .verify ;
@@ -32,8 +31,8 @@ public void setUp() {
3231
3332 /**
3433 * Test to verify that {@link CacheExpiryCheck} correctly identifies and processes an expired cache object.
35- * An object is considered expired based on the `expires` metadata, which defines the duration after which
36- * an object should be considered expired from the time of its last modification . This test ensures that an object
34+ * An object is considered expired based on the `expires` metadata, which defines the absolute epoch
35+ * millisecond time when the object should expire . This test ensures that an object
3736 * past its expiration is appropriately removed from the inventory database.
3837 *
3938 * @throws Exception to handle any exceptions thrown during the test execution
@@ -43,8 +42,7 @@ public void testExpiredObjectRemoval() throws Exception {
4342 // Setup an expired cache object
4443 cacheObject .volume = mockVolume ;
4544 when (cacheObject .hasMetadatum ("expires" )).thenReturn (true );
46- when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (1000L ); // Expires in 1 second
47- when (cacheObject .getLastModified ()).thenReturn (Instant .now ().minusSeconds (10 ).toEpochMilli ());
45+ when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (Instant .now ().minusSeconds (1 ).toEpochMilli ());
4846 when (cacheObject .volume .remove (cacheObject .name )).thenReturn (true );
4947
5048 expiryCheck .check (cacheObject );
@@ -55,7 +53,7 @@ public void testExpiredObjectRemoval() throws Exception {
5553
5654 /**
5755 * Test to ensure that {@link CacheExpiryCheck} does not flag a cache object as expired if the current time has not
58- * exceeded its `expires` duration since its last modification . This test verifies that no removal action is taken
56+ * exceeded its absolute `expires` time . This test verifies that no removal action is taken
5957 * for such non-expired objects.
6058 *
6159 * @throws Exception to handle any exceptions thrown during the test execution
@@ -66,9 +64,7 @@ public void testNonExpiredObject() throws Exception {
6664 cacheObject .name = "nonExpiredObject" ;
6765 cacheObject .volname = "testVolume" ;
6866 when (cacheObject .hasMetadatum ("expires" )).thenReturn (true );
69- when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (14 * 24 * 60 * 60 * 1000L ); // 14 days in milliseconds
70- long lastModified = System .currentTimeMillis () - (7 * 24 * 60 * 60 * 1000L ); // 7 days ago, within expiry period
71- when (cacheObject .getLastModified ()).thenReturn (lastModified );
67+ when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (System .currentTimeMillis () + (7 * 24 * 60 * 60 * 1000L ));
7268
7369 // Perform the check
7470 expiryCheck .check (cacheObject );
@@ -106,7 +102,6 @@ public void testNonExpiredObject_NoRemoval() throws Exception {
106102 // Setup a non-expired cache object
107103 when (cacheObject .hasMetadatum ("expires" )).thenReturn (true );
108104 when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (System .currentTimeMillis () + 10000L ); // Expires in the future
109- when (cacheObject .getLastModified ()).thenReturn (System .currentTimeMillis ());
110105
111106 expiryCheck .check (cacheObject );
112107
@@ -115,22 +110,20 @@ public void testNonExpiredObject_NoRemoval() throws Exception {
115110 }
116111
117112 /**
118- * Tests that an {@link IntegrityException} is thrown when a cache object has the {@code expires} metadata
119- * but lacks a valid {@code lastModified} time.
113+ * Tests that lastModified is not required because {@code expires} is stored as an absolute timestamp.
120114 *
121115 * @throws Exception to handle any exceptions thrown during the test execution
122116 */
123117 @ Test
124- public void testObjectWithExpiresButNoLastModified_ThrowsException () throws Exception {
118+ public void testObjectWithExpiresButNoLastModified_UsesAbsoluteExpires () throws Exception {
125119 cacheObject .name = "objectWithNoLastModified" ;
126120 cacheObject .volname = "testVolume" ;
127121 when (cacheObject .hasMetadatum ("expires" )).thenReturn (true );
128- when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (1000L ); // Expires in 1 second
129- when (cacheObject .getLastModified ()).thenReturn (-1L ); // Last modified not available
122+ when (cacheObject .getMetadatumLong ("expires" , -1L )).thenReturn (System .currentTimeMillis () + 10000L );
130123
131- assertThrows ( IntegrityException . class , () -> {
132- expiryCheck . check ( cacheObject );
133- } );
124+ expiryCheck . check ( cacheObject );
125+
126+ verify ( mockInventoryDB , never ()). removeObject ( anyString (), anyString () );
134127 }
135128
136129 /**
0 commit comments