@@ -67,19 +67,6 @@ public void testGetBucketStat() {
6767 Assert .assertTrue (stat .getStorageSize () >= 1024 * 300 );
6868 Assert .assertTrue (stat .getObjectCount () >= 1 );
6969 Assert .assertTrue (stat .getMultipartUploadCount () >= 1 );
70- Assert .assertTrue (stat .getStandardStorage () >= 1024 * 300 );
71- Assert .assertTrue (stat .getStandardObjectCount () >= 1 );
72- Assert .assertTrue (stat .getLiveChannelCount () >= 0 );
73- Assert .assertTrue (stat .getLastModifiedTime () >= 0 );
74- Assert .assertTrue (stat .getInfrequentAccessStorage () >= 0 );
75- Assert .assertTrue (stat .getInfrequentAccessRealStorage () >= 0 );
76- Assert .assertTrue (stat .getInfrequentAccessObjectCount () >= 0 );
77- Assert .assertTrue (stat .getArchiveStorage () >= 0 );
78- Assert .assertTrue (stat .getArchiveRealStorage () >= 0 );
79- Assert .assertTrue (stat .getArchiveObjectCount () >= 0 );
80- Assert .assertTrue (stat .getColdArchiveStorage () >= 0 );
81- Assert .assertTrue (stat .getColdArchiveRealStorage () >= 0 );
82- Assert .assertTrue (stat .getColdArchiveObjectCount () >= 0 );
8370 Assert .assertEquals (stat .getRequestId ().length (), REQUEST_ID_LEN );
8471 } catch (Exception e ) {
8572 e .printStackTrace ();
@@ -109,5 +96,64 @@ public void testUnormalGetBucketStat() {
10996 }
11097
11198 }
112-
99+
100+ @ Test
101+ public void testGetBucketStatForStorageInfo () {
102+ String key = "obj-upload-file-storage-stat.txt" ;
103+ String uploadId = null ;
104+
105+ try {
106+
107+ File file = createSampleFile (key , 1024 * 500 );
108+
109+ // upload a file
110+ UploadFileRequest uploadFileRequest = new UploadFileRequest (bucketName , key );
111+ uploadFileRequest .setUploadFile (file .getAbsolutePath ());
112+ uploadFileRequest .setTaskNum (10 );
113+
114+ UploadFileResult uploadRes = ossClient .uploadFile (uploadFileRequest );
115+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getBucketName (), bucketName );
116+ Assert .assertEquals (uploadRes .getMultipartUploadResult ().getKey (), key );
117+
118+ // init upload
119+ InitiateMultipartUploadRequest initiateMultipartUploadRequest =
120+ new InitiateMultipartUploadRequest (bucketName , key );
121+ InitiateMultipartUploadResult initiateMultipartUploadResult =
122+ ossClient .initiateMultipartUpload (initiateMultipartUploadRequest );
123+ Assert .assertEquals (initiateMultipartUploadResult .getRequestId ().length (), REQUEST_ID_LEN );
124+ uploadId = initiateMultipartUploadResult .getUploadId ();
125+
126+ BucketStat stat = ossClient .getBucketStat (bucketName );
127+ System .out .println (stat .getStorageSize () + "," + stat .getObjectCount () + "," + stat .getMultipartUploadCount ());
128+ Assert .assertTrue (stat .getStorageSize () >= 1024 * 300 );
129+ Assert .assertTrue (stat .getObjectCount () >= 1 );
130+ Assert .assertTrue (stat .getMultipartUploadCount () >= 1 );
131+ Assert .assertTrue (stat .getStandardStorage () >= 1024 * 300 );
132+ Assert .assertTrue (stat .getStandardObjectCount () >= 1 );
133+ Assert .assertTrue (stat .getLiveChannelCount () >= 0 );
134+ Assert .assertTrue (stat .getLastModifiedTime () >= 0 );
135+ Assert .assertTrue (stat .getInfrequentAccessStorage () >= 0 );
136+ Assert .assertTrue (stat .getInfrequentAccessRealStorage () >= 0 );
137+ Assert .assertTrue (stat .getInfrequentAccessObjectCount () >= 0 );
138+ Assert .assertTrue (stat .getArchiveStorage () >= 0 );
139+ Assert .assertTrue (stat .getArchiveRealStorage () >= 0 );
140+ Assert .assertTrue (stat .getArchiveObjectCount () >= 0 );
141+ Assert .assertTrue (stat .getColdArchiveStorage () >= 0 );
142+ Assert .assertTrue (stat .getColdArchiveRealStorage () >= 0 );
143+ Assert .assertTrue (stat .getColdArchiveObjectCount () >= 0 );
144+ Assert .assertEquals (stat .getRequestId ().length (), REQUEST_ID_LEN );
145+ } catch (Exception e ) {
146+ e .printStackTrace ();
147+ Assert .fail (e .getMessage ());
148+ } catch (Throwable e ) {
149+ e .printStackTrace ();
150+ Assert .fail (e .getMessage ());
151+ } finally {
152+ if (uploadId != null ) {
153+ AbortMultipartUploadRequest AbortMultipartUploadRequest =
154+ new AbortMultipartUploadRequest (bucketName , key , uploadId );
155+ ossClient .abortMultipartUpload (AbortMultipartUploadRequest );
156+ }
157+ }
158+ }
113159}
0 commit comments