@@ -2857,14 +2857,21 @@ public static void listenBucketNotification_test1() throws Exception {
28572857 }
28582858
28592859 long startTime = System .currentTimeMillis ();
2860+ String file = createFile1Mb ();
2861+ String bucketName = getRandomName ();
2862+
28602863 try {
2861- String bucketName = getRandomName ();
28622864 client .makeBucket (bucketName , region );
28632865
28642866 class TestBucketListener implements BucketEventListener {
28652867 int eventsReceived = 0 ;
2868+ Exception lastException = null ;
28662869 NotificationEvent firstEvent = null ;
28672870
2871+ public void updateError (Exception e ) {
2872+ lastException = e ;
2873+ }
2874+
28682875 @ Override
28692876 public void updateEvent (NotificationInfo info ) {
28702877 if (info .records != null && info .records .length > 0 ) {
@@ -2882,36 +2889,58 @@ public void run() {
28822889 try {
28832890 client .listenBucketNotification (bucketName , "prefix" , "suffix" , events , bl );
28842891 } catch (Exception e ) {
2885- System . out . println (e );
2892+ bl . updateError (e );
28862893 }
28872894 }}).start ();
28882895
2889- String file1kb = createFile (1024 );
2890-
28912896 // Upload an object until we detect an event, this is done
28922897 // in a loop because bucket listening is called in a thread
28932898 // and may or may not be executed at this point.
2894- while (bl .eventsReceived < 1 ) {
2895- client .putObject (bucketName , "prefix-random-suffix" , file1kb );
2896- Thread .sleep (300 );
2899+ for (int i = 0 ; i < 20 ; i ++) {
2900+ client .putObject (bucketName , "prefix-random-suffix" , file );
2901+ Thread .sleep (500 );
2902+ if (bl .eventsReceived > 0 || bl .lastException != null ) {
2903+ break ;
2904+ }
2905+ }
2906+
2907+ // Fail for any exception but ignore NotImplemented error
2908+ if (bl .lastException != null ) {
2909+ ErrorResponse errorResponse = null ;
2910+ if (bl .lastException instanceof ErrorResponseException ) {
2911+ ErrorResponseException exp = (ErrorResponseException ) bl .lastException ;
2912+ errorResponse = exp .errorResponse ();
2913+ }
2914+ if (errorResponse != null && errorResponse .errorCode () == ErrorCode .NOT_IMPLEMENTED ) {
2915+ mintIgnoredLog ("listenBucketNotification(String bucketName)" , null , startTime );
2916+ return ;
2917+ } else {
2918+ mintFailedLog ("listenBucketNotification(String bucketName)" , null , startTime ,
2919+ null , bl .lastException .toString () + " >>> " + Arrays .toString (bl .lastException .getStackTrace ()));
2920+ throw bl .lastException ;
2921+ }
28972922 }
28982923
2924+ // No exception at this point, check events result
2925+ if (bl .eventsReceived == 0 ) {
2926+ throw new Exception ("[FAILED] No event notification is received" );
2927+ }
28992928 if (!bl .firstEvent .s3 .bucket .name .equals (bucketName )) {
29002929 throw new Exception ("[FAILED] Bucket name expected: " + bucketName + ", Got: " + bl .firstEvent .s3 .bucket .name );
29012930 }
2902-
29032931 if (!bl .firstEvent .s3 .object .key .equals ("prefix-random-suffix" )) {
2904- throw new Exception ("[FAILED] Bucket name expected: " + file1kb + ", Got: " + bl .firstEvent .s3 .object .key );
2932+ throw new Exception ("[FAILED] Bucket name expected: " + file + ", Got: " + bl .firstEvent .s3 .object .key );
29052933 }
2906-
2907- Files .delete (Paths .get (file1kb ));
2908- client .removeObject (bucketName , "prefix-random-suffix" );
2909- client .removeBucket (bucketName );
29102934 mintSuccessLog ("listenBucketNotification(String bucketName)" , null , startTime );
29112935 } catch (Exception e ) {
29122936 mintFailedLog ("listenBucketNotification(String bucketName)" , null , startTime , null ,
29132937 e .toString () + " >>> " + Arrays .toString (e .getStackTrace ()));
29142938 throw e ;
2939+ } finally {
2940+ // Cleanup
2941+ Files .delete (Paths .get (file ));
2942+ client .removeObject (bucketName , "prefix-random-suffix" );
2943+ client .removeBucket (bucketName );
29152944 }
29162945 }
29172946
@@ -3100,7 +3129,6 @@ public static void main(String[] args) {
31003129 }
31013130 } else {
31023131 FunctionalTest .runTests ();
3103-
31043132 // Get new bucket name to avoid minio azure gateway failure.
31053133 bucketName = getRandomName ();
31063134 // Quick tests with passed region.
0 commit comments