diff options
Diffstat (limited to 'veslibrary/ves_cpplibrary/src')
13 files changed, 1268 insertions, 36 deletions
diff --git a/veslibrary/ves_cpplibrary/src/CMakeLists.txt b/veslibrary/ves_cpplibrary/src/CMakeLists.txt index b788dab..198b406 100755 --- a/veslibrary/ves_cpplibrary/src/CMakeLists.txt +++ b/veslibrary/ves_cpplibrary/src/CMakeLists.txt @@ -6,10 +6,20 @@ set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_SOURCE_DIR}/cmake/") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") -OPTION (ENABLE_COVERAGE "Use gcov" OFF) +OPTION (ENABLE_COVERAGE "Use coverage" OFF) MESSAGE(STATUS ENABLE_COVERAGE=${ENABLE_COVERAGE}) + +iF(NOT DEFINED COVERAGE_DIR) + set(COVERAGE_DIR "coverage") +ENDIF() + +MESSAGE(STATUS COVERAGE_DIR=${COVERAGE_DIR}) + IF(ENABLE_COVERAGE) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") + add_subdirectory(test) + add_dependencies(xtest xencode xtransport) ENDIF() add_subdirectory(lib) + diff --git a/veslibrary/ves_cpplibrary/src/Makefile b/veslibrary/ves_cpplibrary/src/Makefile deleted file mode 100644 index b0bc5eb..0000000 --- a/veslibrary/ves_cpplibrary/src/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -all: - mkdir build - cd build; cmake ..; make; make install - -.PHONY : test -test: - mkdir build - cd build; cmake .. -DENABLE_COVERAGE=ON; make; make install - mkdir test/build - cd test/build; cmake .. -DENABLE_COVERAGE=ON; make; ./xtest - lcov -c -d build/lib/encode/CMakeFiles/xencode.dir -d build/lib/transport/CMakeFiles/xtransport.dir -o coverage.info - lcov -r coverage.info '/usr/*' '*/transport/gen-cpp/*' -o xvesagent.info - genhtml xvesagent.info -o coverage - rm -rf *.info - -clean: - rm *.info -rf - rm build -rf - rm coverage -rf - rm test/build -rf diff --git a/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake index 2c8c993..c0e2191 100644 --- a/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake +++ b/veslibrary/ves_cpplibrary/src/cmake/xencodeConfig.cmake @@ -1,6 +1,8 @@ -find_library(XENCODE_LIBRARY xencode) -find_path(XENCODE_INCLUDE_DIR xvesagent/xencode/XEvent.h) -set(XENCODE_INCLUDE_DIR "${XENCODE_INCLUDE_DIR}/xvesagent/xencode") +find_library(XENCODE_LIBRARY xencode ${PROJECT_BINARY_DIR}/lib/encode) +IF(${XENCODE_LIBRARY} MATCHES "XENCODE_LIBRARY-NOTFOUND") + set(XENCODE_LIBRARY ${PROJECT_BINARY_DIR}/lib/encode/libxencode.so) +ENDIF() +find_path(XENCODE_INCLUDE_DIR XEvent.h ${CMAKE_SOURCE_DIR}/lib/encode/include) message("xencode include dir: ${XENCODE_INCLUDE_DIR}") message("xencode library dir: ${XENCODE_LIBRARY}") diff --git a/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake index 819279f..2565d13 100644 --- a/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake +++ b/veslibrary/ves_cpplibrary/src/cmake/xlogConfig.cmake @@ -1,4 +1,4 @@ -find_path(XLOG_INCLUDE_DIR xvesagent/XLog.h) -set(XLOG_INCLUDE_DIR "${XLOG_INCLUDE_DIR}/xvesagent") +find_path(XLOG_INCLUDE_DIR XLog.h ${CMAKE_SOURCE_DIR}/lib/common) +#set(XLOG_INCLUDE_DIR "${XLOG_INCLUDE_DIR}/xvesagent") message("xlog include dir: ${XLOG_INCLUDE_DIR}") diff --git a/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake b/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake index f0163eb..bc8060e 100644 --- a/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake +++ b/veslibrary/ves_cpplibrary/src/cmake/xtransportConfig.cmake @@ -1,6 +1,8 @@ -find_library(XTRANSPORT_LIBRARY xtransport) -find_path(XTRANSPORT_INCLUDE_DIR xvesagent/xtransport/XTransport.h) -set(XTRANSPORT_INCLUDE_DIR "${XTRANSPORT_INCLUDE_DIR}/xvesagent/xtransport") +find_library(XTRANSPORT_LIBRARY xtransport ${PROJECT_BINARY_DIR}/lib/transport) +IF(XTRANSPORT_LIBRARY MATCHES "XTRANSPORT_LIBRARY-NOTFOUND") + set(XTRANSPORT_LIBRARY ${PROJECT_BINARY_DIR}/lib/transport/libxtransport.so) +ENDIF() +find_path(XTRANSPORT_INCLUDE_DIR XTransport.h ${CMAKE_SOURCE_DIR}/lib/transport/include) message("xtransport include dir: ${XTRANSPORT_INCLUDE_DIR}") message("xtransport library dir: ${XTRANSPORT_LIBRARY}") diff --git a/veslibrary/ves_cpplibrary/src/lib/transport/XDiskQueue.cpp b/veslibrary/ves_cpplibrary/src/lib/transport/XDiskQueue.cpp index c63d19e..5834f97 100755 --- a/veslibrary/ves_cpplibrary/src/lib/transport/XDiskQueue.cpp +++ b/veslibrary/ves_cpplibrary/src/lib/transport/XDiskQueue.cpp @@ -160,7 +160,7 @@ std::string vagt::queue::XDiskQueue::front() std::string vagt::queue::XDiskQueue::createKey()
{
auto now = chrono::system_clock::now().time_since_epoch().count(); - snprintf(key, sizeof(key), "%020ld_%010u", now, keyId_.fetch_add(1));
+ snprintf(key, sizeof(key), "%020ld_%010ld", now, keyId_.fetch_add(1));
return key;
}
diff --git a/veslibrary/ves_cpplibrary/src/lib/transport/XRpcClientTransport.cpp b/veslibrary/ves_cpplibrary/src/lib/transport/XRpcClientTransport.cpp index a63fc00..84711d9 100755 --- a/veslibrary/ves_cpplibrary/src/lib/transport/XRpcClientTransport.cpp +++ b/veslibrary/ves_cpplibrary/src/lib/transport/XRpcClientTransport.cpp @@ -65,12 +65,12 @@ XErrorCode vagt::transport::XRpcClientTransport::post(const std::string & event) {
return (XErrorCode)(rpcClient_->post(event));
}
- catch (TTransportException ex)
+ catch (TTransportException& ex)
{
SPDLOG_ERROR("Fail to post event:({}).", ex.what());
return XErrorNetworkError;
}
- catch (TException ex)
+ catch (TException& ex)
{
SPDLOG_ERROR("Fail to post event:({}).", ex.what());
return XErrorNetworkError;
@@ -133,12 +133,12 @@ XErrorCode vagt::transport::XRpcClientTransport::startRPC() {
rpcTransport_->open();
}
- catch (TTransportException ex)
+ catch (TTransportException& ex)
{
SPDLOG_ERROR("Fail to start rpc client:({}).", ex.what());
return XErrorNok;
}
- catch (TException ex)
+ catch (TException& ex)
{
SPDLOG_ERROR("Fail to start rpc client:({}).", ex.what());
return XErrorNok;
@@ -164,12 +164,12 @@ XErrorCode vagt::transport::XRpcClientTransport::stopRPC() rpcTransport_->close();
rpcTransport_.reset();
}
- catch (TTransportException ex)
+ catch (TTransportException& ex)
{
SPDLOG_ERROR("Fail to stop rpc client:({}).", ex.what());
return XErrorNok;
}
- catch (TException ex)
+ catch (TException& ex)
{
SPDLOG_ERROR("Fail to stop rpc client:({}).", ex.what());
return XErrorNok;
diff --git a/veslibrary/ves_cpplibrary/src/test/CMakeLists.txt b/veslibrary/ves_cpplibrary/src/test/CMakeLists.txt new file mode 100755 index 0000000..682f784 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/test/CMakeLists.txt @@ -0,0 +1,29 @@ +find_package(xencode)
+find_package(xtransport)
+find_package(xlog)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+
+aux_source_directory(. TEST_SRCS)
+
+include_directories(${XENCODE_INCLUDE_DIR})
+include_directories(${XTRANSPORT_INCLUDE_DIR})
+include_directories(${XLOG_INCLUDE_DIR})
+
+add_executable(xtest ${TEST_SRCS})
+
+target_link_libraries(xtest ${XENCODE_LIBRARY} ${XTRANSPORT_LIBRARY})
+
+add_custom_command(TARGET xtest
+ POST_BUILD
+ COMMAND ./test/xtest
+ COMMAND gcov -d lib/encode/CMakeFiles/xencode.dir/*.cpp.gcno lib/transport/CMakeFiles/xtransport.dir/*.cpp.gcno lib/encode/CMakeFiles/xencode.dir/__/common/*.cpp.gcno test/CMakeFiles/xtest.dir/*.cpp.gcno
+ COMMAND mkdir -p ${COVERAGE_DIR}
+ COMMAND mv X*.gcov ${COVERAGE_DIR}/
+ COMMAND rm *.gcov -rf
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+
+INSTALL(TARGETS xtest
+ RUNTIME DESTINATION bin
+)
diff --git a/veslibrary/ves_cpplibrary/src/test/XEventSamples.cpp b/veslibrary/ves_cpplibrary/src/test/XEventSamples.cpp new file mode 100755 index 0000000..76fb1b2 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/test/XEventSamples.cpp @@ -0,0 +1,913 @@ +#include "XEventSamples.h"
+
+shared_ptr<XSerialable> buildFault()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto fault = XFaultFields::create(header,
+ "condition",
+ "specProblem",
+ XEnumFaultFieldsEventSourceTypeVirtualMachine,
+ XEnumFaultFieldsEventSeverityNORMAL,
+ XEnumFaultFieldsVfStatusActive);
+
+ auto header2 = fault->getCommonHeader();
+ header2->setSourceId("XXSourceID");
+
+ fault->setAlarmInterfaceA("Interface");
+ fault->setEventSeverity(XEnumFaultFieldsEventSeverityMAJOR);
+ fault->setAlarmCondition("XXCondition");
+ fault->setVfStatus(XEnumFaultFieldsVfStatusRequestingTermination);
+ fault->setEventCategory("Category");
+ fault->setEventSourceType(XEnumFaultFieldsEventSourceTypeVirtualMachine);
+ fault->setSpecificProblem("XXProblem");
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+ fault->setAlarmAdditionalInformation(hm);
+
+ return fault;
+}
+
+shared_ptr<XSerialable> buildHeartbeat()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ header->toString();
+ header->setEventId("event id");
+ header->setStartEpochMicrosec(0);
+ header->setLastEpochMicrosec(0);
+ header->setReportingEntityName("report name");
+ header->setReportingEntityId("report id");
+ header->setEventType("event type");
+ header->setSequence(0);
+ header->setInternalHeaderFields("{}");
+ header->setPriority(XEnumCommonEventHeaderPriorityHigh);
+ header->setSourceName("source name");
+ header->setEventName("event name");
+ header->setNfNamingCode("nf");
+ header->setNfcNamingCode("nfc");
+ header->setTimeZoneOffset("zone");
+ header->setNfVendorName("vendor");
+
+ auto event = XHeartbeatFields::create(header, 100);
+ event->setHeartbeatInterval(11);
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+ event->setAdditionalFields(hm);
+ event->getCommonHeader();
+
+ return event;
+}
+
+shared_ptr<XSerialable> buildMeasurement()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto event = XMeasurementFields::create(header, 100.0);
+ event->setMeasurementInterval(1);
+ event->getCommonHeader();
+
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+
+ {
+ XCodecsInUse cd("xx",11);
+ cd.setCodecIdentifier("zzz");
+ cd.setNumberInUse(300);
+ XArrayOfXCodecsInUse arr{ cd };
+ event->setCodecUsageArray(arr);
+ }
+
+ event->setFeatureUsageArray(hm);
+ event->setConfiguredEntities(100);
+
+ {
+ XArrayOfNamedHashMap arr{ { "name1", hm },{ "name2", hm } };
+ event->setAdditionalMeasurements(arr);
+ }
+
+ {
+ XArrayOfXCpuUsage arr;
+
+ XCpuUsage u1("cpu1", 100);
+ u1.setCpuUsageSystem(90);
+ u1.setCpuCapacityContention(1);
+ u1.setCpuDemandAvg(1);
+ u1.setCpuDemandMhz(1);
+ u1.setCpuDemandPct(1);
+ u1.setCpuIdentifier("id");
+ u1.setCpuIdle(1);
+ u1.setCpuLatencyAvg(1);
+ u1.setCpuOverheadAvg(1);
+ u1.setCpuSwapWaitTime(1);
+ u1.setCpuUsageInterrupt(1);
+ u1.setCpuUsageNice(1);
+ u1.setCpuUsageSoftIrq(1);
+ u1.setCpuUsageSteal(1);
+ u1.setCpuUsageUser(1);
+ u1.setCpuWait(1);
+ u1.setPercentUsage(1);
+
+ XCpuUsage u2("cpu2", 10);
+ u2.setCpuUsageSystem(99);
+
+ arr.push_back(u1);
+ arr.push_back(u2);
+ event->setCpuUsageArray(arr);
+ }
+
+ event->setRequestRate(99);
+
+ {
+ XArrayOfXFilesystemUsage arr{ { "/root", 1, 2, 3, 4, 5, 6 },{ "/tmp", 1, 2, 3, 4, 5, 6 } };
+ arr[0].setBlockConfigured(1);
+ arr[0].setBlockUsed(1);
+ arr[0].setEphemeralConfigured(1);
+ arr[0].setEphemeralIops(1);
+ arr[0].setBlockIops(1);
+ arr[0].setEphemeralUsed(1);
+ arr[0].setFilesystemName("/var");
+
+ event->setFilesystemUsageArray(arr);
+ }
+
+ {
+ XArrayOfXLoad arr;
+
+ XLoad l1;
+ l1.setLongTerm(100);
+ l1.setMidTerm(50);
+
+ XLoad l2;
+ l2.setLongTerm(100);
+ l2.setShortTerm(10);
+
+ arr.push_back(l1);
+ arr.push_back(l2);
+ event->setLoadArray(arr);
+ }
+
+ {
+ XArrayOfXMachineCheckException arr{ { "Machine1" } };
+
+ XMachineCheckException m("Machine2");
+ m.setCorrectedMemoryErrors(1);
+ m.setUncorrectedMemoryErrors(1);
+ m.setUncorrectedMemoryErrorsIn1Hr(1);
+ m.setCorrectedMemoryErrorsIn1Hr(1);
+ m.setVmIdentifier("xx");
+ arr.push_back(m);
+
+ event->setMachineCheckExceptionArray(arr);
+ }
+
+ event->setMeanRequestLatency(2000);
+ event->setConcurrentSessions(300);
+ event->setAdditionalFields(hm);
+ {
+ XArrayOfXProcessStats arr{ { "process1" } };
+
+ XProcessStats p2("p2");
+ p2.setForkRate(1);
+ p2.setPsStateStopped(1);
+ p2.setPsStatePaging(1);
+ p2.setPsStateSleeping(1);
+ p2.setProcessIdentifier("xx");
+ p2.setPsStateBlocked(1);
+ p2.setPsStateZombie(1);
+ p2.setPsStateRunning(1);
+
+ arr.push_back(p2);
+
+ event->setProcessStatsArray(arr);
+ }
+
+ {
+ XNicPerformance nic("Nic1", XEnumNicPerformanceValuesAreSuspectTrue );
+ nic.setTransmittedErrorPacketsDelta(1);
+ nic.setReceivedErrorPacketsAccumulated(1);
+ nic.setTransmittedDiscardedPacketsDelta(1);
+ nic.setReceivedOctetsDelta(1);
+ nic.setReceivedMulticastPacketsDelta(1);
+ nic.setTransmittedDiscardedPacketsAccumulated(1);
+ nic.setTransmittedMulticastPacketsAccumulated(1);
+ nic.setReceivedDiscardedPacketsDelta(1);
+ nic.setReceivedOctetsAccumulated(1);
+ nic.setTransmittedTotalPacketsAccumulated(1);
+ nic.setTransmittedOctetsAccumulated(1);
+ nic.setSpeed(1);
+ nic.setReceivedDiscardedPacketsAccumulated(1);
+ nic.setReceivedBroadcastPacketsDelta(1);
+ nic.setReceivedPercentDiscard(1);
+ nic.setTransmittedPercentDiscard(1);
+ nic.setTransmittedErrorPacketsAccumulated(1);
+ nic.setTransmittedBroadcastPacketsAccumulated(1);
+ nic.setReceivedTotalPacketsAccumulated(1);
+ nic.setReceivedUnicastPacketsAccumulated(1);
+ nic.setTransmittedBroadcastPacketsDelta(1);
+ nic.setTransmittedMulticastPacketsDelta(1);
+ nic.setReceivedMulticastPacketsAccumulated(1);
+ nic.setReceivedTotalPacketsDelta(1);
+ nic.setReceivedPercentError(1);
+ nic.setReceivedErrorPacketsDelta(1);
+ nic.setTransmittedOctetsDelta(1);
+ nic.setNicIdentifier("xx");
+ nic.setTransmittedUnicastPacketsAccumulated(1);
+ nic.setReceivedUnicastPacketsDelta(1);
+ nic.setTransmittedUtilization(1);
+ nic.setReceivedBroadcastPacketsAccumulated(1);
+ nic.setTransmittedUnicastPacketsDelta(1);
+ nic.setReceivedUtilization(1);
+ nic.setTransmittedPercentError(1);
+ nic.setTransmittedTotalPacketsDelta(1);
+ nic.setValuesAreSuspect(XEnumNicPerformanceValuesAreSuspectFalse);
+ nic.setOperationalState(XEnumNicPerformanceOperationalStateInService);
+ nic.setAdministrativeState(XEnumNicPerformanceAdministrativeStateInService);
+
+ XArrayOfXNicPerformance arr{ nic };
+
+ event->setNicPerformanceArray(arr);
+ }
+
+ {
+ XArrayOfXDiskUsage arr{ { "d1" } };
+
+ XDiskUsage d2("d2");
+
+ d2.setDiskOctetsWriteLast(1);
+ d2.setDiskIoTimeAvg(1);
+ d2.setDiskMergedReadMin(1);
+ d2.setDiskTotalReadLatencyAvg(1);
+ d2.setDiskOpsReadMax(1);
+ d2.setDiskOpsReadMin(1);
+ d2.setDiskBusResets(1);
+ d2.setDiskMergedReadLast(1);
+ d2.setDiskTimeReadAvg(1);
+ d2.setDiskMergedWriteMax(1);
+ d2.setDiskTime(1);
+ d2.setDiskOpsWriteLast(1);
+ d2.setDiskOpsReadAvg(1);
+ d2.setDiskFlushRequests(1);
+ d2.setDiskFlushTime(1);
+ d2.setDiskOpsReadLast(1);
+ d2.setDiskMergedReadAvg(1);
+ d2.setDiskWriteCommandsAvg(1);
+ d2.setDiskTimeReadMin(1);
+ d2.setDiskOpsWriteAvg(1);
+ d2.setDiskWeightedIoTimeMin(1);
+ d2.setDiskIoTimeLast(1);
+ d2.setDiskMergedReadMax(1);
+ d2.setDiskOctetsReadMin(1);
+ d2.setDiskWeightedIoTimeAvg(1);
+ d2.setDiskTimeWriteMin(1);
+ d2.setDiskCommandsAvg(1);
+ d2.setDiskTimeWriteMax(1);
+ d2.setDiskPendingOperationsMin(1);
+ d2.setDiskTimeReadMax(1);
+ d2.setDiskOctetsReadMax(1);
+ d2.setDiskOpsWriteMin(1);
+ d2.setDiskReadCommandsAvg(1);
+ d2.setDiskMergedWriteMin(1);
+ d2.setDiskOctetsWriteMax(1);
+ d2.setDiskTimeWriteLast(1);
+ d2.setDiskPendingOperationsLast(1);
+ d2.setDiskWeightedIoTimeLast(1);
+ d2.setDiskIdentifier("id");
+ d2.setDiskOctetsWriteMin(1);
+ d2.setDiskTimeWriteAvg(1);
+ d2.setDiskOctetsWriteAvg(1);
+ d2.setDiskOctetsReadLast(1);
+ d2.setDiskWeightedIoTimeMax(1);
+ d2.setDiskCommandsAborted(1);
+ d2.setDiskOpsWriteMax(1);
+ d2.setDiskTimeReadLast(1);
+ d2.setDiskMergedWriteAvg(1);
+ d2.setDiskOctetsReadAvg(1);
+ d2.setDiskTotalWriteLatencyAvg(1);
+ d2.setDiskIoTimeMax(1);
+ d2.setDiskIoTimeMin(1);
+ d2.setDiskPendingOperationsAvg(1);
+ d2.setDiskMergedWriteLast(1);
+ d2.setDiskPendingOperationsMax(1);
+
+ arr.push_back(d2);
+ event->setDiskUsageArray(arr);
+ }
+
+ {
+ XIpmi ipmi;
+
+ XIpmiBattery battery("id");
+ battery.setBatteryIdentifier("id");
+ battery.setBatteryType("xx");
+ battery.setBatteryVoltageLevel(1);
+ XArrayOfXIpmiBattery batteries{ battery };
+ ipmi.setIpmiBatteryArray(batteries);
+
+ XIpmiHsbp hsbp("id");
+ hsbp.setHsbpIdentifier("xx");
+ hsbp.setHsbpTemperature(1);
+ ipmi.setIpmiHsbpArray({hsbp});
+
+ ipmi.setSystemAirflow(100);
+
+ XArrayOfXIpmiFan fans{ { "fan1" } };
+ XIpmiFan fan("fan2");
+ fan.setFanSpeed(100);
+ fan.setFanIdentifier("xx");
+ fans.push_back(fan);
+ ipmi.setIpmiFanArray(fans);
+
+ XArrayOfXIpmiProcessor processors{ { "processor1" } };
+ XIpmiProcessor processor2("processor2");
+ processor2.setProcessorThermalControlPercent(90);
+ processor2.setProcessorDtsThermalMargin(80);
+ processor2.setProcessorIdentifier("xx");
+
+ XArrayOfXProcessorDimmAggregateThermalMargin margins{ { "m1",1 },{ "m2",2 } };
+ margins[0].setThermalMargin(1);
+ margins[0].setProcessorDimmAggregateThermalMarginIdentifier("xx");
+
+ processor2.setProcessorDimmAggregateThermalMarginArray(margins);
+ processors.push_back(processor2);
+ ipmi.setIpmiProcessorArray(processors);
+
+ ipmi.setExitAirTemperature(36.5);
+
+
+ XArrayOfXIpmiBaseboardVoltageRegulator vols{ { "vol1" } };
+ XIpmiBaseboardVoltageRegulator vol2("vol2");
+ vol2.setVoltageRegulatorTemperature(70);
+ vol2.setBaseboardVoltageRegulatorIdentifier("xx");
+ vols.push_back(vol2);
+ ipmi.setIpmiBaseboardVoltageRegulatorArray(vols);
+
+ XArrayOfXIpmiGlobalAggregateTemperatureMargin ts{ { "t1",11 },{ "t2", 22 } };
+ ts[0].setGlobalAggregateTemperatureMargin(1);
+ ts[0].setIpmiGlobalAggregateTemperatureMarginIdentifier("xx");
+
+ ipmi.setIpmiGlobalAggregateTemperatureMarginArray(ts);
+
+ XArrayOfXIpmiNic nics{ { "nic1" } };
+ XIpmiNic nic2{ "nic2" };
+ nic2.setNicTemperature(333);
+ nic2.setNicIdentifier("xx");
+ nics.push_back(nic2);
+ ipmi.setIpmiNicArray(nics);
+
+ XArrayOfXIpmiBaseboardTemperature bts{ { "t1" } };
+ XIpmiBaseboardTemperature bt2("b2");
+ bt2.setBaseboardTemperature(55);
+ bt2.setBaseboardTemperatureIdentifier("xx");
+
+ bts.push_back(bt2);
+ ipmi.setIpmiBaseboardTemperatureArray(bts);
+
+ XArrayOfXIpmiPowerSupply pss{ { "p1" } };
+ XIpmiPowerSupply ps2("p2");
+ ps2.setPowerSupplyCurrentOutputPercent(1);
+ ps2.setPowerSupplyInputPower(2);
+ ps2.setPowerSupplyTemperature(3);
+ ps2.setPowerSupplyIdentifier("xx");
+ pss.push_back(ps2);
+ ipmi.setIpmiPowerSupplyArray(pss);
+
+ ipmi.setIoModuleTemperature(66);
+ ipmi.setFrontPanelTemperature(1);
+
+ event->setIpmi(ipmi);
+ }
+
+ {
+ XArrayOfXLatencyBucketMeasure arr{ 1 };
+ XLatencyBucketMeasure lat2(2);
+ lat2.setCountsInTheBucket(100);
+ lat2.setHighEndOfLatencyBucket(1000);
+ lat2.setLowEndOfLatencyBucket(1);
+ arr.push_back(lat2);
+
+ event->setLatencyDistribution(arr);
+ }
+
+ {
+ XArrayOfXHugePages arr{ { "h1" } };
+ XHugePages h2("h2");
+ h2.setBytesUsed(100);
+ h2.setVmPageNumberFree(1);
+ h2.setBytesFree(1);
+ h2.setPercentFree(1);
+ h2.setPercentUsed(1);
+ h2.setVmPageNumberUsed(1);
+ h2.setHugePagesIdentifier("h2");
+
+ arr.push_back(h2);
+ event->setHugePagesArray(arr);
+ }
+
+ event->setNumberOfMediaPortsInUse(111);
+ event->setNfcScalingMetric(222);
+
+ {
+ XArrayOfXMemoryUsage arr{ { "mem1", 100, 200 } };
+ XMemoryUsage mem2("mem2", 2, 3);
+ mem2.setMemorySwapInAvg(1);
+ mem2.setMemorySwapUsedAvg(1);
+ mem2.setMemorySlabRecl(1);
+ mem2.setMemorySwapInRateAvg(1);
+ mem2.setMemoryDemand(1);
+ mem2.setMemoryConfigured(1);
+ mem2.setMemorySharedAvg(1);
+ mem2.setVmIdentifier("xx");
+ mem2.setMemoryLatencyAvg(1);
+ mem2.setMemorySwapOutAvg(1);
+ mem2.setMemorySwapOutRateAvg(1);
+ mem2.setMemoryFree(1);
+ mem2.setMemorySlabUnrecl(1);
+ mem2.setMemoryCached(1);
+ mem2.setMemoryUsed(1);
+ mem2.setMemoryBuffered(1);
+ mem2.setPercentMemoryUsage(1);
+
+ arr.push_back(mem2);
+ event->setMemoryUsageArray(arr);
+ }
+
+ {
+ XArrayOfJsonObject objs;
+
+ XArrayOfXJsonObjectInstance ins;
+ XArrayOfXJsonObjectInstance ins2;
+
+ XJsonObject obj2("obj2", ins2);
+ obj2.setObjectSchema("xx");
+ obj2.setObjectName("xx");
+ obj2.setNfSubscribedObjectName("xx");
+ obj2.setNfSubscriptionId("xx");
+ obj2.setObjectSchemaUrl("xx");
+ obj2.setObjectInstances(ins2);
+
+ XJsonObjectInstance ins1;
+ ins1.setJsonObject(obj2);
+ ins1.setObjectInstance(R"({"aa":"bb"})");
+ ins1.setObjectInstanceEpochMicrosec(111);
+ XArrayOfXKey keys{ { "k1" } };
+ XKey k2("k2");
+ k2.setKeyName("keyname");
+ k2.setKeyOrder(11);
+ k2.setKeyValue("value");
+ keys.push_back(k2);
+ ins1.setObjectKeys(keys);
+
+ ins.push_back(ins1);
+
+ XJsonObject obj("obj1", ins);
+ objs.push_back(obj);
+
+ event->setAdditionalObjects(objs);
+ }
+
+ return event;
+}
+
+shared_ptr<XSerialable> buildNotification()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto event = XNotificationFields::create(header, "notif", "removed");
+ event->getCommonHeader();
+ event->setNewState("xx");
+ event->setChangeType("xx");
+ event->setChangeContact("xx");
+ event->setChangeIdentifier("xx");
+ event->setAdditionalFields({ { "xxx","123" },{ "yyy","456" } });
+ event->setOldState("xx");
+ event->setStateInterface("xx");
+ XNamedHashMap nhm("xx", { { "xxx","123" },{ "yyy","456" } });
+ nhm.setName("xx");
+ nhm.setHashMap({ { "xxx","123" },{ "yyy","456" } });
+ event->setArrayOfNamedHashMap({nhm});
+
+ return event;
+}
+
+shared_ptr<XSerialable> buildOther()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto event = XOtherFields::create(header);
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+ XArrayOfNamedHashMap arr{ { "name1", hm },{ "name2", hm } };
+
+ event->setHashMap(hm);
+ event->setArrayOfNamedHashMap(arr);
+
+ {
+ XArrayOfJsonObject objs;
+
+ XArrayOfXJsonObjectInstance ins;
+ XArrayOfXJsonObjectInstance ins2;
+
+ XJsonObject obj2("obj2", ins2);
+
+ XJsonObjectInstance ins1;
+ ins1.setJsonObject(obj2);
+ ins1.setObjectInstance(R"({"aa":"bb"})");
+ ins1.setObjectInstanceEpochMicrosec(111);
+ XArrayOfXKey keys{ { "k1" } };
+ XKey k2("k2");
+ k2.setKeyName("keyname");
+ k2.setKeyOrder(11);
+ k2.setKeyValue("value");
+ keys.push_back(k2);
+ ins1.setObjectKeys(keys);
+
+ ins.push_back(ins1);
+
+ XJsonObject obj("obj1", ins);
+ objs.push_back(obj);
+
+ event->setJsonObjects(objs);
+ }
+ event->getCommonHeader();
+ return event;
+}
+
+shared_ptr<XSerialable> buildPnfRegistration()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto event = XPnfRegistrationFields::create(header);
+ event->setMacAddress("xx");
+ event->setUnitFamily("xx");
+ event->setSerialNumber("xx");
+ event->setUnitType("xx");
+ event->setManufactureDate("xx");
+ event->setSoftwareVersion("xx");
+ event->setModelNumber("xx");
+ event->setLastServiceDate("xx");
+ event->setOamV6IpAddress("xx");
+ event->setAdditionalFields({ { "xxx","123" },{ "yyy","456" } });
+ event->setVendorName("xx");
+ event->setOamV4IpAddress("xx");
+
+ event->getCommonHeader();
+ return event;
+}
+
+shared_ptr<XSerialable> buildStateChange()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto event = XStateChangeFields::create(header,
+ XEnumStateChangeFieldsStateInService,
+ XEnumStateChangeFieldsStateOutOfService,
+ "interface"
+ );
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+ event->setAdditionalFields(hm);
+ event->setNewState(XEnumStateChangeFieldsStateMaintenance);
+ event->setOldState(XEnumStateChangeFieldsStateMaintenance);
+ event->setStateInterface("xx");
+ event->getCommonHeader();
+ return event;
+}
+
+shared_ptr<XSerialable> buildSyslog()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ auto event = XSyslogFields::create(header,
+ XEnumSyslogFieldsEventSourceTypePort,
+ "tag",
+ "message"
+ );
+ event->setSyslogSev(XEnumSyslogFieldsSyslogSevInfo);
+ event->setSyslogProcId(1);
+ event->setSyslogFacility(1);
+ event->setSyslogPri(1);
+ event->setSyslogMsgHost("xx");
+ event->setSyslogSData("xx");
+ event->setSyslogMsg("xx");
+ event->setSyslogProc("xx");
+ event->setEventSourceHost("xx");
+ event->setSyslogTs("xx");
+ event->setSyslogTag("xx");
+ event->setSyslogVer(1);
+ event->setAdditionalFields({ { "xxx","123" },{ "yyy","456" } });
+ event->setSyslogSdId("xx");
+ event->setEventSourceType(XEnumSyslogFieldsEventSourceTypeCard);
+
+ event->getCommonHeader();
+ return event;
+}
+
+shared_ptr<XSerialable> buildThresholdCrossingAlert()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+ XArrayOfXCounter counters{ { XEnumCounterCriticalityMAJ, hm, "thres1" } };
+ counters[0].setCriticality(XEnumCounterCriticalityCRIT);
+ counters[0].setThresholdCrossed("xx");
+ counters[0].setHashMap(hm);
+
+ auto event = XThresholdCrossingAlertFields::create(header,
+ XEnumThresholdCrossingAlertFieldsAlertActionSET,
+ XEnumThresholdCrossingAlertFieldsAlertTypeINTERFACE_ANOMALY,
+ XEnumThresholdCrossingAlertFieldsEventSeverityMINOR,
+ "description",
+ "collect time",
+ "start time",
+ counters
+ );
+
+ event->getCommonHeader();
+ event->setAlertDescription("xx");
+ event->setInterfaceName("xx");
+ event->setCollectionTimestamp("xx");
+ event->setPossibleRootCause("xx");
+ event->setAlertValue("xx");
+ event->setDataCollector("xx");
+ event->setNetworkService("xx");
+ event->setElementType("xx");
+ event->setAdditionalFields({ { "xxx","123" },{ "yyy","456" } });
+ event->setEventStartTimestamp("xx");
+ event->setAlertType(XEnumThresholdCrossingAlertFieldsAlertTypeCARD_ANOMALY);
+ event->setEventSeverity(XEnumThresholdCrossingAlertFieldsEventSeverityCRITICAL);
+ event->setAssociatedAlertIdList({"xx","yy"});
+
+ XCounter x(XEnumCounterCriticalityCRIT, {{"xx","123"}}, "xx");
+ event->setAdditionalParameters({x});
+ event->setAlertAction(XEnumThresholdCrossingAlertFieldsAlertActionCONT);
+
+ return event;
+}
+
+shared_ptr<XSerialable> buildXVoiceQuality()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ XVendorNfNameFields vendor("testVendor");
+
+ auto event = XVoiceQualityFields::create(header,
+ "calleeSideCodec",
+ "callerSideCodec",
+ "correlator",
+ "midCallRtcp",
+ vendor
+ );
+
+ XEndOfCallVqmSummaries summaries("summeries", XEnumEndOfCallVqmSummariesEndpointDescriptionCallee);
+ summaries.setLocalRtpPacketsDiscarded(1);
+ summaries.setLocalMaxJitter(1);
+ summaries.setRoundTripDelay(1);
+ summaries.setLocalRtpOctetsSent(1);
+ summaries.setLocalAverageJitterBufferDelay(1);
+ summaries.setLocalRtpPacketsLost(1);
+ summaries.setEndpointRtpOctetsReceived(1);
+ summaries.setRFactor(1);
+ summaries.setLocalRtpPacketsReceived(1);
+ summaries.setEndpointRtpPacketsLost(1);
+ summaries.setLocalAverageJitter(1);
+ summaries.setMosCqe(1);
+ summaries.setOneWayDelay(1);
+ summaries.setEndpointRtpOctetsLost(1);
+ summaries.setPacketLossPercent(1);
+ summaries.setEndpointRtpOctetsDiscarded(1);
+ summaries.setLocalRtpPacketsSent(1);
+ summaries.setEndpointAverageJitter(1);
+ summaries.setEndpointRtpOctetsSent(1);
+ summaries.setEndpointMaxJitter(1);
+ summaries.setEndpointRtpPacketsReceived(1);
+ summaries.setEndpointRtpPacketsSent(1);
+ summaries.setLocalMaxJitterBufferDelay(1);
+ summaries.setLocalRtpOctetsLost(1);
+ summaries.setLocalRtpOctetsReceived(1);
+ summaries.setEndpointRtpPacketsDiscarded(1);
+ summaries.setLocalRtpOctetsDiscarded(1);
+ summaries.setAdjacencyName("xxxx");
+ summaries.setEndpointDescription(XEnumEndOfCallVqmSummariesEndpointDescriptionCallee);
+
+ event->setEndOfCallVqmSummaries(summaries);
+ event->setMidCallRtcp("xx");
+ event->setAdditionalInformation({ { "xxx","123" },{ "yyy","456" } });
+ event->setCalleeSideCodec("xx");
+ event->setPhoneNumber("xx");
+ event->setCallerSideCodec("xx");
+ event->setCorrelator("xx");
+ event->setVendorNfNameFields(vendor);
+ event->getCommonHeader();
+
+ return event;
+}
+
+shared_ptr<XSerialable> buildBatch()
+{
+ auto batch = XBatch::create();
+ batch->addEvent(buildFault());
+ batch->addEvent(buildSyslog());
+ return batch;
+}
+
+shared_ptr<XSerialable> buildMobileFlow()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ XHashMap hm{ { "xxx","123" },{ "yyy","456" } };
+
+ XGtpPerFlowMetrics m(1, 1, 1, 1, 1, 1, 1, 1, 1, "xx", "yy", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
+
+ m.setNumLostPackets(1);
+ m.setNumPacketsReceivedExclRetrans(1);
+ m.setFlowDeactivationMicrosec(1);
+ m.setAvgTransmitThroughput(1);
+ m.setLargePacketRtt(1);
+ m.setNumHttpErrors(1);
+ m.setNumTimeouts(1);
+ m.setFlowActivationEpoch(1);
+ m.setNumPacketErrors(1);
+ m.setAvgPacketDelayVariation(1);
+ m.setAvgBitErrorRate(1);
+ m.setFlowActivationMicrosec(1);
+ m.setAvgPacketLatency(1);
+ m.setNumBytesTransmitted(1);
+ m.setNumBitErrors(1);
+ m.setMaxReceiveBitRate(1);
+ m.setMaxTransmitBitRate(1);
+ m.setAvgReceiveThroughput(1);
+ m.setNumRetries(1);
+ m.setDurConnectionFailedStatus(1);
+ m.setNumL7BytesTransmitted(1);
+ m.setTimeToFirstByte(1);
+ m.setNumBytesReceived(1);
+ m.setFlowDeactivationEpoch(1);
+ m.setNumGtpEchoFailures(1);
+ m.setNumPacketsReceivedInclRetrans(1);
+ m.setNumGtpTunnelErrors(1);
+ m.setRoundTripTime(1);
+ m.setNumActivationFailures(1);
+ m.setMaxPacketDelayVariation(1);
+ m.setNumTunneledL7BytesReceived(1);
+ m.setNumL7BytesReceived(1);
+ m.setNumDroppedPackets(1);
+ m.setNumPacketsTransmittedInclRetrans(1);
+ m.setNumOutOfOrderPackets(1);
+ m.setLargePacketThreshold(1);
+ m.setDurTunnelFailedStatus(1);
+ m.setFlowActivationTime("xx");
+ m.setFlowDeactivationTime("xx");
+ m.setFlowActivatedBy("xx");
+ m.setIpTosCountList(hm);
+ m.setMobileQciCosCountList(hm);
+ m.setIpTosList({"xxx","yyy"});
+ m.setMobileQciCosList({"xxx","yyy"});
+ m.setGtpConnectionStatus("xx");
+ m.setTcpFlagList({"xxx","yyy"});
+ m.setFlowStatus("xx");
+ m.setGtpTunnelStatus("xx");
+ m.setTcpFlagCountList(hm);
+ m.setFlowDeactivatedBy("xx");
+
+ auto event = XMobileFlowFields::create(header,"xx", m, "xx", "xx", "xx",1,"xx",1);
+ event->setRac("xx");
+ event->setSac("xx");
+ event->setSamplingAlgorithm(1);
+ event->setIpVersion("xx");
+ event->setTac("xx");
+ event->setMnc("xx");
+ event->setTunnelId("xx");
+ event->setAppProtocolVersion("xx");
+ event->setGtpVersion("xx");
+ event->setConnectionType("xx");
+ event->setHttpHeader("xx");
+ event->setImsi("xx");
+ event->setApplicationType("xx");
+ event->setMsisdn("xx");
+ event->setMcc("xx");
+ event->setFlowDirection("xx");
+ event->setLac("xx");
+ event->setOtherEndpointPort(1);
+ event->setVlanId("xx");
+ event->setImei("xx");
+ event->setGtpProtocolType("xx");
+ event->setEcgi("xx");
+ event->setCid("xx");
+ event->setReportingEndpointPort(1);
+ event->setRadioAccessTechnology("xx");
+ event->setAppProtocolType("xx");
+ event->setOtherEndpointIpAddress("xx");
+ event->setIpProtocolType("xx");
+ event->setOtherFunctionalRole("xx");
+ event->setReportingEndpointIpAddr("xx");
+
+ event->setGtpPerFlowMetrics(m);
+ event->setAdditionalFields({ { "xxx","123" },{ "yyy","456" } });
+ event->getCommonHeader();
+
+ return event;
+}
+
+shared_ptr<XSerialable> buildSipSignaling()
+{
+ auto header = XCommonEventHeader::create(
+ "EventName",
+ "EventId",
+ "SourceName",
+ "ReportName",
+ XEnumCommonEventHeaderPriorityNormal,
+ 111
+ );
+
+ XVendorNfNameFields vendor("xx");
+ vendor.setVendorName("xx");
+ vendor.setNfName("xx");
+ vendor.setNfModuleName("xx");
+ auto event = XSipSignalingFields::create(header,"x","x","x","x","x", vendor);
+ event->getCommonHeader();
+
+ event->setRemotePort("xx");
+ event->setSummarySip("xx");
+ event->setLocalPort("xx");
+ event->setAdditionalInformation({ { "xxx","123" },{ "yyy","456" } });
+ event->setLocalIpAddress("xx");
+ event->setCompressedSip("xx");
+ event->setCorrelator("xx");
+ event->setRemoteIpAddress("xx");
+ event->setVendorNfNameFields(vendor);
+
+ return event;
+}
diff --git a/veslibrary/ves_cpplibrary/src/test/XEventSamples.h b/veslibrary/ves_cpplibrary/src/test/XEventSamples.h new file mode 100755 index 0000000..b33ad01 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/test/XEventSamples.h @@ -0,0 +1,34 @@ +#pragma once
+
+#include "XFaultFields.h"
+#include "XHeartbeatFields.h"
+#include "XMeasurementFields.h"
+#include "XNotificationFields.h"
+#include "XOtherFields.h"
+#include "XPnfRegistrationFields.h"
+#include "XStateChangeFields.h"
+#include "XSyslogFields.h"
+#include "XThresholdCrossingAlertFields.h"
+#include "XVoiceQualityFields.h"
+#include "XBatch.h"
+#include "XMobileFlowFields.h"
+#include "XSipSignalingFields.h"
+
+using namespace std;
+using namespace vagt;
+using namespace vagt::encode;
+
+shared_ptr<XSerialable> buildFault();
+shared_ptr<XSerialable> buildHeartbeat();
+shared_ptr<XSerialable> buildMeasurement();
+shared_ptr<XSerialable> buildNotification();
+shared_ptr<XSerialable> buildOther();
+shared_ptr<XSerialable> buildPnfRegistration();
+shared_ptr<XSerialable> buildStateChange();
+shared_ptr<XSerialable> buildSyslog();
+shared_ptr<XSerialable> buildThresholdCrossingAlert();
+shared_ptr<XSerialable> buildXVoiceQuality();
+shared_ptr<XSerialable> buildBatch();
+shared_ptr<XSerialable> buildMobileFlow();
+shared_ptr<XSerialable> buildSipSignaling();
+
diff --git a/veslibrary/ves_cpplibrary/src/test/XMain.cpp b/veslibrary/ves_cpplibrary/src/test/XMain.cpp new file mode 100755 index 0000000..26d4069 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/test/XMain.cpp @@ -0,0 +1,49 @@ +#include "XEventSamples.h"
+#include "XTransportSamples.h"
+#include "XLog.h"
+#include <iostream>
+#include <cstdlib>
+#include <vector>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ // common
+ vagt::log::init("/dev/null");
+ vagt::log::setLevel(log::XLogOff);
+
+ // encode
+ vector<shared_ptr<XSerialable>> events = {
+ buildFault(),
+ buildHeartbeat(),
+ buildMeasurement(),
+ buildNotification(),
+ buildOther(),
+ buildPnfRegistration(),
+ buildStateChange(),
+ buildSyslog(),
+ buildThresholdCrossingAlert(),
+ buildXVoiceQuality(),
+ buildBatch(),
+ buildMobileFlow(),
+ buildSipSignaling()
+ };
+
+ for (auto event : events)
+ {
+ event->toString();
+ }
+
+ //transport
+
+ testLibcurlTransport();
+ testRetryTransport();
+ testSwitchableTransport();
+ testMemBufferedTransport();
+ testDiskBufferedTransport();
+ testRpcClientTransport();
+ testRpcServerTransport();
+
+ return 0;
+}
diff --git a/veslibrary/ves_cpplibrary/src/test/XTransportSamples.cpp b/veslibrary/ves_cpplibrary/src/test/XTransportSamples.cpp new file mode 100755 index 0000000..6c8be40 --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/test/XTransportSamples.cpp @@ -0,0 +1,201 @@ +#include "XTransportSamples.h"
+#include <thread>
+
+using namespace std;
+using namespace vagt;
+using namespace vagt::encode;
+using namespace vagt::queue;
+using namespace vagt::transport;
+using namespace std::chrono;
+
+void testLibcurlTransport()
+{
+ auto event = buildFault();
+
+ XTransportOption opt;
+ opt.url_ = "http://127.0.0.1:30000";
+
+ auto transport = XTransport::SynchronizedTransport(XTransport::LibCurlTransport(opt));
+
+ transport->start();
+
+ transport->post(event->toString());
+
+ transport->stop();
+}
+
+void testRetryTransport()
+{
+ auto event = buildFault();
+
+ XTransportOption opt;
+ opt.url_ = "http://127.0.0.1:30000";
+
+ auto transport = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+
+ transport->start();
+
+ transport->post(event->toString());
+
+ transport->stop();
+}
+
+void testSwitchableTransport()
+{
+ auto event = buildFault();
+
+ vector<shared_ptr<XTransport>> transports;
+
+ XTransportOption opt;
+ opt.url_ = "http://127.0.0.1:30000";
+ auto transport1 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport1);
+
+ opt.url_ = "http://127.0.0.1:30001";
+ auto transport2 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport2);
+
+ auto transport = XTransport::SwitchableTransport(transports);
+
+ transport->start();
+
+ transport->post(event->toString());
+
+ transport->stop();
+}
+
+void testMemBufferedTransport()
+{
+ auto event = buildFault();
+
+ vector<shared_ptr<XTransport>> transports;
+
+ XTransportOption opt;
+ opt.url_ = "http://127.0.0.1:30000";
+ auto transport1 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport1);
+
+ opt.url_ = "http://127.0.0.1:30001";
+ auto transport2 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport2);
+
+ auto que = XQueue::create(1000);
+ auto transport = XTransport::BufferedTransport(XTransport::SwitchableTransport(transports),
+ que);
+
+ transport->start();
+
+ for (int i=0; i<1200; i++)
+ {
+ transport->post(event->toString());
+ }
+
+ this_thread::sleep_for(seconds(10));
+
+ transport->stop();
+}
+
+void testDiskBufferedTransport()
+{
+ auto event = buildFault();
+
+ vector<shared_ptr<XTransport>> transports;
+
+ XTransportOption opt;
+ opt.url_ = "http://127.0.0.1:30000";
+ auto transport1 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport1);
+
+ opt.url_ = "http://127.0.0.1:30001";
+ auto transport2 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport2);
+
+ auto que = XQueue::create("/tmp");
+ auto transport = XTransport::BufferedTransport(XTransport::SwitchableTransport(transports),
+ que);
+
+ transport->start();
+
+ for (int i=0; i<10; i++)
+ {
+ transport->post(event->toString());
+ }
+
+ this_thread::sleep_for(seconds(10));
+
+ transport->stop();
+}
+
+void testRpcClientTransport()
+{
+ auto event = buildFault();
+
+ XTransportOption rpcOpt;
+ rpcOpt.host_ = "127.0.0.1";
+ rpcOpt.port_ = 5678;
+
+ auto retryTransport = XTransport::RetryTransport(XTransport::RpcClientTransport(rpcOpt),
+ seconds(1),
+ 3);
+ auto transport = XTransport::BufferedTransport(retryTransport,
+ XQueue::create(1000)
+ );
+
+ transport->start();
+
+ for (int i=0; i<100; i++)
+ {
+ transport->post(event->toString());
+ }
+
+ this_thread::sleep_for(seconds(10));
+
+ transport->stop();
+}
+
+void testRpcServerTransport()
+{
+ vector<shared_ptr<XTransport>> transports;
+
+ XTransportOption opt;
+ opt.url_ = "http://127.0.0.1:30000";
+ auto transport1 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport1);
+
+ opt.url_ = "http://127.0.0.1:30001";
+ auto transport2 = XTransport::RetryTransport(XTransport::LibCurlTransport(opt),
+ seconds(1),
+ 3);
+ transports.push_back(transport2);
+
+ auto que = XQueue::create("/tmp");
+ auto bufferedTransport = XTransport::BufferedTransport(XTransport::SwitchableTransport(transports),
+ que);
+
+ XTransportOption rpcOpt;
+ rpcOpt.port_ = 5678;
+
+ auto transport = XTransport::RpcServerTransport(bufferedTransport, rpcOpt);
+
+ transport->start();
+
+ this_thread::sleep_for(seconds(10));
+
+ transport->stop();
+}
diff --git a/veslibrary/ves_cpplibrary/src/test/XTransportSamples.h b/veslibrary/ves_cpplibrary/src/test/XTransportSamples.h new file mode 100755 index 0000000..0ed261f --- /dev/null +++ b/veslibrary/ves_cpplibrary/src/test/XTransportSamples.h @@ -0,0 +1,12 @@ +#pragma once
+
+#include "XTransport.h"
+#include "XEventSamples.h"
+
+void testLibcurlTransport();
+void testRetryTransport();
+void testSwitchableTransport();
+void testMemBufferedTransport();
+void testDiskBufferedTransport();
+void testRpcClientTransport();
+void testRpcServerTransport();
|