Skip to content

Commit

Permalink
Merge pull request OpenDDS#3561 from sonndinh/task_586
Browse files Browse the repository at this point in the history
Fix BuiltInTopicTest timeout error

(cherry picked from commit 01c4d77)
  • Loading branch information
mitza-oci committed Jun 29, 2022
1 parent fc71487 commit 7aeb167
Show file tree
Hide file tree
Showing 9 changed files with 935 additions and 1,131 deletions.
96 changes: 44 additions & 52 deletions tests/DCPS/BuiltInTopicTest/DataReaderListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ using namespace std;

DataReaderListenerImpl::DataReaderListenerImpl()
: num_reads_(0),
publication_handle_ (::DDS::HANDLE_NIL),
post_restart_publication_handle_ (::DDS::HANDLE_NIL)
publication_handle_(::DDS::HANDLE_NIL),
post_restart_publication_handle_(::DDS::HANDLE_NIL)
{
}

DataReaderListenerImpl::~DataReaderListenerImpl ()
DataReaderListenerImpl::~DataReaderListenerImpl()
{
}

Expand All @@ -29,9 +29,8 @@ void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader)

try {
::Messenger::MessageDataReader_var message_dr = ::Messenger::MessageDataReader::_narrow(reader);
if (CORBA::is_nil (message_dr.in ())) {
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListener: read: _narrow failed.\n")));
if (!message_dr) {
ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) DataReaderListener: read: _narrow failed.\n")));
exit(1);
}

Expand All @@ -41,26 +40,20 @@ void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader)

if (status == DDS::RETCODE_OK) {

if (si.valid_data)
{
if (si.valid_data) {
if (si.publication_handle == ::DDS::HANDLE_NIL
|| (si.publication_handle != this->publication_handle_
&& si.publication_handle != this->post_restart_publication_handle_))
{
|| (si.publication_handle != this->publication_handle_
&& si.publication_handle != this->post_restart_publication_handle_)) {
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListener: ERROR: publication_handle validate failed.\n")));
exit(1);
}

ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) DataReaderListener: Message count = %i\n"), message.count));
}
else if (si.instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE)
{
} else if (si.instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) instance is disposed\n")));
}
else if (si.instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE)
{
} else if (si.instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) instance is unregistered\n")));
}
} else if (status == DDS::RETCODE_NO_DATA) {
Expand All @@ -71,39 +64,38 @@ void DataReaderListenerImpl::on_data_available(DDS::DataReader_ptr reader)
"(%P|%t) DataReaderListener: ERROR: read Message: Error: %i\n"), status));
}
} catch (CORBA::Exception& e) {
e._tao_print_exception(
"DataReaderListener: Exception caught in read:", stderr);
e._tao_print_exception("DataReaderListener: Exception caught in read:", stderr);
exit(1);
}
}

void DataReaderListenerImpl::on_requested_deadline_missed (
DDS::DataReader_ptr,
const DDS::RequestedDeadlineMissedStatus &)
void DataReaderListenerImpl::on_requested_deadline_missed(
DDS::DataReader_ptr,
const DDS::RequestedDeadlineMissedStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_requested_deadline_missed\n")));
}

void DataReaderListenerImpl::on_requested_incompatible_qos (
DDS::DataReader_ptr,
const DDS::RequestedIncompatibleQosStatus &)
void DataReaderListenerImpl::on_requested_incompatible_qos(
DDS::DataReader_ptr,
const DDS::RequestedIncompatibleQosStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_requested_incompatible_qos\n")));
}

void DataReaderListenerImpl::on_liveliness_changed (
DDS::DataReader_ptr,
const DDS::LivelinessChangedStatus &)
void DataReaderListenerImpl::on_liveliness_changed(
DDS::DataReader_ptr,
const DDS::LivelinessChangedStatus&)
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_liveliness_changed\n")));
}

void DataReaderListenerImpl::on_subscription_matched (
DDS::DataReader_ptr,
const DDS::SubscriptionMatchedStatus & status)
void DataReaderListenerImpl::on_subscription_matched(
DDS::DataReader_ptr,
const DDS::SubscriptionMatchedStatus& status)
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_matched handle=%i\n"),
Expand All @@ -128,8 +120,8 @@ bool DataReaderListenerImpl::read_bit_instance()
} else if (publication_handle_ != ::DDS::HANDLE_NIL) {
handle = publication_handle_;
} else {
ACE_DEBUG((LM_ERROR, ACE_TEXT(
"(%P|%t) Can't read bit instance, pre and post restart handles are invalid.\n")));
ACE_ERROR((LM_ERROR, "(%P|%t) ERROR: DataReaderListenerImpl::read_bit_instance:"
" Can't read bit instance, pre and post restart handles are invalid.\n"));
return false;
}
DDS::PublicationBuiltinTopicDataSeq data;
Expand All @@ -142,32 +134,32 @@ bool DataReaderListenerImpl::read_bit_instance()
switch (ret) {
case DDS::RETCODE_OK:
ACE_DEBUG((LM_DEBUG, ACE_TEXT(
"(%P|%t) read bit instance returned ok\n")));
return false;
"(%P|%t) DataReaderListenerImpl::read_bit_instance: returned ok\n")));
return true;
case DDS::RETCODE_NO_DATA:
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) read bit instance returned no data\n")));
ACE_ERROR((LM_NOTICE, ACE_TEXT(
"(%P|%t) NOTICE: DataReaderListenerImpl::read_bit_instance: returned no data. Retrying...\n")));
break;
case DDS::RETCODE_BAD_PARAMETER:
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) read bit instance returned bad parameter\n")));
ACE_ERROR((LM_NOTICE, ACE_TEXT(
"(%P|%t) NOTICE: DataReaderListenerImpl::read_bit_instance: returned bad parameter. Retrying...\n")));
break;
default:
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) ERROR read bit instance returned %i\n"), ret));
return true;
"(%P|%t) ERROR: DataReaderListenerImpl::read_bit_instance: returned %i\n"), ret));
return false;
}
ACE_OS::sleep(ACE_Time_Value(0, 100000));
}

ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) ERROR read bit instance: giving up after retries\n")));
return true;
"(%P|%t) ERROR: DataReaderListenerImpl::read_bit_instance: giving up after retries\n")));
return false;
}

void DataReaderListenerImpl::on_sample_rejected(
DDS::DataReader_ptr,
const DDS::SampleRejectedStatus&)
DDS::DataReader_ptr,
const DDS::SampleRejectedStatus&)
{
ACE_ERROR((LM_ERROR, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_sample_rejected\n")));
Expand All @@ -181,31 +173,31 @@ void DataReaderListenerImpl::on_sample_lost(
"(%P|%t) DataReaderListenerImpl::on_sample_lost\n")));
}

void DataReaderListenerImpl::on_subscription_disconnected (
void DataReaderListenerImpl::on_subscription_disconnected(
DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus &)
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus&)
{
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_disconnected\n")));
}

void DataReaderListenerImpl::on_subscription_reconnected (
void DataReaderListenerImpl::on_subscription_reconnected(
DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus &)
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus&)
{
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_reconnected\n")));
}

void DataReaderListenerImpl::on_subscription_lost (
void DataReaderListenerImpl::on_subscription_lost(
DDS::DataReader_ptr,
const ::OpenDDS::DCPS::SubscriptionLostStatus &)
const ::OpenDDS::DCPS::SubscriptionLostStatus&)
{
ACE_ERROR((LM_WARNING, ACE_TEXT(
"(%P|%t) DataReaderListenerImpl::on_subscription_lost\n")));
}

void DataReaderListenerImpl::set_builtin_datareader (
void DataReaderListenerImpl::set_builtin_datareader(
DDS::DataReader_ptr builtin)
{
builtin_ = DDS::DataReader::_duplicate(builtin);
Expand Down
37 changes: 18 additions & 19 deletions tests/DCPS/BuiltInTopicTest/DataReaderListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@
#endif /* ACE_LACKS_PRAGMA_ONCE */

class DataReaderListenerImpl
: public virtual OpenDDS::DCPS::LocalObject<DDS::DataReaderListener>
{
: public virtual OpenDDS::DCPS::LocalObject<DDS::DataReaderListener> {
public:
DataReaderListenerImpl ();
DataReaderListenerImpl();

virtual ~DataReaderListenerImpl (void);
virtual ~DataReaderListenerImpl(void);

virtual void on_requested_deadline_missed (
virtual void on_requested_deadline_missed(
DDS::DataReader_ptr reader,
const DDS::RequestedDeadlineMissedStatus & status);
const DDS::RequestedDeadlineMissedStatus& status);

virtual void on_requested_incompatible_qos (
virtual void on_requested_incompatible_qos(
DDS::DataReader_ptr reader,
const DDS::RequestedIncompatibleQosStatus & status);
const DDS::RequestedIncompatibleQosStatus& status);

virtual void on_liveliness_changed (
virtual void on_liveliness_changed(
DDS::DataReader_ptr reader,
const DDS::LivelinessChangedStatus & status);
const DDS::LivelinessChangedStatus& status);

virtual void on_subscription_matched (
virtual void on_subscription_matched(
DDS::DataReader_ptr reader,
const DDS::SubscriptionMatchedStatus & status);
const DDS::SubscriptionMatchedStatus& status);

virtual void on_sample_rejected(
DDS::DataReader_ptr reader,
Expand All @@ -45,23 +44,23 @@ class DataReaderListenerImpl
DDS::DataReader_ptr reader,
const DDS::SampleLostStatus& status);

virtual void on_subscription_disconnected (
virtual void on_subscription_disconnected(
DDS::DataReader_ptr reader,
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus & status);
const ::OpenDDS::DCPS::SubscriptionDisconnectedStatus& status);

virtual void on_subscription_reconnected (
virtual void on_subscription_reconnected(
DDS::DataReader_ptr reader,
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus & status);
const ::OpenDDS::DCPS::SubscriptionReconnectedStatus& status);

virtual void on_subscription_lost (
virtual void on_subscription_lost(
DDS::DataReader_ptr reader,
const ::OpenDDS::DCPS::SubscriptionLostStatus & status);
const ::OpenDDS::DCPS::SubscriptionLostStatus& status);

long num_reads() const {
return num_reads_;
}

void set_builtin_datareader (DDS::DataReader_ptr builtin);
void set_builtin_datareader(DDS::DataReader_ptr builtin);

bool read_bit_instance();

Expand Down

0 comments on commit 7aeb167

Please sign in to comment.