@@ -1651,4 +1651,95 @@ public void testGetSnapshotDiffReportJob() throws Exception {
16511651 }
16521652 }
16531653 }
1654+
1655+ @ Test
1656+ public void testSnapshotDiffReportWithObjectTags () throws IOException {
1657+ Map <String , String > originalTags = new HashMap <>();
1658+ originalTags .put ("Environment" , "Production" );
1659+ originalTags .put ("Team" , "Backend" );
1660+
1661+ Map <String , String > modifiedTags = new HashMap <>();
1662+ modifiedTags .put ("Environment" , "Staging" );
1663+ modifiedTags .put ("Team" , "Backend" );
1664+
1665+ OmKeyInfo keyWithOriginalTags = new OmKeyInfo .Builder ()
1666+ .setObjectID (100 )
1667+ .setParentObjectID (200 )
1668+ .setVolumeName (VOLUME_NAME )
1669+ .setBucketName (BUCKET_NAME )
1670+ .setKeyName ("key-with-tags" )
1671+ .setReplicationConfig (new ECReplicationConfig (3 , 2 ))
1672+ .addAllTags (originalTags )
1673+ .build ();
1674+
1675+ OmKeyInfo keyWithModifiedTags = new OmKeyInfo .Builder ()
1676+ .setObjectID (100 )
1677+ .setParentObjectID (200 )
1678+ .setVolumeName (VOLUME_NAME )
1679+ .setBucketName (BUCKET_NAME )
1680+ .setKeyName ("key-with-tags" )
1681+ .setReplicationConfig (new ECReplicationConfig (3 , 2 ))
1682+ .addAllTags (modifiedTags )
1683+ .build ();
1684+
1685+ assertFalse (keyWithOriginalTags .isKeyInfoSame (keyWithModifiedTags ,
1686+ false , false , false , false , true ));
1687+
1688+ PersistentMap <byte [], byte []> oldObjectIdKeyMap = new StubbedPersistentMap <>();
1689+ PersistentMap <byte [], byte []> newObjectIdKeyMap = new StubbedPersistentMap <>();
1690+ PersistentMap <byte [], Boolean > objectIdToIsDirMap = new StubbedPersistentMap <>();
1691+
1692+ byte [] objectId100 = codecRegistry .asRawData (100L );
1693+ byte [] keyNameBytes = codecRegistry .asRawData ("key-with-tags" );
1694+ oldObjectIdKeyMap .put (objectId100 , keyNameBytes );
1695+ newObjectIdKeyMap .put (objectId100 , keyNameBytes );
1696+ objectIdToIsDirMap .put (objectId100 , false );
1697+
1698+ Map <String , WithParentObjectId > fromSnapshotTableMap = new HashMap <>();
1699+ Map <String , WithParentObjectId > toSnapshotTableMap = new HashMap <>();
1700+ fromSnapshotTableMap .put ("key-with-tags" , keyWithOriginalTags );
1701+ toSnapshotTableMap .put ("key-with-tags" , keyWithModifiedTags );
1702+
1703+ try (MockedStatic <SnapshotUtils > mockedSnapshotUtils = mockStatic (SnapshotUtils .class )) {
1704+ mockedSnapshotUtils .when (() ->
1705+ SnapshotUtils .isBlockLocationInfoSame (any (OmKeyInfo .class ), any (OmKeyInfo .class )))
1706+ .thenCallRealMethod ();
1707+
1708+ String tableName = "KeyTable" ;
1709+ Table <String , OmKeyInfo > fromSnapshotTable = mock (Table .class );
1710+ when (fromSnapshotTable .get (anyString ())).thenAnswer (i ->
1711+ fromSnapshotTableMap .get (i .getArgument (0 )));
1712+ when (fromSnapshotTable .getName ()).thenReturn (tableName );
1713+
1714+ Table <String , OmKeyInfo > toSnapshotTable = mock (Table .class );
1715+ when (toSnapshotTable .get (anyString ())).thenAnswer (i ->
1716+ toSnapshotTableMap .get (i .getArgument (0 )));
1717+ when (fromSnapshotTable .getName ()).thenReturn (tableName );
1718+
1719+ Map <String , String > tablePrefixes = mock (Map .class );
1720+ when (tablePrefixes .get (anyString ())).thenReturn ("" );
1721+
1722+ SnapshotDiffManager spy = spy (snapshotDiffManager );
1723+ doReturn (true ).when (spy )
1724+ .areDiffJobAndSnapshotsActive (VOLUME_NAME , BUCKET_NAME , "fromSnap" , "toSnap" );
1725+
1726+ long totalDiffEntries = spy .generateDiffReport ("jobId" ,
1727+ fromSnapshotTable , toSnapshotTable , null , null ,
1728+ objectIdToIsDirMap , oldObjectIdKeyMap , newObjectIdKeyMap ,
1729+ VOLUME_NAME , BUCKET_NAME , "fromSnap" , "toSnap" , false ,
1730+ Optional .empty (), Optional .empty (), tablePrefixes );
1731+
1732+ assertEquals (1 , totalDiffEntries );
1733+
1734+ SnapshotDiffJob snapshotDiffJob = new SnapshotDiffJob (0 , "jobId" ,
1735+ JobStatus .DONE , VOLUME_NAME , BUCKET_NAME , "fromSnap" , "toSnap" ,
1736+ false , true , 1 , null , 0.0 );
1737+ SnapshotDiffReportOzone diffReport = snapshotDiffManager .createPageResponse (
1738+ snapshotDiffJob , VOLUME_NAME , BUCKET_NAME , "fromSnap" , "toSnap" ,
1739+ 0 , Integer .MAX_VALUE );
1740+
1741+ DiffReportEntry entry = diffReport .getDiffList ().get (0 );
1742+ assertEquals (SnapshotDiffReport .DiffType .MODIFY , entry .getType ());
1743+ }
1744+ }
16541745}
0 commit comments