Skip to content

Commit

Permalink
Cherry-picked only the test changes from PR969:
Browse files Browse the repository at this point in the history
The total_count_change value should be the incremental changes in total_count since the last time the listener was called or the status was read. Tested and fixed this for on_offered_deadline_missed and on_requested_deadline_missed, see issue OpenDDS#619

    * tests/DCPS/Deadline/DataReaderListenerImpl.cpp:
    * tests/DCPS/Deadline/DataReaderListenerImpl.h:
    * tests/DCPS/Deadline/DataWriterListenerImpl.cpp:
    * tests/DCPS/Deadline/DataWriterListenerImpl.h:
    * tests/DCPS/Deadline/publisher.cpp:
    * tests/DCPS/Deadline/subscriber.cpp:
  • Loading branch information
mitza-oci committed Nov 2, 2018
1 parent 507d356 commit e48e427
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 45 deletions.
27 changes: 22 additions & 5 deletions tests/DCPS/Deadline/DataReaderListenerImpl.cpp
Expand Up @@ -10,6 +10,7 @@ DataReaderListenerImpl::DataReaderListenerImpl()
, matched_condition_(mutex_)
, matched_(0)
, num_arrived_(0)
, requested_deadline_total_count_ (0)
{
}

Expand All @@ -30,11 +31,23 @@ DataReaderListenerImpl::on_requested_deadline_missed(
DDS::DataReader_ptr /* reader */,
DDS::RequestedDeadlineMissedStatus const & status)
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) DataReaderListenerImpl::on_requested_deadline_missed:")
ACE_TEXT("total_count=%d total_count_change=%d last_instance_handle=%d\n"),
status.total_count, status.total_count_change, status.last_instance_handle));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DataReaderListenerImpl::on_requested_deadline_missed\n")));
if ((requested_deadline_total_count_ + status.total_count_change) != status.total_count)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) DataReaderListenerImpl::on_requested_deadline_missed:")
ACE_TEXT("Received incorrect total_count_change, previous total count %d ")
ACE_TEXT("new total_count=%d total_count_change=%d last_instance_handle=%d\n"),
requested_deadline_total_count_, status.total_count, status.total_count_change,
status.last_instance_handle));
}
else
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) DataReaderListenerImpl::on_requested_deadline_missed:")
ACE_TEXT("total_count=%d total_count_change=%d last_instance_handle=%d\n"),
status.total_count, status.total_count_change, status.last_instance_handle));
}
requested_deadline_total_count_ += status.total_count_change;
}

void
Expand Down Expand Up @@ -122,3 +135,7 @@ int DataReaderListenerImpl::wait_matched(long count, const ACE_Time_Value *absti
return count == matched_ ? 0 : result;
}

CORBA::Long DataReaderListenerImpl::requested_deadline_total_count (void) const
{
return requested_deadline_total_count_;
}
3 changes: 3 additions & 0 deletions tests/DCPS/Deadline/DataReaderListenerImpl.h
Expand Up @@ -63,6 +63,8 @@ class DataReaderListenerImpl

int wait_matched(long count, const ACE_Time_Value *abstime) const;

CORBA::Long requested_deadline_total_count (void) const;

protected:

virtual ~DataReaderListenerImpl (void);
Expand All @@ -73,6 +75,7 @@ class DataReaderListenerImpl
mutable ACE_Condition<ACE_Thread_Mutex> matched_condition_;
long matched_;
long num_arrived_;
CORBA::Long requested_deadline_total_count_;
};

#endif /* DATAREADER_LISTENER_IMPL */
29 changes: 22 additions & 7 deletions tests/DCPS/Deadline/DataWriterListenerImpl.cpp
Expand Up @@ -11,6 +11,7 @@ DataWriterListenerImpl::DataWriterListenerImpl()
: mutex_()
, matched_condition_(mutex_)
, matched_(0)
, offered_deadline_total_count_ (0)
{
}

Expand All @@ -23,13 +24,23 @@ DataWriterListenerImpl::on_offered_deadline_missed(
::DDS::DataWriter_ptr /* writer */,
const ::DDS::OfferedDeadlineMissedStatus& status)
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) DataWriterListenerImpl::on_offered_deadline_missed:")
ACE_TEXT("total_count=%d total_count_change=%d last_instance_handle=%d \n"),
status.total_count, status.total_count_change, status.last_instance_handle));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DataWriterListenerImpl::on_offered_deadline_missed\n")
ACE_TEXT(" total_count = %d\n")
ACE_TEXT(" total_count_change = %d\n"), status.total_count, status.total_count_change));
if ((offered_deadline_total_count_ + status.total_count_change) != status.total_count)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) DataWriterListenerImpl::on_offered_deadline_missed:")
ACE_TEXT("Received incorrect total_count_change, previous total count %d ")
ACE_TEXT("new total_count=%d total_count_change=%d last_instance_handle=%d\n"),
offered_deadline_total_count_, status.total_count, status.total_count_change,
status.last_instance_handle));
}
else
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) DataWriterListenerImpl::on_offered_deadline_missed:")
ACE_TEXT("total_count=%d total_count_change=%d last_instance_handle=%d\n"),
status.total_count, status.total_count_change, status.last_instance_handle));
}
offered_deadline_total_count_ += status.total_count_change;
}

void
Expand Down Expand Up @@ -94,3 +105,7 @@ int DataWriterListenerImpl::wait_matched(long count, const ACE_Time_Value *absti
return count == matched_ ? 0 : result;
}

CORBA::Long DataWriterListenerImpl::offered_deadline_total_count (void) const
{
return offered_deadline_total_count_;
}
26 changes: 10 additions & 16 deletions tests/DCPS/Deadline/DataWriterListenerImpl.h
Expand Up @@ -20,50 +20,44 @@ class DataWriterListenerImpl

virtual void on_offered_deadline_missed (
::DDS::DataWriter_ptr writer,
const ::DDS::OfferedDeadlineMissedStatus& status
);
const ::DDS::OfferedDeadlineMissedStatus& status);

virtual void on_offered_incompatible_qos (
::DDS::DataWriter_ptr writer,
const ::DDS::OfferedIncompatibleQosStatus& status
);
const ::DDS::OfferedIncompatibleQosStatus& status);

virtual void on_liveliness_lost (
::DDS::DataWriter_ptr writer,
const ::DDS::LivelinessLostStatus& status
);
const ::DDS::LivelinessLostStatus& status);

virtual void on_publication_matched (
::DDS::DataWriter_ptr writer,
const ::DDS::PublicationMatchedStatus& status
);
const ::DDS::PublicationMatchedStatus& status);

virtual void on_publication_disconnected (
::DDS::DataWriter_ptr reader,
const ::OpenDDS::DCPS::PublicationDisconnectedStatus& status
);
const ::OpenDDS::DCPS::PublicationDisconnectedStatus& status);

virtual void on_publication_reconnected (
::DDS::DataWriter_ptr reader,
const ::OpenDDS::DCPS::PublicationReconnectedStatus& status
);
const ::OpenDDS::DCPS::PublicationReconnectedStatus& status);

virtual void on_publication_lost (
::DDS::DataWriter_ptr writer,
const ::OpenDDS::DCPS::PublicationLostStatus& status
);
const ::OpenDDS::DCPS::PublicationLostStatus& status);

int wait_matched(long count, const ACE_Time_Value *abstime) const;

protected:
CORBA::Long offered_deadline_total_count (void) const;

protected:
virtual ~DataWriterListenerImpl (void);

private:

mutable ACE_Thread_Mutex mutex_;
mutable ACE_Condition<ACE_Thread_Mutex> matched_condition_;
long matched_;
CORBA::Long offered_deadline_total_count_;
};

#endif /* DATAWRITER_LISTENER_IMPL */
17 changes: 11 additions & 6 deletions tests/DCPS/Deadline/publisher.cpp
Expand Up @@ -96,7 +96,8 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[]){
// ----------------------------------------------

// Create the listener.
DDS::DataWriterListener_var listener(new DataWriterListenerImpl);
DataWriterListenerImpl* typed_listener_ptr = new DataWriterListenerImpl;
DDS::DataWriterListener_var listener(typed_listener_ptr);
if (CORBA::is_nil(listener.in()))
{
cerr << "ERROR: listener is nil." << endl;
Expand Down Expand Up @@ -130,7 +131,7 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[]){
dw_qos.deadline.period.sec = DEADLINE_PERIOD.sec;
dw_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec;

cerr << "Seting datawriter deadline QOS" << endl;
cerr << "Setting datawriter deadline QOS" << endl;

// Set qos with deadline. The watch dog starts now.
if (dw->set_qos(dw_qos) != ::DDS::RETCODE_OK)
Expand Down Expand Up @@ -182,12 +183,14 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[]){
exit(1);
}

if (deadline_status.total_count_change != NUM_EXPIRATIONS * NUM_WRITE_THREADS)
// Check if the total count changed is correctly giving the change between
// the last time our listener got invoked and our manual call now
if (deadline_status.total_count_change != (deadline_status.total_count - typed_listener_ptr->offered_deadline_total_count()))
{
cerr << "ERROR: Incorrect missed offered "
<< "deadline count change ("
<< deadline_status.total_count_change
<< ") instead of " << NUM_EXPIRATIONS * NUM_WRITE_THREADS
<< ") instead of " << (deadline_status.total_count - typed_listener_ptr->offered_deadline_total_count())
<< endl;

exit(1);
Expand Down Expand Up @@ -228,13 +231,15 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[]){
{
cerr << "ERROR: Unexpected number of missed offered "
<< "deadlines (" << deadline_status.total_count
<< " instead of " << (NUM_EXPIRATIONS + 2) * NUM_WRITE_THREADS << ") "
<< " instead of " << (deadline_status.total_count - typed_listener_ptr->offered_deadline_total_count()) << ") "
<< endl;

exit(1);
}

if (deadline_status.total_count_change != NUM_WRITE_THREADS * 2)
// Check if the total count changed is correctly giving the change between
// the last time our listener got invoked and our manual call now
if (deadline_status.total_count_change != (deadline_status.total_count - typed_listener_ptr->offered_deadline_total_count()))
{
cerr << "ERROR: Incorrect missed offered "
<< "deadline count change ("
Expand Down
30 changes: 19 additions & 11 deletions tests/DCPS/Deadline/subscriber.cpp
Expand Up @@ -317,16 +317,21 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
exit(1);
}

if (deadline_status1.total_count_change != NUM_INSTANCE
|| deadline_status2.total_count_change != NUM_INSTANCE)
// dr1 has a listener so we need to check if the total count changed compared
// to the last time we got it through the listener
// dr2 has no listener, so the total_count_change should match the total count
// and we have to save the value for the next check
CORBA::Long const deadline_total_count_2 = deadline_status2.total_count;
if (deadline_status1.total_count_change != (deadline_status1.total_count - listener_servant->requested_deadline_total_count ())
|| deadline_status2.total_count_change != deadline_status2.total_count)
{
cerr << "ERROR: Incorrect missed requested "
<< "deadline count change" << endl
<< " ("
<< "deadline count change ("
<< deadline_status1.total_count_change
<< " and/or "
<< deadline_status2.total_count_change
<< " instead of " << NUM_EXPIRATIONS * NUM_INSTANCE << ")."
<< ") instead of (" << (deadline_status1.total_count - listener_servant->requested_deadline_total_count ())
<< " and " << deadline_status2.total_count << ")"
<< endl;

exit(1);
Expand Down Expand Up @@ -389,21 +394,24 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
exit(1);
}

if (deadline_status1.total_count_change != 2 * NUM_INSTANCE
|| deadline_status2.total_count_change != 2 * NUM_INSTANCE)
// dr1 has a listener so we need to check if the total count changed compared
// to the last time we got it through the listener
// dr2 has no listener, so the total_count_change should match the total count
if (deadline_status1.total_count_change != (deadline_status1.total_count - listener_servant->requested_deadline_total_count ())
|| deadline_status2.total_count_change != (deadline_status2.total_count - deadline_total_count_2))
{
cerr << "ERROR: Incorrect missed requested "
<< "deadline count" << endl
<< " change ("
<< "deadline count change ("
<< deadline_status1.total_count_change
<< "and/or "
<< deadline_status2.total_count_change
<< " instead of " << NUM_EXPIRATIONS << ")." << endl;
<< ") instead of (" << (deadline_status1.total_count - listener_servant->requested_deadline_total_count ())
<< " and " << (deadline_status2.total_count - deadline_total_count_2) << ")"
<< endl;

exit(1);
}


int expected = 10;
while (listener_servant->num_arrived() < expected) {
ACE_OS::sleep(1);
Expand Down

0 comments on commit e48e427

Please sign in to comment.