MCPcopy Create free account
hub / github.com/apache/qpid-proton / test_reconnect_url

Class test_reconnect_url

cpp/src/reconnect_test.cpp:369–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369class test_reconnect_url : public proton::messaging_handler {
370public:
371 test_reconnect_url()
372 : container_(*this, "test_reconnect_update") {}
373
374 proton::reconnect_options ropts() {
375 // Fast as we can to avoid needless test slowness.
376 return proton::reconnect_options().delay(proton::duration::MILLISECOND);
377 }
378
379 proton::connection_options copts() { return proton::connection_options(); }
380
381 void on_container_start(proton::container &c) override {
382 // Never actually connects, keeps re-trying to bogus hostnames with
383 // changing options.
384 c.connect("nosuchhost0",
385 copts()
386 .reconnect(ropts())
387 .virtual_host("vhost0")
388 .user("user0")
389 .reconnect_url("hahaha1"));
390 }
391
392 void on_transport_error(proton::transport &t) override {
393 switch (++errors_) {
394 case 1:
395 ASSERT_SUBSTRING("nosuchhost0", t.error().what()); // First failure
396 break;
397 case 2: {
398 ASSERT_SUBSTRING("hahaha1",t.error().what()); // Second failure
399 ASSERT_EQUAL("user0", t.connection().user());
400 break;
401 }
402 case 3:
403 ASSERT_SUBSTRING("hahaha1", t.error().what()); // Still trying reconnect url
404 t.connection().update_options(copts().reconnect_url("nosuchhost1"));
405 // Verify changing reconnect options does not affect other options.
406 ASSERT_EQUAL("user0", t.connection().user());
407 break;
408 case 4:
409 ASSERT_SUBSTRING("nosuchhost1", t.error().what()); // Re-try new reconnect url
410 break;
411 default:
412 t.connection().container().stop();
413 }
414 }
415
416 void run() { container_.run(); }
417
418private:
419 int errors_ = 0;
420 proton::container container_;
421};
422
423// Verify we can change connection options for reconnect on_transport_error()
424class test_reconnect_update_failover : public proton::messaging_handler {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68