1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one
3+ * or more contributor license agreements. See the NOTICE file
4+ * distributed with this work for additional information
5+ * regarding copyright ownership. The ASF licenses this file
6+ * to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance
8+ * with the License. You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing, software
13+ * distributed under the License is distributed on an "AS IS" BASIS,
14+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ * See the License for the specific language governing permissions and
16+ * limitations under the License.
17+ *
18+ */
19+ package org .apache .hadoop .ozone .om ;
20+
21+ import java .io .IOException ;
22+ import java .util .ArrayList ;
23+
24+ import org .apache .hadoop .hdds .HddsConfigKeys ;
25+ import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
26+ import org .apache .hadoop .hdds .protocol .StorageType ;
27+ import org .apache .hadoop .hdds .protocol .proto .HddsProtos .ReplicationFactor ;
28+ import org .apache .hadoop .hdds .protocol .proto .HddsProtos .ReplicationType ;
29+ import org .apache .hadoop .hdds .scm .protocol .ScmBlockLocationProtocol ;
30+ import org .apache .hadoop .ozone .om .helpers .OmBucketInfo ;
31+ import org .apache .hadoop .ozone .om .helpers .OmKeyArgs ;
32+ import org .apache .hadoop .ozone .om .helpers .OmKeyArgs .Builder ;
33+ import org .apache .hadoop .ozone .om .helpers .OmMultipartInfo ;
34+ import org .apache .hadoop .ozone .om .helpers .OmMultipartUploadListParts ;
35+ import org .apache .hadoop .ozone .security .OzoneBlockTokenSecretManager ;
36+ import org .apache .hadoop .test .GenericTestUtils ;
37+
38+ import org .junit .Assert ;
39+ import org .junit .Before ;
40+ import org .junit .Test ;
41+ import org .mockito .Mockito ;
42+
43+ /**
44+ * Unit test key manager.
45+ */
46+ public class TestKeyManagerUnit {
47+
48+ private OmMetadataManagerImpl metadataManager ;
49+ private KeyManagerImpl keyManager ;
50+
51+ @ Before
52+ public void setup () throws IOException {
53+ OzoneConfiguration configuration = new OzoneConfiguration ();
54+ configuration .set (HddsConfigKeys .OZONE_METADATA_DIRS ,
55+ GenericTestUtils .getRandomizedTestDir ().toString ());
56+ metadataManager = new OmMetadataManagerImpl (configuration );
57+ keyManager = new KeyManagerImpl (
58+ Mockito .mock (ScmBlockLocationProtocol .class ),
59+ metadataManager ,
60+ configuration ,
61+ "omtest" ,
62+ Mockito .mock (OzoneBlockTokenSecretManager .class )
63+ );
64+ }
65+
66+ @ Test
67+ public void listMultipartUploadPartsWithZeroUpload () throws IOException {
68+ //GIVEN
69+ createBucket (metadataManager , "vol1" , "bucket1" );
70+
71+ OmMultipartInfo omMultipartInfo =
72+ initMultipartUpload (keyManager , "vol1" , "bucket1" , "dir/key1" );
73+
74+ //WHEN
75+ OmMultipartUploadListParts omMultipartUploadListParts = keyManager
76+ .listParts ("vol1" , "bucket1" , "dir/key1" , omMultipartInfo .getUploadID (),
77+ 0 , 10 );
78+
79+ Assert .assertEquals (0 ,
80+ omMultipartUploadListParts .getPartInfoList ().size ());
81+
82+ }
83+
84+ private void createBucket (OmMetadataManagerImpl omMetadataManager ,
85+ String volume , String bucket )
86+ throws IOException {
87+ omMetadataManager .getBucketTable ()
88+ .put (omMetadataManager .getBucketKey (volume , bucket ),
89+ OmBucketInfo .newBuilder ()
90+ .setVolumeName (volume )
91+ .setBucketName (bucket )
92+ .setStorageType (StorageType .DISK )
93+ .setIsVersionEnabled (false )
94+ .setAcls (new ArrayList <>())
95+ .build ());
96+ }
97+
98+ private OmMultipartInfo initMultipartUpload (KeyManagerImpl omtest ,
99+ String volume , String bucket , String key )
100+ throws IOException {
101+ OmKeyArgs key1 = new Builder ()
102+ .setVolumeName (volume )
103+ .setBucketName (bucket )
104+ .setKeyName (key )
105+ .setType (ReplicationType .RATIS )
106+ .setFactor (ReplicationFactor .THREE )
107+ .setAcls (new ArrayList <>())
108+ .build ();
109+ return omtest .initiateMultipartUpload (key1 );
110+ }
111+ }
0 commit comments