245 lines
7.6 KiB
C++
Executable File
245 lines
7.6 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Unit test for ServiceManagement (SCM)
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Hannes Baeuerle, SLSE, 2015-03-14
|
|
*/
|
|
|
|
#include "data_topic_tests.h"
|
|
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
|
|
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
|
#include <Common/ProjectConfig/project_defines.h>
|
|
#include <DDS/DTS/generic_dts_impl.h>
|
|
#include <DDS/DTC/generic_dtc_impl.h>
|
|
|
|
#include <QtTest/QTest>
|
|
#include <QVariant>
|
|
#include <QThread>
|
|
|
|
|
|
|
|
DataTopicTests::DataTopicTests()
|
|
: m_domainParticipantPub(nullptr)
|
|
, m_domainParticipantSub(nullptr)
|
|
, m_domainId(0)
|
|
, m_ddsPublisher(nullptr)
|
|
, m_dtsServiceInformation(nullptr)
|
|
, m_dtsGroupInformation(nullptr)
|
|
, m_ddsSubscriber(nullptr)
|
|
, m_subscriberListener(nullptr)
|
|
, m_subscriberListenerBinder(nullptr)
|
|
, m_dtcServiceInformation(nullptr)
|
|
, m_dtcGroupInformation(nullptr)
|
|
, m_mainThreadId(QThread::currentThreadId())
|
|
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTests.DataTopicTests"))
|
|
{
|
|
if (!DDS::QosProfile::setDefault())
|
|
ERROR_LOG(m_logger) << "Error setting default QoS from xml-file ";
|
|
|
|
DEBUG_LOG(m_logger) << "Main thread ID is " << m_mainThreadId;
|
|
}
|
|
|
|
DataTopicTests::~DataTopicTests()
|
|
{
|
|
// Publisher
|
|
delete m_dtsServiceInformation;
|
|
delete m_dtsGroupInformation;
|
|
|
|
// Subscriber
|
|
delete m_dtcServiceInformation;
|
|
delete m_dtcGroupInformation;
|
|
|
|
m_subscriberListener->prepareShutdown();
|
|
m_subscriberListenerBinder = nullptr;
|
|
|
|
m_ddsSubscriber = nullptr;
|
|
m_ddsPublisher = nullptr;
|
|
|
|
m_domainParticipantSub = nullptr;
|
|
m_domainParticipantPub = nullptr;
|
|
}
|
|
|
|
/**
|
|
* Publisher
|
|
**/
|
|
|
|
bool DataTopicTests::initPublisher()
|
|
{
|
|
m_domainParticipantPub =
|
|
dds::domain::DomainParticipant(m_domainId,
|
|
DDS::QosProfile::domainParticipantShm());
|
|
|
|
dds::pub::qos::PublisherQos publisherQos = m_domainParticipantPub.default_publisher_qos();
|
|
|
|
// ExerciseData will be published to Partition 0
|
|
// use only selected partition
|
|
const std::string partition = IDL::exercisePartition(0);
|
|
|
|
dds::core::policy::Partition partitionQos;
|
|
partitionQos.name( { partition } );
|
|
publisherQos << partitionQos;
|
|
|
|
DEBUG_LOG(m_logger) << "Publish on partition " << partition;
|
|
|
|
m_ddsPublisher = dds::pub::Publisher(m_domainParticipantPub, publisherQos);
|
|
|
|
// Create DTSs
|
|
m_dtsServiceInformation = new DTS::ServiceInformationImpl(m_domainParticipantPub, m_ddsPublisher);
|
|
m_dtsGroupInformation = new DTS::GroupInformationImpl(m_domainParticipantPub, m_ddsPublisher);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool DataTopicTests::write(const ServiceManagement::ServiceInformation &data)
|
|
{
|
|
INFO_LOG(m_logger) << "Publish topic ServiceInformation ";
|
|
|
|
DEBUG_LOG(m_logger) << "Id: " << data.id()
|
|
<< ", Name: " << data.name()
|
|
<< ", State: " << data.state()
|
|
<< ", Timestamp: " << data.timestamp()
|
|
<< ", ErrorString: " << data.errorString()
|
|
;
|
|
|
|
return m_dtsServiceInformation->write(data);
|
|
}
|
|
|
|
bool DataTopicTests::write(const ServiceManagement::GroupInformation &data)
|
|
{
|
|
INFO_LOG(m_logger) << "Publish topic GroupInformation ";
|
|
|
|
if(m_logger.isDebugEnabled())
|
|
{
|
|
QString services;
|
|
|
|
for(int serviceId : data.services())
|
|
{
|
|
services.append(QString::number(serviceId));
|
|
services.append(QLatin1Char(','));
|
|
}
|
|
|
|
if(services.endsWith(QLatin1Char(',')))
|
|
services.chop(1);
|
|
|
|
DEBUG_LOG(m_logger) << "Type: " << data.type()
|
|
<< ", Domain: " << data.domainId()
|
|
<< ", Partition: " << data.exercisePartitionId()
|
|
<< ", Partition: " << data.replayPartitionId()
|
|
<< ", Services: " << services
|
|
<< ", Timestamp: " << data.timestamp();
|
|
}
|
|
|
|
return m_dtsGroupInformation->write(data);
|
|
}
|
|
|
|
ServiceManagement::ServiceInformation DataTopicTests::getReceivedServiceInformationData() const
|
|
{
|
|
return m_receivedServiceInformationData;
|
|
}
|
|
|
|
ServiceManagement::GroupInformation DataTopicTests::getReceivedGroupInformationData() const
|
|
{
|
|
return m_receivedGroupInformationData;
|
|
}
|
|
|
|
void DataTopicTests::processData(const ServiceManagement::ServiceInformation &instance, DataModification modType)
|
|
{
|
|
Q_UNUSED(modType);
|
|
INFO_LOG(m_logger) << "process Lts_ServiceInformation";
|
|
|
|
DEBUG_LOG(m_logger) << "Id: " << instance.id();
|
|
DEBUG_LOG(m_logger) << "Name: " << instance.name();
|
|
DEBUG_LOG(m_logger) << "State: " << instance.state();
|
|
DEBUG_LOG(m_logger) << "Timestamp: " << instance.timestamp();
|
|
DEBUG_LOG(m_logger) << "ErrorString: " << instance.errorString();
|
|
|
|
m_receivedServiceInformationData = instance;
|
|
|
|
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
|
|
|
emit serviceInformationDataArrived();
|
|
}
|
|
|
|
void DataTopicTests::processData(const ServiceManagement::GroupInformation &instance, DataModification modType)
|
|
{
|
|
Q_UNUSED(modType);
|
|
INFO_LOG(m_logger) << "process Lts_ServiceInformation";
|
|
|
|
if(m_logger.isDebugEnabled())
|
|
{
|
|
QString services;
|
|
|
|
for(int serviceId : instance.services())
|
|
{
|
|
services.append(QString::number(serviceId));
|
|
services.append(QLatin1Char(','));
|
|
}
|
|
|
|
if(services.endsWith(QLatin1Char(',')))
|
|
services.chop(1);
|
|
|
|
DEBUG_LOG(m_logger) << "Type: " << instance.type();
|
|
DEBUG_LOG(m_logger) << "Domain: " << instance.domainId();
|
|
DEBUG_LOG(m_logger) << "Partition: " << instance.exercisePartitionId();
|
|
DEBUG_LOG(m_logger) << "Replay Partition: " << instance.replayPartitionId();
|
|
DEBUG_LOG(m_logger) << "Services: " << services;
|
|
DEBUG_LOG(m_logger) << "Timestamp: " << instance.timestamp();
|
|
}
|
|
|
|
m_receivedGroupInformationData = instance;
|
|
|
|
QCOMPARE(m_mainThreadId, QThread::currentThreadId());
|
|
|
|
emit groupInformationDataArrived();
|
|
}
|
|
|
|
/**
|
|
* Subscriber
|
|
**/
|
|
|
|
bool DataTopicTests::initSubscriber()
|
|
{
|
|
DEBUG_LOG(m_logger) << "Initialisation DDS (Subscriber/Reader)";
|
|
|
|
m_domainParticipantSub =
|
|
dds::domain::DomainParticipant(m_domainId,
|
|
DDS::QosProfile::domainParticipantShm());
|
|
|
|
dds::sub::qos::SubscriberQos subscriberQos = m_domainParticipantSub.default_subscriber_qos();
|
|
|
|
// Initial Partition for listening on topic Exercise => partition 0
|
|
// + Listening for Topics in partition 1
|
|
dds::core::StringSeq partitions;
|
|
partitions.reserve(2);
|
|
for(int partitionId : { 0, 1 } )
|
|
{
|
|
partitions.push_back(IDL::exercisePartition(partitionId));
|
|
}
|
|
|
|
dds::core::policy::Partition partitionQos;
|
|
partitionQos.name( partitions );
|
|
subscriberQos << partitionQos;
|
|
|
|
DEBUG_LOG(m_logger) << "Initialise DTC::SubscriberListener";
|
|
m_subscriberListener = new DDSGeneric::SubscriberListener;
|
|
|
|
m_ddsSubscriber = dds::sub::Subscriber(m_domainParticipantSub,
|
|
subscriberQos);
|
|
m_subscriberListenerBinder = rti::core::bind_and_manage_listener(m_ddsSubscriber,
|
|
m_subscriberListener,
|
|
DDSGeneric::SubscriberListener::mask());
|
|
|
|
// Initialise DTCs
|
|
m_dtcServiceInformation = new DTC::ServiceInformationImpl(m_domainParticipantSub, m_ddsSubscriber, m_subscriberListener);
|
|
m_dtcGroupInformation = new DTC::GroupInformationImpl(m_domainParticipantSub, m_ddsSubscriber, m_subscriberListener);
|
|
|
|
m_dtcServiceInformation->setSubscriberCallback([this] (const ServiceManagement::ServiceInformation &data, DataModification modType) { processData(data, modType); } );
|
|
m_dtcGroupInformation->setSubscriberCallback([this] (const ServiceManagement::GroupInformation &data, DataModification modType) { processData(data, modType); } );
|
|
|
|
return true;
|
|
}
|