OLD | NEW |
1 /* | 1 /* |
2 Copyright 2011 Google Inc | 2 Copyright 2011 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 Assert.That(handler.Calls, Is.EqualTo(1)); | 531 Assert.That(handler.Calls, Is.EqualTo(1)); |
532 // the returned response should contain ETag, check that the ser
vice add the right ETag property on· | 532 // the returned response should contain ETag, check that the ser
vice add the right ETag property on· |
533 // the response | 533 // the response |
534 handler.ResponseObject.ETag = handler.ResponseETag; | 534 handler.ResponseObject.ETag = handler.ResponseETag; |
535 Assert.That(response, Is.EqualTo(handler.ResponseObject)); | 535 Assert.That(response, Is.EqualTo(handler.ResponseObject)); |
536 } | 536 } |
537 } | 537 } |
538 | 538 |
539 /// <summary>· | 539 /// <summary>· |
540 /// A subtest for testing execute when an exception is thrown during sen
ding the request, with or without· | 540 /// A subtest for testing execute when an exception is thrown during sen
ding the request, with or without· |
541 /// back-off. If back-off handler is attached to the service's message h
andler, there are going to be several· | 541 /// back-off. If back-off handler is attached to the service's message h
andler, there are going to be 3 tries· |
542 /// retries (up to 2 minutes). | 542 /// (3 is the default value of <seealso cref="ConfigurableMessageHandler
.NumTries" />) before the operation· |
| 543 /// fails. |
543 /// </summary> | 544 /// </summary> |
544 /// <param name="backOff">Indicates if back-off handler is attached to t
he service.</param> | 545 /// <param name="backOff">Indicates if back-off handler is attached to t
he service.</param> |
545 private void SubtestExecute_ThrowException(bool backOff) | 546 private void SubtestExecute_ThrowException(bool backOff) |
546 { | 547 { |
547 var handler = new MockMessageHandler(true); | 548 var handler = new MockMessageHandler(true); |
548 var initializer = new BaseClientService.Initializer() | 549 var initializer = new BaseClientService.Initializer() |
549 { | 550 { |
550 HttpClientFactory = new MockHttpClientFactory(handler) | 551 HttpClientFactory = new MockHttpClientFactory(handler) |
551 }; | 552 }; |
552 | 553 |
553 // by default back-off is used, so disable it in case backOff is fal
se | 554 // sets the default exponential back-off policy by the input |
554 if (!backOff) | 555 initializer.DefaultExponentialBackOffPolicy = backOff ? |
555 { | 556 BaseClientService.ExponentialBackOffPolicy.Exception : |
556 initializer.DefaultExponentialBackOffPolicy = BaseClientService.
ExponentialBackOffPolicy.None; | 557 BaseClientService.ExponentialBackOffPolicy.None; |
557 } | |
558 | 558 |
559 using (var service = new MockClientService(initializer)) | 559 using (var service = new MockClientService(initializer)) |
560 { | 560 { |
561 var request = new TestClientServiceRequest(service, "GET", null)
; | 561 var request = new TestClientServiceRequest(service, "GET", null)
; |
562 Assert.Throws<InvalidOperationMockException>(() => request.Execu
te()); | 562 Assert.Throws<InvalidOperationMockException>(() => request.Execu
te()); |
563 | 563 |
564 // if back-off is enabled, we use 2 minutes maximum wait time fo
r a request, so we should make lg(120) | 564 int calls = backOff ? service.HttpClient.MessageHandler.NumTries
: 1; |
565 // 1 calls | |
566 int calls = backOff ? (int)Math.Ceiling(Math.Log(120, 2) 1) :
1; | |
567 Assert.That(handler.Calls, Is.EqualTo(calls)); | 565 Assert.That(handler.Calls, Is.EqualTo(calls)); |
568 } | 566 } |
569 } | 567 } |
570 | 568 |
571 /// <summary>· | 569 /// <summary>· |
572 /// Tests execute when an exception is thrown during a request and expon
ential back-off is enabled. | 570 /// Tests execute when an exception is thrown during a request and expon
ential back-off is enabled. |
573 /// </summary> | 571 /// </summary> |
574 [Test] | 572 [Test] |
575 public void Execute_ThrowException_WithBackOff() | 573 public void Execute_ThrowException_WithBackOff() |
576 { | 574 { |
577 SubtestExecute_ThrowException(true); | 575 SubtestExecute_ThrowException(true); |
578 } | 576 } |
579 | 577 |
580 /// <summary>· | 578 /// <summary>· |
581 /// Tests execute when an exception is thrown during a request and expon
ential back-off is disabled. | 579 /// Tests execute when an exception is thrown during a request and expon
ential back-off is disabled. |
582 /// </summary> | 580 /// </summary> |
583 [Test] | 581 [Test] |
584 public void Execute_ThrowException_WithoutBackOff() | 582 public void Execute_ThrowException_WithoutBackOff() |
585 { | 583 { |
586 SubtestExecute_ThrowException(false); | 584 SubtestExecute_ThrowException(false); |
587 } | 585 } |
588 | 586 |
589 /// <summary>· | 587 /// <summary>· |
590 /// A subtest for testing async execute when an exception is thrown duri
ng sending the request, with or without· | 588 /// A subtest for testing async execute when an exception is thrown duri
ng sending the request, with or without· |
591 /// back-off handler. If back-off handler is attached to the service's m
essage handler, there are going to be· | 589 /// back-off handler. If back-off handler is attached to the service's m
essage handler, there are going to be 3 |
592 /// several retries (up to 2 minutes). | 590 /// tries (3 is the default value of <seealso cref="ConfigurableMessageH
andler.NumTries" />) before the· |
| 591 /// operation fails. |
593 /// </summary> | 592 /// </summary> |
863 /// <param name="backOff">Indicates if back-off handler is attached to t
he service.</param> | 593 /// <param name="backOff">Indicates if back-off handler is attached to t
he service.</param> |
595 private void SubtestExecuteAsync_ThrowException(bool backOff) | 863 private void SubtestExecuteAsync_ThrowException(bool backOff) |
596 { | 595 { |
597 var handler = new MockMessageHandler(true); | 596 var handler = new MockMessageHandler(true); |
598 var initializer = new BaseClientService.Initializer() | 597 var initializer = new BaseClientService.Initializer() |
599 { | 598 { |
600 HttpClientFactory = new MockHttpClientFactory(handler) | 599 HttpClientFactory = new MockHttpClientFactory(handler) |
601 }; | 600 }; |
602 | 601 |
603 // by default back-off is used, so disable it in case backOff is fal
se | 602 // configure the back-off behavior by the input |
604 if (!backOff) | 603 initializer.DefaultExponentialBackOffPolicy = backOff ? |
605 { | 604 BaseClientService.ExponentialBackOffPolicy.Exception : |
606 initializer.DefaultExponentialBackOffPolicy = BaseClientService.
ExponentialBackOffPolicy.None; | 605 BaseClientService.ExponentialBackOffPolicy.None; |
607 } | |
608 | 606 |
609 using (var service = new MockClientService(initializer)) | 607 using (var service = new MockClientService(initializer)) |
610 { | 608 { |
611 var request = new TestClientServiceRequest(service, "GET", null)
; | 609 var request = new TestClientServiceRequest(service, "GET", null)
; |
612 var task = request.ExecuteAsync(); | 610 var task = request.ExecuteAsync(); |
613 try | 611 try |
614 { | 612 { |
615 var result = task.Result; | 613 var result = task.Result; |
616 Assert.Fail("Exception should be thrown"); | 614 Assert.Fail("Exception should be thrown"); |
617 } | 615 } |
618 catch (AggregateException ex) | 616 catch (AggregateException ex) |
619 { | 617 { |
620 Assert.That(ex.InnerException, Is.AssignableFrom(typeof(Inva
lidOperationMockException))); | 618 Assert.That(ex.InnerException, Is.AssignableFrom(typeof(Inva
lidOperationMockException))); |
621 } | 619 } |
622 | 620 |
623 // if back-off is enabled, we use 2 minutes maximum wait time fo
r a request, so we should make lg(120) | 621 int calls = backOff ? service.HttpClient.MessageHandler.NumTries
: 1; |
624 // 1 calls | |
625 int calls = backOff ? (int)Math.Ceiling(Math.Log(120, 2) 1) :
1; | |
626 Assert.That(handler.Calls, Is.EqualTo(calls)); | 622 Assert.That(handler.Calls, Is.EqualTo(calls)); |
627 } | 623 } |
628 } | 624 } |
629 | 625 |
630 /// <summary>· | 626 /// <summary>· |
631 /// Tests async execute when an exception is thrown during a request and
exponential back-off is enabled. | 627 /// Tests async execute when an exception is thrown during a request and
exponential back-off is enabled. |
632 /// </summary> | 628 /// </summary> |
633 [Test] | 629 [Test] |
634 public void ExecuteAsync_ThrowException_WithBackOff() | 630 public void ExecuteAsync_ThrowException_WithBackOff() |
635 { | 631 { |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Post)); | 1113 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Post)); |
1118 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Patch)); | 1114 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Patch)); |
1119 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Put)); | 1115 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Put)); |
1120 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Delete)); | 1116 Assert.AreEqual(ETagAction.IfMatch, ClientServiceRequest<object>.Get
DefaultETagAction(HttpConsts.Delete)); |
1121 Assert.AreEqual(ETagAction.Ignore, ClientServiceRequest<object>.GetD
efaultETagAction("INVALID")); | 1117 Assert.AreEqual(ETagAction.Ignore, ClientServiceRequest<object>.GetD
efaultETagAction("INVALID")); |
1122 } | 1118 } |
1123 | 1119 |
1124 #endregion | 1120 #endregion |
1125 } | 1121 } |
1126 } | 1122 } |
OLD | NEW |