3636import com .azure .json .JsonProviders ;
3737import com .azure .json .JsonReader ;
3838import com .azure .storage .blob .BlobContainerClient ;
39-
40- import reactor .core .publisher .Mono ;
41-
4239import org .junit .jupiter .api .Assertions ;
43- import org .junit .jupiter .api .Assumptions ;
4440import org .junit .jupiter .api .Test ;
41+ import org .junit .jupiter .api .condition .DisabledIf ;
4542import org .junit .jupiter .api .parallel .Execution ;
4643import org .junit .jupiter .api .parallel .ExecutionMode ;
4744import org .junit .jupiter .api .parallel .Isolated ;
45+ import reactor .core .publisher .Mono ;
4846
4947import java .io .BufferedWriter ;
5048import java .io .File ;
5149import java .io .FileWriter ;
5250import java .io .IOException ;
53- import java .io .StringReader ;
5451import java .nio .charset .StandardCharsets ;
5552import java .time .Duration ;
5653import java .time .OffsetDateTime ;
5754import java .util .ArrayList ;
5855import java .util .List ;
56+ import java .util .Locale ;
5957
6058@ Execution (ExecutionMode .SAME_THREAD )
6159@ Isolated
@@ -76,9 +74,7 @@ protected void beforeTest() {
7674 }
7775 }
7876
79- /*
80- * Test TypeSpec Shared model among GET-PUT Roundtrip operation
81- * */
77+ // Test TypeSpec Shared model among GET-PUT Roundtrip operation
8278 @ SyncAsyncTest
8379 public void testTaskUnifiedModel () {
8480 String testModeSuffix = SyncAsyncExtension .execute (() -> "sync" , () -> Mono .just ("async" ));
@@ -429,16 +425,15 @@ public void testAddMultiTasksWithError() {
429425
430426 Assertions .assertTrue (true , "Should not here" );
431427 } catch (RuntimeException ex ) {
432- System .out .printf ("Expect exception %s" , ex . toString () );
428+ System .out .printf ("Expect exception %s" , ex );
433429 }
434430 }
435431
432+ // This test will temporarily only run in Live/Record mode. It runs fine in Playback mode too on Mac and Windows machines.
433+ // Linux machines are causing issues. This issue is under investigation.
434+ @ DisabledIf (value = "skipInPlayback" )
436435 @ Test
437- public void failIfPoisonTaskTooLargeSync () throws Exception {
438- //This test will temporarily only run in Live/Record mode. It runs fine in Playback mode too on Mac and Windows machines.
439- // Linux machines are causing issues. This issue is under investigation.
440- Assumptions .assumeFalse (getTestMode () == TestMode .PLAYBACK , "This Test only runs in Live/Record mode" );
441-
436+ public void failIfPoisonTaskTooLargeSync () {
442437 String jobId = getStringIdWithUserNamePrefix ("-failIfPoisonTaskTooLarge-sync" );
443438 String taskId = "mytask-sync" ;
444439
@@ -447,9 +442,9 @@ public void failIfPoisonTaskTooLargeSync() throws Exception {
447442 BatchJobCreateParameters parameters = new BatchJobCreateParameters (jobId , poolInfo );
448443 batchClient .createJob (parameters );
449444
450- List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <BatchTaskCreateParameters >();
445+ List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <>();
451446 BatchTaskCreateParameters taskToAdd = new BatchTaskCreateParameters (taskId , "sleep 1" );
452- List <ResourceFile > resourceFiles = new ArrayList <ResourceFile >();
447+ List <ResourceFile > resourceFiles = new ArrayList <>();
453448 ResourceFile resourceFile ;
454449
455450 // If this test fails try increasing the size of the Task in case maximum size increase
@@ -501,12 +496,11 @@ public void failIfPoisonTaskTooLargeSync() throws Exception {
501496 }
502497 }
503498
499+ // This test will temporarily only run in Live/Record mode. It runs fine in Playback mode too on Mac and Windows machines.
500+ // Linux machines are causing issues. This issue is under investigation.
501+ @ DisabledIf (value = "skipInPlayback" )
504502 @ Test
505- public void failIfPoisonTaskTooLargeAsync () throws Exception {
506- //This test will temporarily only run in Live/Record mode. It runs fine in Playback mode too on Mac and Windows machines.
507- // Linux machines are causing issues. This issue is under investigation.
508- Assumptions .assumeFalse (getTestMode () == TestMode .PLAYBACK , "This Test only runs in Live/Record mode" );
509-
503+ public void failIfPoisonTaskTooLargeAsync () {
510504 String jobId = getStringIdWithUserNamePrefix ("-failIfPoisonTaskTooLarge-async" );
511505 String taskId = "mytask-async" ;
512506
@@ -515,9 +509,9 @@ public void failIfPoisonTaskTooLargeAsync() throws Exception {
515509 BatchJobCreateParameters parameters = new BatchJobCreateParameters (jobId , poolInfo );
516510 batchAsyncClient .createJob (parameters ).block ();
517511
518- List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <BatchTaskCreateParameters >();
512+ List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <>();
519513 BatchTaskCreateParameters taskToAdd = new BatchTaskCreateParameters (taskId , "sleep 1" );
520- List <ResourceFile > resourceFiles = new ArrayList <ResourceFile >();
514+ List <ResourceFile > resourceFiles = new ArrayList <>();
521515 ResourceFile resourceFile ;
522516
523517 // If this test fails try increasing the size of the Task in case maximum size increase
@@ -560,13 +554,12 @@ public void failIfPoisonTaskTooLargeAsync() throws Exception {
560554 }
561555 }
562556
557+ // This test does not run in Playback mode. It only runs in Record/Live mode.
558+ // This test uses multi threading. Playing back the test doesn't match its recorded sequence always.
559+ // Hence Playback of this test is disabled.
560+ @ DisabledIf (value = "skipInPlayback" )
563561 @ Test
564562 public void succeedWithRetrySync () {
565- //This test does not run in Playback mode. It only runs in Record/Live mode.
566- // This test uses multi threading. Playing back the test doesn't match its recorded sequence always.
567- // Hence Playback of this test is disabled.
568- Assumptions .assumeFalse (getTestMode () == TestMode .PLAYBACK , "This Test only runs in Live/Record mode" );
569-
570563 String jobId = getStringIdWithUserNamePrefix ("-succeedWithRetry-sync" );
571564 String taskId = "mytask-sync" ;
572565
@@ -575,9 +568,9 @@ public void succeedWithRetrySync() {
575568 BatchJobCreateParameters jobToCreate = new BatchJobCreateParameters (jobId , poolInfo );
576569 batchClient .createJob (jobToCreate );
577570
578- List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <BatchTaskCreateParameters >();
571+ List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <>();
579572 BatchTaskCreateParameters taskToAdd ;
580- List <ResourceFile > resourceFiles = new ArrayList <ResourceFile >();
573+ List <ResourceFile > resourceFiles = new ArrayList <>();
581574 ResourceFile resourceFile ;
582575
583576 BatchTaskBulkCreateOptions option = new BatchTaskBulkCreateOptions ();
@@ -612,13 +605,12 @@ public void succeedWithRetrySync() {
612605 }
613606 }
614607
608+ // This test does not run in Playback mode. It only runs in Record/Live mode.
609+ // This test uses multi threading. Playing back the test doesn't match its recorded sequence always.
610+ // Hence Playback of this test is disabled.
611+ @ DisabledIf (value = "skipInPlayback" )
615612 @ Test
616613 public void succeedWithRetryAsync () {
617- //This test does not run in Playback mode. It only runs in Record/Live mode.
618- // This test uses multi threading. Playing back the test doesn't match its recorded sequence always.
619- // Hence Playback of this test is disabled.
620- Assumptions .assumeFalse (getTestMode () == TestMode .PLAYBACK , "This Test only runs in Live/Record mode" );
621-
622614 String jobId = getStringIdWithUserNamePrefix ("-succeedWithRetry-async" );
623615 String taskId = "mytask-async" ;
624616
@@ -627,9 +619,9 @@ public void succeedWithRetryAsync() {
627619 BatchJobCreateParameters jobToCreate = new BatchJobCreateParameters (jobId , poolInfo );
628620 batchAsyncClient .createJob (jobToCreate ).block ();
629621
630- List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <BatchTaskCreateParameters >();
622+ List <BatchTaskCreateParameters > tasksToAdd = new ArrayList <>();
631623 BatchTaskCreateParameters taskToAdd ;
632- List <ResourceFile > resourceFiles = new ArrayList <ResourceFile >();
624+ List <ResourceFile > resourceFiles = new ArrayList <>();
633625 ResourceFile resourceFile ;
634626
635627 BatchTaskBulkCreateOptions option = new BatchTaskBulkCreateOptions ();
@@ -879,16 +871,15 @@ public void testCreateTasks() {
879871 }
880872
881873 @ Test
882- public void testDeserializationOfBatchTaskStatistics () {
874+ public void testDeserializationOfBatchTaskStatistics () throws IOException {
883875 // Simulated JSON response with numbers as strings
884- String jsonResponse = "{" + "\" url\" :\" http://example.com/statistics\" ,"
885- + "\" startTime\" :\" 2022-01-01T00:00:00Z\" ," + "\" lastUpdateTime\" :\" 2022-01-01T01:00:00Z\" ,"
886- + "\" userCPUTime\" :\" PT1H\" ," + "\" kernelCPUTime\" :\" PT2H\" ," + "\" wallClockTime\" :\" PT3H\" ,"
887- + "\" readIOps\" :\" 1000\" ," + "\" writeIOps\" :\" 500\" ," + "\" readIOGiB\" :0.5," + "\" writeIOGiB\" :0.25,"
888- + "\" waitTime\" :\" PT30M\" " + "}" ;
876+ String jsonResponse = "{\" url\" :\" http://example.com/statistics\" ,\" startTime\" :\" 2022-01-01T00:00:00Z\" ,"
877+ + "\" lastUpdateTime\" :\" 2022-01-01T01:00:00Z\" ,\" userCPUTime\" :\" PT1H\" ,\" kernelCPUTime\" :\" PT2H\" ,"
878+ + "\" wallClockTime\" :\" PT3H\" ,\" readIOps\" :\" 1000\" ,\" writeIOps\" :\" 500\" ,\" readIOGiB\" :0.5,"
879+ + "\" writeIOGiB\" :0.25,\" waitTime\" :\" PT30M\" }" ;
889880
890881 // Deserialize JSON response using JsonReader from JsonProviders
891- try (JsonReader jsonReader = JsonProviders .createReader (new StringReader ( jsonResponse ) )) {
882+ try (JsonReader jsonReader = JsonProviders .createReader (jsonResponse )) {
892883 BatchTaskStatistics stats = BatchTaskStatistics .fromJson (jsonReader );
893884
894885 // Assertions
@@ -904,8 +895,20 @@ public void testDeserializationOfBatchTaskStatistics() {
904895 Assertions .assertEquals (0.5 , stats .getReadIoGiB ());
905896 Assertions .assertEquals (0.25 , stats .getWriteIoGiB ());
906897 Assertions .assertEquals (Duration .parse ("PT30M" ), stats .getWaitTime ());
907- } catch (IOException e ) {
908- throw new RuntimeException (e );
909898 }
910899 }
900+
901+ private static boolean skipInPlayback () {
902+ final String azureTestMode = Configuration .getGlobalConfiguration ().get ("AZURE_TEST_MODE" );
903+
904+ if (azureTestMode != null ) {
905+ try {
906+ return TestMode .valueOf (azureTestMode .toUpperCase (Locale .US )) == TestMode .PLAYBACK ;
907+ } catch (IllegalArgumentException e ) {
908+ return true ; // TestMode unknown, default is PLAYBACK.
909+ }
910+ }
911+
912+ return true ; // TestMode unknown, default is PLAYBACK.
913+ }
911914}
0 commit comments