@@ -770,39 +770,12 @@ public void testPutKeyRatisThreeNodesParallel() throws IOException,
770770 public void testReadKeyWithVerifyChecksumFlagEnable () throws Exception {
771771 String volumeName = UUID .randomUUID ().toString ();
772772 String bucketName = UUID .randomUUID ().toString ();
773-
774- String value = "sample value" ;
775- store .createVolume (volumeName );
776- OzoneVolume volume = store .getVolume (volumeName );
777- volume .createBucket (bucketName );
778- OzoneBucket bucket = volume .getBucket (bucketName );
779773 String keyName = UUID .randomUUID ().toString ();
780774
781- // Write data into a key
782- OzoneOutputStream out = bucket .createKey (keyName ,
783- value .getBytes ().length , ReplicationType .RATIS ,
784- ReplicationFactor .ONE , new HashMap <>());
785- out .write (value .getBytes ());
786- out .close ();
787-
788- // We need to find the location of the chunk file corresponding to the
789- // data we just wrote.
790- OzoneKey key = bucket .getKey (keyName );
791- long containerID = ((OzoneKeyDetails ) key ).getOzoneKeyLocations ().get (0 )
792- .getContainerID ();
775+ // Create and corrupt key
776+ createAndCorruptKey (volumeName , bucketName , keyName );
793777
794- // Get the container by traversing the datanodes. Atleast one of the
795- // datanode must have this container.
796- Container container = null ;
797- for (HddsDatanodeService hddsDatanode : cluster .getHddsDatanodes ()) {
798- container = hddsDatanode .getDatanodeStateMachine ().getContainer ()
799- .getContainerSet ().getContainer (containerID );
800- if (container != null ) {
801- break ;
802- }
803- }
804- Assert .assertNotNull ("Container not found" , container );
805- corruptData (container , key );
778+ // read corrupt key with verify checksum enabled
806779 readCorruptedKey (volumeName , bucketName , keyName , true );
807780
808781 }
@@ -812,13 +785,23 @@ public void testReadKeyWithVerifyChecksumFlagEnable() throws Exception {
812785 public void testReadKeyWithVerifyChecksumFlagDisable () throws Exception {
813786 String volumeName = UUID .randomUUID ().toString ();
814787 String bucketName = UUID .randomUUID ().toString ();
788+ String keyName = UUID .randomUUID ().toString ();
789+
790+ // Create and corrupt key
791+ createAndCorruptKey (volumeName , bucketName , keyName );
815792
793+ // read corrupt key with verify checksum enabled
794+ readCorruptedKey (volumeName , bucketName , keyName , false );
795+
796+ }
797+
798+ private void createAndCorruptKey (String volumeName , String bucketName ,
799+ String keyName ) throws IOException {
816800 String value = "sample value" ;
817801 store .createVolume (volumeName );
818802 OzoneVolume volume = store .getVolume (volumeName );
819803 volume .createBucket (bucketName );
820804 OzoneBucket bucket = volume .getBucket (bucketName );
821- String keyName = UUID .randomUUID ().toString ();
822805
823806 // Write data into a key
824807 OzoneOutputStream out = bucket .createKey (keyName ,
@@ -845,8 +828,6 @@ public void testReadKeyWithVerifyChecksumFlagDisable() throws Exception {
845828 }
846829 Assert .assertNotNull ("Container not found" , container );
847830 corruptData (container , key );
848- readCorruptedKey (volumeName , bucketName , keyName , false );
849-
850831 }
851832
852833
0 commit comments