@@ -408,7 +408,7 @@ public void testBatchBlobDelete() throws Exception {
408408
409409 // execute batch
410410
411- Iterable < Map . Entry <CloudBlob , Void > > responses = container .getServiceClient ().executeBatch (batchDeleteOp );
411+ Map <CloudBlob , Void > responses = container .getServiceClient ().executeBatch (batchDeleteOp );
412412
413413 // validate
414414
@@ -417,8 +417,8 @@ public void testBatchBlobDelete() throws Exception {
417417 }
418418
419419 int numResponses = 0 ;
420- for (Map .Entry <CloudBlob , Void > response : responses ) {
421- assertEquals (blobs .get ( numResponses ), response .getKey ());
420+ for (Map .Entry <CloudBlob , Void > response : responses . entrySet () ) {
421+ assertTrue (blobs .contains ( response .getKey () ));
422422 assertNull (response .getValue ()); // CloudBlob::delete() returns Void (null), so all batch responses should be null
423423 numResponses ++;
424424 }
@@ -438,7 +438,7 @@ public void testBatchBlobDeleteNoRequests() throws Exception {
438438
439439 // execute batch
440440
441- Iterable < Map . Entry <CloudBlob , Void > > responses = container .getServiceClient ().executeBatch (batchDeleteOp ); //throws
441+ Map <CloudBlob , Void > responses = container .getServiceClient ().executeBatch (batchDeleteOp ); //throws
442442 }
443443
444444 @ Test
@@ -458,7 +458,6 @@ public void testBatchBlobDeleteMixedRequests() throws Exception {
458458 for (int i = 0 ; i < BLOBS ; i ++) {
459459 CloudBlockBlob blob = container .getBlockBlobReference ("testblob_" + UUID .randomUUID ());
460460
461- // bad requests first; displays that good responses come first regardless of order of request
462461 if (i >= BAD_REQUESTS ) {
463462 blob .uploadText ("content" );
464463 }
@@ -469,33 +468,20 @@ public void testBatchBlobDeleteMixedRequests() throws Exception {
469468
470469 // execute batch
471470
472- Iterable <Map .Entry <CloudBlob , Void >> responses = container .getServiceClient ().executeBatch (batchDeleteOp );
473-
474- // validate
475-
476- // good deletes are successful
477- for (CloudBlob blob : blobs ) {
478- assertFalse (blob .exists ());
479- }
480-
481- // manually iterate to show we get every result we expect
482- Iterator <Map .Entry <CloudBlob , Void >> it = responses .iterator ();
483- for (int i = 0 ; i < BLOBS - BAD_REQUESTS ; i ++) {
484- assertTrue (it .hasNext ());
485- assertTrue (blobs .contains (it .next ().getKey ()));
486- }
487-
471+ Map <CloudBlob , Void > responses ;
488472 boolean threw = true ;
489473 try {
490- it . hasNext (); // throws
474+ responses = container . getServiceClient (). executeBatch ( batchDeleteOp );
491475 threw = false ;
492476 }
477+
478+ // validate
479+
493480 catch (BatchException e ) {
494- assertEquals (BAD_REQUESTS , e .size ());
495- for (Map .Entry <StorageException , Object > entry : e .entrySet ()) {
496- assertNotNull (entry .getKey ());
497- // unnecessary cast for Collection::contains(), but shows the value must usually be casted
498- assertTrue (blobs .contains ((CloudBlob )entry .getValue ()));
481+ // good deletes are successful
482+ for (CloudBlob blob : blobs ) {
483+ assertFalse (blob .exists ());
484+ assertTrue (e .getSuccessfulResponses ().keySet ().contains (blob ) || e .getExceptions ().keySet ().contains (blob ));
499485 }
500486 }
501487 finally {
@@ -525,7 +511,7 @@ public void testBatchBlobSetTier() throws Exception {
525511
526512 // execute batch
527513
528- Iterable < Map . Entry <CloudBlob , Void > > responses = container .getServiceClient ().executeBatch (batchTierOp );
514+ Map <CloudBlob , Void > responses = container .getServiceClient ().executeBatch (batchTierOp );
529515
530516 // validate
531517
@@ -535,8 +521,8 @@ public void testBatchBlobSetTier() throws Exception {
535521 }
536522
537523 int numResponses = 0 ;
538- for (Map .Entry <CloudBlob , Void > response : responses ) {
539- assertEquals (blobs .get ( numResponses ), response .getKey ());
524+ for (Map .Entry <CloudBlob , Void > response : responses . entrySet () ) {
525+ assertTrue (blobs .contains ( response .getKey () ));
540526 assertNull (response .getValue ()); // CloudBlob::setTier() returns Void (null), so all batch responses should be null
541527 numResponses ++;
542528 }
@@ -556,7 +542,7 @@ public void testBatchBlobSetTierNoRequests() throws Exception {
556542
557543 // execute batch
558544
559- Iterable < Map . Entry <CloudBlob , Void > > responses = container .getServiceClient ().executeBatch (batchDeleteOp ); //throws
545+ Map <CloudBlob , Void > responses = container .getServiceClient ().executeBatch (batchDeleteOp ); //throws
560546 }
561547
562548 @ Test
@@ -571,7 +557,7 @@ public void testBatchBlobSetTierMixedRequests() throws Exception {
571557 container .createIfNotExists ();
572558
573559 List <CloudBlob > blobs = new ArrayList <>();
574- BlobSetTierBatchOperation batchDeleteOp = new BlobSetTierBatchOperation ();
560+ BlobSetTierBatchOperation batchSetTierOp = new BlobSetTierBatchOperation ();
575561
576562 for (int i = 0 ; i < BLOBS ; i ++) {
577563 CloudBlockBlob blob = container .getBlockBlobReference ("testblob_" + UUID .randomUUID ());
@@ -582,41 +568,28 @@ public void testBatchBlobSetTierMixedRequests() throws Exception {
582568 }
583569
584570 blobs .add (blob );
585- batchDeleteOp .addSubOperation (blob , StandardBlobTier .HOT );
571+ batchSetTierOp .addSubOperation (blob , StandardBlobTier .HOT );
586572 }
587573
588574 // execute batch
589575
590- Iterable <Map .Entry <CloudBlob , Void >> responses = container .getServiceClient ().executeBatch (batchDeleteOp );
591-
592- // validate
593-
594- // good deletes are successful
595- for (CloudBlob blob : blobs ) {
596- if (blob .exists ()) {
597- blob .downloadAttributes ();
598- assertEquals (StandardBlobTier .HOT , blob .getProperties ().getStandardBlobTier ());
599- }
600- }
601-
602- // manually iterate to show we get every result we expect
603- Iterator <Map .Entry <CloudBlob , Void >> it = responses .iterator ();
604- for (int i = 0 ; i < BLOBS - BAD_REQUESTS ; i ++) {
605- assertTrue (it .hasNext ());
606- assertTrue (blobs .contains (it .next ().getKey ()));
607- }
608-
576+ Map <CloudBlob , Void > responses ;
609577 boolean threw = true ;
610578 try {
611- it . hasNext (); // throws
579+ responses = container . getServiceClient (). executeBatch ( batchSetTierOp );
612580 threw = false ;
613581 }
582+
583+ // validate
584+
614585 catch (BatchException e ) {
615- assertEquals (BAD_REQUESTS , e .size ());
616- for (Map .Entry <StorageException , Object > entry : e .entrySet ()) {
617- assertNotNull (entry .getKey ());
618- // unnecessary cast for Collection::contains(), but shows the value must usually be casted
619- assertTrue (blobs .contains ((CloudBlob )entry .getValue ()));
586+ // good deletes are successful
587+ for (CloudBlob blob : blobs ) {
588+ if (blob .exists ()) {
589+ blob .downloadAttributes ();
590+ assertEquals (StandardBlobTier .HOT , blob .getProperties ().getStandardBlobTier ());
591+ }
592+ assertTrue (e .getSuccessfulResponses ().keySet ().contains (blob ) || e .getExceptions ().keySet ().contains (blob ));
620593 }
621594 }
622595 finally {
0 commit comments