Verify we can change connection options for reconnect on_transport_error()
| 422 | |
| 423 | // Verify we can change connection options for reconnect on_transport_error() |
| 424 | class test_reconnect_update_failover : public proton::messaging_handler { |
| 425 | public: |
| 426 | test_reconnect_update_failover() |
| 427 | : container_(*this, "test_reconnect_update") {} |
| 428 | |
| 429 | proton::reconnect_options ropts() { |
| 430 | // Fast as we can to avoid needless test slowness. |
| 431 | return proton::reconnect_options().delay(proton::duration::MILLISECOND); |
| 432 | } |
| 433 | |
| 434 | proton::connection_options copts() { return proton::connection_options(); } |
| 435 | |
| 436 | void on_container_start(proton::container &c) override { |
| 437 | // Never actually connects, keeps re-trying to bogus hostnames with |
| 438 | // changing options. |
| 439 | c.connect("nosuchhost0", copts().reconnect(ropts()).virtual_host("vhost0").user("user0")); |
| 440 | } |
| 441 | |
| 442 | void on_transport_error(proton::transport &t) override { |
| 443 | switch (++errors_) { |
| 444 | case 1: |
| 445 | ASSERT_SUBSTRING("nosuchhost0", t.error().what()); // First failure |
| 446 | break; |
| 447 | case 2: { |
| 448 | ASSERT_SUBSTRING("nosuchhost0",t.error().what()); // Second failure |
| 449 | std::vector<std::string> urls; |
| 450 | urls.push_back("nosuchhost1"); |
| 451 | // Update the failover list |
| 452 | t.connection().update_options(copts().failover_urls(urls)); |
| 453 | // Verify changing reconnect options does not affect other options. |
| 454 | ASSERT_EQUAL("user0", t.connection().user()); |
| 455 | break; |
| 456 | } |
| 457 | case 3: |
| 458 | ASSERT_SUBSTRING("nosuchhost1", t.error().what()); // Using failover host |
| 459 | // Change a non-reconnect option should not affect reconnect |
| 460 | t.connection().update_options(copts().user("user1")); |
| 461 | break; |
| 462 | case 4: |
| 463 | ASSERT_SUBSTRING("nosuchhost0", t.error().what()); // Back to original url |
| 464 | ASSERT_EQUAL("user1", t.connection().user()); |
| 465 | break; |
| 466 | case 5: |
| 467 | ASSERT_SUBSTRING("nosuchhost1", t.error().what()); // Still have failover |
| 468 | break; |
| 469 | default: |
| 470 | t.connection().container().stop(); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void run() { container_.run(); } |
| 475 | |
| 476 | private: |
| 477 | int errors_ = 0; |
| 478 | proton::container container_; |
| 479 | }; |
| 480 | |
| 481 | class test_reconnect_update_simple : public proton::messaging_handler { |