@@ -165,10 +165,15 @@ public void shouldBeAbleToAddANodeAndCreateASession() throws URISyntaxException
165
165
MutableCapabilities sessionCaps = new MutableCapabilities (caps );
166
166
sessionCaps .setCapability ("sausages" , "gravy" );
167
167
try (NewSessionPayload payload = NewSessionPayload .create (sessionCaps )) {
168
- Session session = distributor .newSession (createRequest (payload )).right ().getSession ();
169
-
170
- assertThat (session .getCapabilities ()).isEqualTo (sessionCaps );
171
- assertThat (session .getUri ()).isEqualTo (routableUri );
168
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
169
+ distributor .newSession (createRequest (payload ));
170
+ if (result .isRight ()) {
171
+ Session session = result .right ().getSession ();
172
+ assertThat (session .getCapabilities ()).isEqualTo (sessionCaps );
173
+ assertThat (session .getUri ()).isEqualTo (routableUri );
174
+ } else {
175
+ fail ("Session creation failed" , result .left ());
176
+ }
172
177
}
173
178
}
174
179
@@ -201,11 +206,17 @@ public void creatingASessionAddsItToTheSessionMap() throws URISyntaxException {
201
206
MutableCapabilities sessionCaps = new MutableCapabilities (caps );
202
207
sessionCaps .setCapability ("sausages" , "gravy" );
203
208
try (NewSessionPayload payload = NewSessionPayload .create (sessionCaps )) {
204
- Session returned = distributor .newSession (createRequest (payload )).right ().getSession ();
209
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
210
+ distributor .newSession (createRequest (payload ));
205
211
206
- Session session = sessions .get (returned .getId ());
207
- assertThat (session .getCapabilities ()).isEqualTo (sessionCaps );
208
- assertThat (session .getUri ()).isEqualTo (routableUri );
212
+ if (result .isRight ()) {
213
+ Session returned = result .right ().getSession ();
214
+ Session session = sessions .get (returned .getId ());
215
+ assertThat (session .getCapabilities ()).isEqualTo (sessionCaps );
216
+ assertThat (session .getUri ()).isEqualTo (routableUri );
217
+ } else {
218
+ fail ("Session creation failed" , result .left ());
219
+ }
209
220
}
210
221
}
211
222
@@ -520,9 +531,15 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
520
531
wait .until (obj -> distributor .getStatus ().hasCapacity ());
521
532
522
533
try (NewSessionPayload payload = NewSessionPayload .create (caps )) {
523
- Session session = distributor .newSession (createRequest (payload )).right ().getSession ();
534
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
535
+ distributor .newSession (createRequest (payload ));
524
536
525
- assertThat (session .getUri ()).isEqualTo (lightest .getStatus ().getUri ());
537
+ if (result .isRight ()) {
538
+ Session session = result .right ().getSession ();
539
+ assertThat (session .getUri ()).isEqualTo (lightest .getStatus ().getUri ());
540
+ } else {
541
+ fail ("Session creation failed" , result .left ());
542
+ }
526
543
}
527
544
}
528
545
@@ -559,20 +576,32 @@ public void shouldUseLastSessionCreatedTimeAsTieBreaker() {
559
576
handler .addHandler (middle );
560
577
distributor .add (middle );
561
578
try (NewSessionPayload payload = NewSessionPayload .create (caps )) {
562
- Session session = distributor .newSession (createRequest (payload )).right ().getSession ();
579
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
580
+ distributor .newSession (createRequest (payload ));
563
581
564
- // Least lightly loaded is middle
565
- assertThat (session .getUri ()).isEqualTo (middle .getStatus ().getUri ());
582
+ if (result .isRight ()) {
583
+ Session session = result .right ().getSession ();
584
+ // Least lightly loaded is middle
585
+ assertThat (session .getUri ()).isEqualTo (middle .getStatus ().getUri ());
586
+ } else {
587
+ fail ("Session creation failed" , result .left ());
588
+ }
566
589
}
567
590
568
591
Node mostRecent = createNode (caps , 5 , 0 );
569
592
handler .addHandler (mostRecent );
570
593
distributor .add (mostRecent );
571
594
try (NewSessionPayload payload = NewSessionPayload .create (caps )) {
572
- Session session = distributor .newSession (createRequest (payload )).right ().getSession ();
595
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
596
+ distributor .newSession (createRequest (payload ));
597
+ if (result .isRight ()) {
598
+ Session session = result .right ().getSession ();
573
599
574
- // Least lightly loaded is most recent
575
- assertThat (session .getUri ()).isEqualTo (mostRecent .getStatus ().getUri ());
600
+ // Least lightly loaded is most recent
601
+ assertThat (session .getUri ()).isEqualTo (mostRecent .getStatus ().getUri ());
602
+ } else {
603
+ fail ("Session creation failed" , result .left ());
604
+ }
576
605
}
577
606
578
607
// All the nodes should be equally loaded.
@@ -582,9 +611,15 @@ public void shouldUseLastSessionCreatedTimeAsTieBreaker() {
582
611
583
612
// All nodes are now equally loaded. We should be going in time order now
584
613
try (NewSessionPayload payload = NewSessionPayload .create (caps )) {
585
- Session session = distributor .newSession (createRequest (payload )).right ().getSession ();
614
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
615
+ distributor .newSession (createRequest (payload ));
616
+ if (result .isRight ()) {
617
+ Session session = result .right ().getSession ();
586
618
587
- assertThat (session .getUri ()).isEqualTo (leastRecent .getStatus ().getUri ());
619
+ assertThat (session .getUri ()).isEqualTo (leastRecent .getStatus ().getUri ());
620
+ } else {
621
+ fail ("Session creation failed" , result .left ());
622
+ }
588
623
}
589
624
}
590
625
@@ -723,22 +758,27 @@ public void shouldReleaseSlotOnceSessionEnds() throws URISyntaxException {
723
758
// Use up the one slot available
724
759
Session session ;
725
760
try (NewSessionPayload payload = NewSessionPayload .create (caps )) {
726
- session = distributor .newSession (createRequest (payload )).right ().getSession ();
727
- }
728
-
729
- // Make sure the session map has the session
730
- sessions .get (session .getId ());
731
-
732
- node .stop (session .getId ());
733
- // Now wait for the session map to say the session is gone.
734
- wait .until (obj -> {
735
- try {
761
+ Either <SessionNotCreatedException , CreateSessionResponse > result =
762
+ distributor .newSession (createRequest (payload ));
763
+ if (result .isRight ()) {
764
+ session = result .right ().getSession ();
765
+ // Make sure the session map has the session
736
766
sessions .get (session .getId ());
737
- return false ;
738
- } catch (NoSuchSessionException e ) {
739
- return true ;
767
+
768
+ node .stop (session .getId ());
769
+ // Now wait for the session map to say the session is gone.
770
+ wait .until (obj -> {
771
+ try {
772
+ sessions .get (session .getId ());
773
+ return false ;
774
+ } catch (NoSuchSessionException e ) {
775
+ return true ;
776
+ }
777
+ });
778
+ } else {
779
+ fail ("Session creation failed" , result .left ());
740
780
}
741
- });
781
+ }
742
782
743
783
wait .until (obj -> distributor .getStatus ().hasCapacity ());
744
784
@@ -940,30 +980,50 @@ public void shouldPrioritizeHostsWithTheMostSlotsAvailableForASessionType() {
940
980
try (NewSessionPayload chromePayload = NewSessionPayload .create (chromeCapabilities );
941
981
NewSessionPayload firefoxPayload = NewSessionPayload .create (firefoxCapabilities )) {
942
982
943
- Session chromeSession = distributor .newSession (createRequest (chromePayload )).right ().getSession ();
944
-
945
- assertThat ( //Ensure the Uri of the Session matches one of the Chrome Nodes, not the Edge Node
946
- chromeSession .getUri ()).isIn (
947
- chromeNodes
948
- .stream ().map (Node ::getStatus ).collect (Collectors .toList ()) //List of getStatus() from the Set
949
- .stream ().map (NodeStatus ::getUri ).collect (Collectors .toList ()) //List of getUri() from the Set
950
- );
951
-
952
- Session firefoxSession = distributor .newSession (createRequest (firefoxPayload )).right ().getSession ();
953
- LOG .info (String .format ("Firefox Session %d assigned to %s" , i , chromeSession .getUri ()));
954
-
955
- boolean inFirefoxNodes = firefoxNodes .stream ().anyMatch (node -> node .getUri ().equals (firefoxSession .getUri ()));
956
- boolean inChromeNodes = chromeNodes .stream ().anyMatch (node -> node .getUri ().equals (chromeSession .getUri ()));
957
- //This could be either, or, or both
958
- assertTrue (inFirefoxNodes || inChromeNodes );
983
+ Either <SessionNotCreatedException , CreateSessionResponse > chromeResult =
984
+ distributor .newSession (createRequest (chromePayload ));
985
+
986
+ if (chromeResult .isRight ()) {
987
+ Session chromeSession = chromeResult .right ().getSession ();
988
+
989
+ assertThat ( //Ensure the Uri of the Session matches one of the Chrome Nodes, not the Edge Node
990
+ chromeSession .getUri ()).isIn (
991
+ chromeNodes
992
+ .stream ().map (Node ::getStatus ).collect (Collectors .toList ()) //List of getStatus() from the Set
993
+ .stream ().map (NodeStatus ::getUri ).collect (Collectors .toList ()) //List of getUri() from the Set
994
+ );
995
+
996
+ Either <SessionNotCreatedException , CreateSessionResponse > firefoxResult =
997
+ distributor .newSession (createRequest (firefoxPayload ));
998
+
999
+ if (firefoxResult .isRight ()) {
1000
+ Session firefoxSession = firefoxResult .right ().getSession ();
1001
+ LOG .info (String .format ("Firefox Session %d assigned to %s" , i , chromeSession .getUri ()));
1002
+
1003
+ boolean inFirefoxNodes = firefoxNodes .stream ().anyMatch (node -> node .getUri ().equals (firefoxSession .getUri ()));
1004
+ boolean inChromeNodes = chromeNodes .stream ().anyMatch (node -> node .getUri ().equals (chromeSession .getUri ()));
1005
+ //This could be either, or, or both
1006
+ assertTrue (inFirefoxNodes || inChromeNodes );
1007
+ } else {
1008
+ fail ("Session creation failed" , firefoxResult .left ());
1009
+ }
1010
+ } else {
1011
+ fail ("Session creation failed" , chromeResult .left ());
1012
+ }
959
1013
}
960
1014
}
961
1015
962
1016
//The Chrome Nodes should be full at this point, but Firefox isn't... so send an Edge session and make sure it routes to an Edge node
963
1017
try (NewSessionPayload edgePayload = NewSessionPayload .create (edgeCapabilities )) {
964
- Session edgeSession = distributor .newSession (createRequest (edgePayload )).right ().getSession ();
965
-
966
- assertTrue (edgeNodes .stream ().anyMatch (node -> node .getUri ().equals (edgeSession .getUri ())));
1018
+ Either <SessionNotCreatedException , CreateSessionResponse > edgeResult =
1019
+ distributor .newSession (createRequest (edgePayload ));
1020
+ if (edgeResult .isRight ()) {
1021
+ Session edgeSession = edgeResult .right ().getSession ();
1022
+
1023
+ assertTrue (edgeNodes .stream ().anyMatch (node -> node .getUri ().equals (edgeSession .getUri ())));
1024
+ } else {
1025
+ fail ("Session creation failed" , edgeResult .left ());
1026
+ }
967
1027
}
968
1028
}
969
1029
0 commit comments