bool Client::test_oneway_timeout (bool flood) { bool status = true; ACE_Auto_Array_Ptr<char> tmp (new char [6000000]); char* msg = tmp.get(); ACE_OS::memset (msg,'A',5999999); msg[5999999] = 0; test_obj_->dummy_two_way (); // connection establishment ACE_Time_Value tv (0); if (flood && !this->flood_connection(tv)) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> flooding failed.\n")); } // Timeout with SYNC_SCOPE SYNC_NONE try { std::string scope_name ("SYNC_NONE"); ACE_OS::strncpy (msg, scope_name.c_str(), scope_name.length()); test_obj_none_timeout_->dummy_one_way (msg); if (flood && flush_strategy_ == BLOCKING) { // block flushing gives a oneway SYNCH_WITH_TRANSPORT semantics ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: A Timeout was expected for SYNC_NONE.\n")); } else { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected no Timeout received for SYNC_NONE\n")); } } catch (const CORBA::TIMEOUT&) { if (flood && flush_strategy_ == BLOCKING) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected a timeout was received for SYNC_NONE.\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Unexpected " "timeout exception with synch scope SYNC_NONE.\n")); status = false; } } // Timeout with TAO specific SYNC_SCOPE SYNC_EAGER_BUFFERING try { std::string scope_name ("SYNC_EAGER_BUFFERING"); ACE_OS::strncpy (msg, scope_name.c_str(), scope_name.length()); /* BLOCKed flushing has SYNCH_WITH_TRANSPORT semantics. With flooding turned on you would have received a TIMEOUT in the previous test (SYNC_NONE). Even without flooding there is a chance to get back a TIMEOUT. The TIMEOUT has the side-effect closing out the connection. Therefore when flush_strategy is set to BLOCK we want to re-establish connection before each test. With flooding turned on we need to first unsleep the test server, re-establish connection and put it back to sleep. With flooding=0 we simple re-establish connection. This trick is performed at beginning of every test for flush_strategy == BLOCKING. */ if (flush_strategy_ == BLOCKING) { if (flood) { management_->unsleep (); test_obj_->sleep (0, 0); // rebuild connection and put server thread to sleep } else { // else simply re-establish connection test_obj_->dummy_two_way (); } } test_obj_eager_timeout_->dummy_one_way (msg); if (flood && flush_strategy_ == BLOCKING) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: A Timeout was expected for SYNC_EAGER_BUFFERING\n")); } else { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected no Timeout received for SYNC_EAGER_BUFFERING\n")); } } catch (const CORBA::TIMEOUT&) { if (flood && flush_strategy_ == BLOCKING) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected a timeout was received for SYNC_EAGER_BUFFERING\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Unexpected " "timeout exception with synch scope SYNC_EAGER_BUFFERING.\n")); status = false; } } // Timeout with TAO specific SYNC_SCOPE SYNC_DELAYED_BUFFERING try { std::string scope_name ("SYNC_DELAYED_BUFFERING"); ACE_OS::strncpy (msg, scope_name.c_str(), scope_name.length()); if (flush_strategy_ == BLOCKING) { if (flood) { management_->unsleep (); test_obj_->sleep (0, 0); } else { test_obj_->dummy_two_way (); } } test_obj_delayed_timeout_->dummy_one_way (msg); if (flood && flush_strategy_ == BLOCKING) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: A Timeout was expected for SYNC_DELAYED_BUFFERING\n")); } else { test_obj_delayed_timeout_->dummy_one_way ("SYNC_DELAYED_BUFFERING"); ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected no Timeout received for SYNC_DELAYED_BUFFERING\n")); } } catch (const CORBA::TIMEOUT&) { if (flood && flush_strategy_ == BLOCKING) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) Expected timeout received for SYNC_DELAYED_BUFFERING\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Unexpected " "timeout exception with synch scope SYNC_DELAYED_BUFFERING.\n")); status = false; } } /* Cleanup queue before the synchronous tests. We don't want the test results affected by leftovers from previous runs. */ ACE_Time_Value tv_tmp (1); orb_->run (tv_tmp); // Timeout with SYNC_SCOPE SYNC_WITH_TRANSPORT try { std::string scope_name ("SYNC_WITH_TRANSPORT"); ACE_OS::strncpy (msg, scope_name.c_str(), scope_name.length()); if (flush_strategy_ == BLOCKING) { if (flood) { management_->unsleep (); test_obj_->sleep (0, 0); } else { test_obj_->dummy_two_way (); } } test_obj_transport_timeout_->dummy_one_way (msg); if (flood) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Expected " "timeout not received for synch scope SYNC_WITH_TRANSPORT.\n" )); status = false; } else { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected no Timeout received for SYNC_WITH_TRANSPORT\n")); } } catch (const CORBA::TIMEOUT&) { if (flood) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) Expected Timeout received for SYNC_WITH_TRANSPORT\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Unexpected " "timeout exception with synch scope SYNC_WITH_TRANSPORT.\n")); status = false; } } // Timeout with default SYNC_SCOPE SYNC_WITH_SERVER try { std::string scope_name ("SYNC_WITH_SERVER"); ACE_OS::strncpy (msg, scope_name.c_str(), scope_name.length()); if (flush_strategy_ == BLOCKING) { if (flood) { management_->unsleep (); test_obj_->sleep (0, 0); } else { test_obj_->dummy_two_way (); } } test_obj_server_timeout_->dummy_one_way (msg); if (flood) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Expected " "timeout not received for SYNC_SCOPE SYNC_WITH_SERVER.\n")); status = false; } else { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected no Timeout received for SYNC_WITH_SERVER\n")); } } catch (const CORBA::TIMEOUT&) { if (flood) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) Expected Timeout received for SYNC_WITH_SERVER\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Unexpected " "timeout exception with synch scope SYNC_WITH_SERVER.\n")); status = false; } } // Timeout with default SYNC_SCOPE (SYNC_WITH_TARGET) try { std::string scope_name ("SYNC_WITH_TARGET"); ACE_OS::strncpy (msg, scope_name.c_str(), scope_name.length()); if (flush_strategy_ == BLOCKING) { if (flood) { management_->unsleep (); test_obj_->sleep (0, 0); } else { test_obj_->dummy_two_way (); } } test_obj_target_timeout_->dummy_one_way (msg); if (flood) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Expected " "timeout not received for SYNC_SCOPE SYNC_WITH_TARGET.\n")); status = false; } else { ACE_DEBUG ((LM_DEBUG, "(%P|%t) As expected no Timeout received for SYNC_WITH_TARGET\n")); } } catch (const CORBA::TIMEOUT&) { if (flood) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) Expected Timeout received for SYNC_WITH_TARGET\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: test_oneway_timeout> Unexpected " "timeout exception with synch scope SYNC_WITH_TARGET.\n")); status = false; } } if (flood) { management_->unsleep (); } return status; }
// Execute the client tests. void * client (void *arg) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) running client\n"))); ACE_INET_Addr *connection_addr = reinterpret_cast<ACE_INET_Addr *> (arg); CONNECTOR connector; int i; // Automagic memory cleanup. Write_Handler **temp_writers = 0; ACE_NEW_RETURN (temp_writers, Write_Handler *[opt_nconnections], 0); ACE_Auto_Basic_Array_Ptr <Write_Handler *> writers (temp_writers); ACE_TCHAR *temp_failed = 0; ACE_NEW_RETURN (temp_failed, ACE_TCHAR[opt_nconnections], 0); ACE_Auto_Basic_Array_Ptr <ACE_TCHAR> failed_svc_handlers (temp_failed); // Automagic memory cleanup. ACE_INET_Addr *temp_addresses; ACE_NEW_RETURN (temp_addresses, ACE_INET_Addr [opt_nconnections], 0); ACE_Auto_Array_Ptr <ACE_INET_Addr> addresses (temp_addresses); // Initialize array. for (i = 0; i < opt_nconnections; i++) { writers[i] = 0; addresses[i] = *connection_addr; } // Connection all <opt_nconnections> svc_handlers int result = connector.connect_n (opt_nconnections, writers.get (), addresses.get (), failed_svc_handlers.get ()); if (result == -1) { // Print out the connections that failed... for (i = 0; i < opt_nconnections; i++) if (failed_svc_handlers.get ()[i]) { ACE_INET_Addr failed_addr = addresses.get()[i]; ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) connection failed to %s, %d\n"), failed_addr.get_host_name (), failed_addr.get_port_number ())); } return 0; } // If no connections failed (result == 0) then there should be valid // ACE_Svc_handler pointers in each writers[] position. Iterate to // send data for (int j = 0; j < opt_nloops; j++) for (i = 0; i < opt_nconnections; i++) if (writers[i]->send_data () == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("writer::send_data")), 0); // Cleanup for (i = 0; i < opt_nconnections; i++) writers[i]->destroy (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) finishing client\n"))); return 0; }