1+ package org .apache .hadoop .ozone .om ;
2+
3+ import java .io .IOException ;
4+ import java .util .ArrayList ;
5+
6+ import org .apache .hadoop .hdds .HddsConfigKeys ;
7+ import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
8+ import org .apache .hadoop .hdds .protocol .StorageType ;
9+ import org .apache .hadoop .hdds .protocol .proto .HddsProtos .ReplicationFactor ;
10+ import org .apache .hadoop .hdds .protocol .proto .HddsProtos .ReplicationType ;
11+ import org .apache .hadoop .hdds .scm .protocol .ScmBlockLocationProtocol ;
12+ import org .apache .hadoop .ozone .om .helpers .OmBucketInfo ;
13+ import org .apache .hadoop .ozone .om .helpers .OmKeyArgs ;
14+ import org .apache .hadoop .ozone .om .helpers .OmKeyArgs .Builder ;
15+ import org .apache .hadoop .ozone .om .helpers .OmMultipartInfo ;
16+ import org .apache .hadoop .ozone .om .helpers .OmMultipartUploadListParts ;
17+ import org .apache .hadoop .ozone .security .OzoneBlockTokenSecretManager ;
18+ import org .apache .hadoop .test .GenericTestUtils ;
19+
20+ import org .junit .Assert ;
21+ import org .junit .Before ;
22+ import org .junit .Test ;
23+ import org .mockito .Mockito ;
24+
25+ /**
26+ * Unit test key manager.
27+ */
28+ public class TestKeyManagerUnit {
29+
30+ private OmMetadataManagerImpl metadataManager ;
31+ private KeyManagerImpl keyManager ;
32+
33+ @ Before
34+ public void setup () throws IOException {
35+ OzoneConfiguration configuration = new OzoneConfiguration ();
36+ configuration .set (HddsConfigKeys .OZONE_METADATA_DIRS ,
37+ GenericTestUtils .getRandomizedTestDir ().toString ());
38+ metadataManager = new OmMetadataManagerImpl (configuration );
39+ keyManager = new KeyManagerImpl (
40+ Mockito .mock (ScmBlockLocationProtocol .class ),
41+ metadataManager ,
42+ configuration ,
43+ "omtest" ,
44+ Mockito .mock (OzoneBlockTokenSecretManager .class )
45+ );
46+ }
47+
48+ @ Test
49+ public void listMultipartUploadPartsWithZeroUpload () throws IOException {
50+ //GIVEN
51+ createBucket (metadataManager , "vol1" , "bucket1" );
52+
53+ OmMultipartInfo omMultipartInfo =
54+ initMultipartUpload (keyManager , "vol1" , "bucket1" , "dir/key1" );
55+
56+ //WHEN
57+ OmMultipartUploadListParts omMultipartUploadListParts = keyManager
58+ .listParts ("vol1" , "bucket1" , "dir/key1" , omMultipartInfo .getUploadID (),
59+ 0 , 10 );
60+
61+ Assert .assertEquals (0 ,
62+ omMultipartUploadListParts .getPartInfoList ().size ());
63+
64+ }
65+
66+ private void createBucket (OmMetadataManagerImpl omMetadataManager ,
67+ String volume , String bucket )
68+ throws IOException {
69+ omMetadataManager .getBucketTable ()
70+ .put (omMetadataManager .getBucketKey (volume , bucket ),
71+ OmBucketInfo .newBuilder ()
72+ .setVolumeName (volume )
73+ .setBucketName (bucket )
74+ .setStorageType (StorageType .DISK )
75+ .setIsVersionEnabled (false )
76+ .setAcls (new ArrayList <>())
77+ .build ());
78+ }
79+
80+ private OmMultipartInfo initMultipartUpload (KeyManagerImpl omtest ,
81+ String volume , String bucket , String key )
82+ throws IOException {
83+ OmKeyArgs key1 = new Builder ()
84+ .setVolumeName (volume )
85+ .setBucketName (bucket )
86+ .setKeyName (key )
87+ .setType (ReplicationType .RATIS )
88+ .setFactor (ReplicationFactor .THREE )
89+ .setAcls (new ArrayList <>())
90+ .build ();
91+ return omtest .initiateMultipartUpload (key1 );
92+ }
93+ }
0 commit comments