| 479 | }; |
| 480 | |
| 481 | class test_reconnect_update_simple : public proton::messaging_handler { |
| 482 | public: |
| 483 | test_reconnect_update_simple() |
| 484 | : container_(*this, "test_reconnect_update") {} |
| 485 | |
| 486 | proton::reconnect_options ropts() { |
| 487 | // Fast as we can to avoid needless test slowness. |
| 488 | return proton::reconnect_options().delay(proton::duration::MILLISECOND); |
| 489 | } |
| 490 | |
| 491 | proton::connection_options copts() { return proton::connection_options(); } |
| 492 | |
| 493 | void on_container_start(proton::container &c) override { |
| 494 | // Never actually connects, keeps re-trying to bogus hostnames with |
| 495 | // changing options. |
| 496 | c.connect("nosuchhost0", copts().reconnect(ropts()).virtual_host("vhost0").user("user0")); |
| 497 | } |
| 498 | |
| 499 | void on_transport_error(proton::transport &t) override { |
| 500 | switch (++errors_) { |
| 501 | case 1: |
| 502 | ASSERT_SUBSTRING("nosuchhost0", t.error().what()); // First failure |
| 503 | break; |
| 504 | case 2: { |
| 505 | ASSERT_SUBSTRING("nosuchhost0",t.error().what()); // Second failure |
| 506 | t.connection().update_options(copts().reconnect_url("nosuchhost1")); |
| 507 | // Verify changing reconnect options does not affect other options. |
| 508 | ASSERT_EQUAL("user0", t.connection().user()); |
| 509 | break; |
| 510 | } |
| 511 | case 3: |
| 512 | ASSERT_SUBSTRING("nosuchhost1", t.error().what()); // Re-try original |
| 513 | t.connection().update_options(copts().reconnect_url("notsuchahostatall")); |
| 514 | break; |
| 515 | case 4: |
| 516 | ASSERT_SUBSTRING("notsuchahostatall", t.error().what()); // Re-try new reconnect url |
| 517 | break; |
| 518 | case 5: |
| 519 | ASSERT_SUBSTRING("notsuchahostatall", t.error().what()); // Re-try new reconnect url |
| 520 | // Change a non-reconnect option should not affect reconnect |
| 521 | t.connection().update_options(copts().user("user1")); |
| 522 | break; |
| 523 | case 6: |
| 524 | ASSERT_SUBSTRING("notsuchahostatall", t.error().what()); // Same reconnect url |
| 525 | ASSERT_EQUAL("user1", t.connection().user()); |
| 526 | t.connection().update_options(copts().reconnect_url("nosuchhost1")); |
| 527 | break; |
| 528 | case 7: |
| 529 | ASSERT_SUBSTRING("nosuchhost1", t.error().what()); |
| 530 | break; |
| 531 | default: |
| 532 | t.connection().container().stop(); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | void run() { container_.run(); } |
| 537 | |
| 538 | private: |