Upgrading dependency to Thrift 0.12.0
This commit is contained in:
parent
3e4590dcc0
commit
356978cb42
1302 changed files with 101701 additions and 26784 deletions
10
vendor/git.apache.org/thrift.git/lib/cpp/test/AllProtocolTests.tcc
generated
vendored
10
vendor/git.apache.org/thrift.git/lib/cpp/test/AllProtocolTests.tcc
generated
vendored
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include "GenericHelpers.h"
|
||||
|
||||
using boost::shared_ptr;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using namespace apache::thrift;
|
||||
using namespace apache::thrift::protocol;
|
||||
using namespace apache::thrift::transport;
|
||||
|
@ -190,14 +190,14 @@ void testProtocol(const char* protoname) {
|
|||
|
||||
testNaked<TProto, int64_t>(0);
|
||||
for (int64_t i = 0; i < 62; i++) {
|
||||
testNaked<TProto, int64_t>(1L << i);
|
||||
testNaked<TProto, int64_t>(-(1L << i));
|
||||
testNaked<TProto, int64_t>(1LL << i);
|
||||
testNaked<TProto, int64_t>(-(1LL << i));
|
||||
}
|
||||
|
||||
testField<TProto, T_I64, int64_t>(0);
|
||||
for (int i = 0; i < 62; i++) {
|
||||
testField<TProto, T_I64, int64_t>(1L << i);
|
||||
testField<TProto, T_I64, int64_t>(-(1L << i));
|
||||
testField<TProto, T_I64, int64_t>(1LL << i);
|
||||
testField<TProto, T_I64, int64_t>(-(1LL << i));
|
||||
}
|
||||
|
||||
testNaked<TProto, double>(123.456);
|
||||
|
|
68
vendor/git.apache.org/thrift.git/lib/cpp/test/AnnotationTest.cpp
generated
vendored
Normal file
68
vendor/git.apache.org/thrift.git/lib/cpp/test/AnnotationTest.cpp
generated
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#define BOOST_TEST_MODULE AnnotationTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "gen-cpp/AnnotationTest_types.h"
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
// Normally thrift generates ostream operators, however
|
||||
// with the annotation "cpp.customostream" one can tell the
|
||||
// compiler they are going to provide their own, and not
|
||||
// emit operator << or printTo().
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ostr_custom& osc)
|
||||
{
|
||||
os << "{ bar = " << osc.bar << "; }";
|
||||
return os;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_cpp_compiler_generated_ostream_operator)
|
||||
{
|
||||
ostr_default def;
|
||||
def.__set_bar(10);
|
||||
|
||||
std::stringstream ssd;
|
||||
ssd << def;
|
||||
BOOST_CHECK_EQUAL(ssd.str(), "ostr_default(bar=10)");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_cpp_customostream_uses_consuming_application_definition)
|
||||
{
|
||||
ostr_custom cus;
|
||||
cus.__set_bar(10);
|
||||
|
||||
std::stringstream csd;
|
||||
csd << cus;
|
||||
BOOST_CHECK_EQUAL(csd.str(), "{ bar = 10; }");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled; see THRIFT-1567 - not sure what it is supposed to do
|
||||
BOOST_AUTO_TEST_CASE(test_cpp_type) {
|
||||
// Check that the "cpp.type" annotation changes "struct foo" to "DenseFoo"
|
||||
// This won't compile if the annotation is mishandled
|
||||
DenseFoo foo;
|
||||
foo.__set_bar(5);
|
||||
}
|
||||
*/
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
4
vendor/git.apache.org/thrift.git/lib/cpp/test/Base64Test.cpp
generated
vendored
4
vendor/git.apache.org/thrift.git/lib/cpp/test/Base64Test.cpp
generated
vendored
|
@ -37,6 +37,10 @@ void setupTestData(int i, uint8_t* data, int& len) {
|
|||
}
|
||||
|
||||
void checkEncoding(uint8_t* data, int len) {
|
||||
#ifdef NDEBUG
|
||||
((void)data);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
BOOST_ASSERT(isalnum(data[i]) || data[i] == '/' || data[i] == '+');
|
||||
}
|
||||
|
|
21
vendor/git.apache.org/thrift.git/lib/cpp/test/Benchmark.cpp
generated
vendored
21
vendor/git.apache.org/thrift.git/lib/cpp/test/Benchmark.cpp
generated
vendored
|
@ -23,8 +23,9 @@
|
|||
#include <iostream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include "thrift/transport/TBufferTransports.h"
|
||||
#include "thrift/protocol/TBinaryProtocol.h"
|
||||
#include "thrift/stdcxx.h"
|
||||
#include "thrift/transport/TBufferTransports.h"
|
||||
#include "gen-cpp/DebugProtoTest_types.h"
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
|
@ -48,11 +49,11 @@ public:
|
|||
};
|
||||
|
||||
int main() {
|
||||
using namespace std;
|
||||
using namespace thrift::test::debug;
|
||||
using namespace apache::thrift::transport;
|
||||
using namespace apache::thrift::protocol;
|
||||
using namespace boost;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
OneOfEach ooe;
|
||||
ooe.im_true = true;
|
||||
|
@ -67,7 +68,7 @@ int main() {
|
|||
ooe.base64 = "\1\2\3\255";
|
||||
|
||||
int num = 100000;
|
||||
boost::shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer(num*1000));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer(num*1000));
|
||||
|
||||
uint8_t* data = NULL;
|
||||
uint32_t datasize = 0;
|
||||
|
@ -88,7 +89,7 @@ int main() {
|
|||
buf->getBuffer(&data, &datasize);
|
||||
|
||||
{
|
||||
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
TBinaryProtocolT<TMemoryBuffer> prot(buf2);
|
||||
OneOfEach ooe2;
|
||||
double elapsed = 0.0;
|
||||
|
@ -116,7 +117,7 @@ int main() {
|
|||
|
||||
{
|
||||
OneOfEach ooe2;
|
||||
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
TBinaryProtocolT<TMemoryBuffer, TNetworkLittleEndian> prot(buf2);
|
||||
double elapsed = 0.0;
|
||||
Timer timer;
|
||||
|
@ -142,7 +143,7 @@ int main() {
|
|||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
TBinaryProtocolT<TMemoryBuffer> prot(buf2);
|
||||
OneOfEach ooe2;
|
||||
double elapsed = 0.0;
|
||||
|
@ -181,7 +182,7 @@ int main() {
|
|||
buf->getBuffer(&data, &datasize);
|
||||
|
||||
{
|
||||
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
TBinaryProtocolT<TMemoryBuffer> prot(buf2);
|
||||
ListDoublePerf listDoublePerf2;
|
||||
double elapsed = 0.0;
|
||||
|
@ -205,7 +206,7 @@ int main() {
|
|||
|
||||
{
|
||||
ListDoublePerf listDoublePerf2;
|
||||
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
TBinaryProtocolT<TMemoryBuffer, TNetworkLittleEndian> prot(buf2);
|
||||
double elapsed = 0.0;
|
||||
Timer timer;
|
||||
|
@ -227,7 +228,7 @@ int main() {
|
|||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
|
||||
TBinaryProtocolT<TMemoryBuffer> prot(buf2);
|
||||
ListDoublePerf listDoublePerf2;
|
||||
double elapsed = 0.0;
|
||||
|
|
60
vendor/git.apache.org/thrift.git/lib/cpp/test/CMakeLists.txt
generated
vendored
60
vendor/git.apache.org/thrift.git/lib/cpp/test/CMakeLists.txt
generated
vendored
|
@ -19,11 +19,17 @@
|
|||
|
||||
include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
|
||||
|
||||
#Make sure gen-cpp files can be included
|
||||
if (WITH_DYN_LINK_TEST)
|
||||
add_definitions( -DBOOST_TEST_DYN_LINK )
|
||||
endif()
|
||||
|
||||
# Make sure gen-cpp files can be included
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# Create the thrift C++ test library
|
||||
set(testgencpp_SOURCES
|
||||
gen-cpp/AnnotationTest_types.cpp
|
||||
gen-cpp/AnnotationTest_types.h
|
||||
gen-cpp/DebugProtoTest_types.cpp
|
||||
gen-cpp/DebugProtoTest_types.h
|
||||
gen-cpp/EnumTest_types.cpp
|
||||
|
@ -34,6 +40,10 @@ set(testgencpp_SOURCES
|
|||
gen-cpp/Recursive_types.h
|
||||
gen-cpp/ThriftTest_types.cpp
|
||||
gen-cpp/ThriftTest_types.h
|
||||
gen-cpp/OneWayTest_types.cpp
|
||||
gen-cpp/OneWayTest_types.h
|
||||
gen-cpp/OneWayService.cpp
|
||||
gen-cpp/OneWayService.h
|
||||
gen-cpp/TypedefTest_types.cpp
|
||||
gen-cpp/TypedefTest_types.h
|
||||
ThriftTest_extras.cpp
|
||||
|
@ -54,7 +64,6 @@ set(testgencpp_cob_SOURCES
|
|||
)
|
||||
add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
|
||||
|
||||
|
||||
add_executable(Benchmark Benchmark.cpp)
|
||||
target_link_libraries(Benchmark testgencpp)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(Benchmark thrift)
|
||||
|
@ -63,6 +72,7 @@ target_link_libraries(Benchmark testgencpp)
|
|||
|
||||
set(UnitTest_SOURCES
|
||||
UnitTestMain.cpp
|
||||
OneWayHTTPTest.cpp
|
||||
TMemoryBufferTest.cpp
|
||||
TBufferBaseTest.cpp
|
||||
Base64Test.cpp
|
||||
|
@ -72,8 +82,9 @@ set(UnitTest_SOURCES
|
|||
TServerTransportTest.cpp
|
||||
)
|
||||
|
||||
if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS AND NOT MSVC)
|
||||
list(APPEND UnitTest_SOURCES RWMutexStarveTest.cpp)
|
||||
if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS AND NOT MSVC AND NOT MINGW)
|
||||
list(APPEND UnitTest_SOURCES concurrency/MutexTest.cpp)
|
||||
list(APPEND UnitTest_SOURCES concurrency/RWMutexStarveTest.cpp)
|
||||
endif()
|
||||
|
||||
add_executable(UnitTests ${UnitTest_SOURCES})
|
||||
|
@ -105,7 +116,7 @@ LINK_AGAINST_THRIFT_LIBRARY(TInterruptTest thrift)
|
|||
if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT MINGW)
|
||||
target_link_libraries(TInterruptTest -lrt)
|
||||
endif ()
|
||||
add_test(NAME TInterruptTest COMMAND TInterruptTest "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys")
|
||||
add_test(NAME TInterruptTest COMMAND TInterruptTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys")
|
||||
|
||||
add_executable(TServerIntegrationTest TServerIntegrationTest.cpp)
|
||||
target_link_libraries(TServerIntegrationTest
|
||||
|
@ -141,6 +152,13 @@ LINK_AGAINST_THRIFT_LIBRARY(ZlibTest thriftz)
|
|||
add_test(NAME ZlibTest COMMAND ZlibTest)
|
||||
endif(WITH_ZLIB)
|
||||
|
||||
add_executable(AnnotationTest AnnotationTest.cpp)
|
||||
target_link_libraries(AnnotationTest
|
||||
testgencpp
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(AnnotationTest thrift)
|
||||
add_test(NAME AnnotationTest COMMAND AnnotationTest)
|
||||
|
||||
add_executable(EnumTest EnumTest.cpp)
|
||||
target_link_libraries(EnumTest
|
||||
|
@ -283,7 +301,21 @@ target_link_libraries(TNonblockingServerTest
|
|||
LINK_AGAINST_THRIFT_LIBRARY(TNonblockingServerTest thrift)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TNonblockingServerTest thriftnb)
|
||||
add_test(NAME TNonblockingServerTest COMMAND TNonblockingServerTest)
|
||||
endif()
|
||||
|
||||
if(OPENSSL_FOUND AND WITH_OPENSSL)
|
||||
set(TNonblockingSSLServerTest_SOURCES TNonblockingSSLServerTest.cpp)
|
||||
add_executable(TNonblockingSSLServerTest ${TNonblockingSSLServerTest_SOURCES})
|
||||
include_directories(${LIBEVENT_INCLUDE_DIRS})
|
||||
target_link_libraries(TNonblockingSSLServerTest
|
||||
testgencpp_cob
|
||||
${LIBEVENT_LIBRARIES}
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TNonblockingSSLServerTest thrift)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TNonblockingSSLServerTest thriftnb)
|
||||
add_test(NAME TNonblockingSSLServerTest COMMAND TNonblockingSSLServerTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys")
|
||||
endif(OPENSSL_FOUND AND WITH_OPENSSL)
|
||||
endif(WITH_LIBEVENT)
|
||||
|
||||
if(OPENSSL_FOUND AND WITH_OPENSSL)
|
||||
add_executable(OpenSSLManualInitTest OpenSSLManualInitTest.cpp)
|
||||
|
@ -303,7 +335,7 @@ LINK_AGAINST_THRIFT_LIBRARY(SecurityTest thrift)
|
|||
if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT MINGW)
|
||||
target_link_libraries(SecurityTest -lrt)
|
||||
endif ()
|
||||
add_test(NAME SecurityTest COMMAND SecurityTest "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys")
|
||||
add_test(NAME SecurityTest COMMAND SecurityTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys")
|
||||
|
||||
endif()
|
||||
|
||||
|
@ -327,8 +359,16 @@ endif()
|
|||
# Common thrift code generation rules
|
||||
#
|
||||
|
||||
add_custom_command(OUTPUT gen-cpp/AnnotationTest_constants.cpp
|
||||
gen-cpp/AnnotationTest_constants.h
|
||||
gen-cpp/AnnotationTest_types.cpp
|
||||
gen-cpp/AnnotationTest_types.h
|
||||
gen-cpp/foo_service.cpp
|
||||
gen-cpp/foo_service.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/AnnotationTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h
|
||||
add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
|
||||
)
|
||||
|
||||
|
@ -356,6 +396,10 @@ add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants
|
|||
COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT gen-cpp/OneWayService.cpp gen-cpp/OneWayTest_constants.cpp gen-cpp/OneWayTest_types.h gen-cpp/OneWayService.h gen-cpp/OneWayTest_constants.h gen-cpp/OneWayTest_types.cpp
|
||||
COMMAND ${THRIFT_COMPILER} --gen cpp ${CMAKE_CURRENT_SOURCE_DIR}/OneWayTest.thrift
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cpp/ParentService.h gen-cpp/proc_types.cpp gen-cpp/proc_types.h
|
||||
COMMAND ${THRIFT_COMPILER} --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift
|
||||
)
|
||||
|
|
7
vendor/git.apache.org/thrift.git/lib/cpp/test/DebugProtoTest.cpp
generated
vendored
7
vendor/git.apache.org/thrift.git/lib/cpp/test/DebugProtoTest.cpp
generated
vendored
|
@ -21,13 +21,14 @@
|
|||
#include <cmath>
|
||||
#include "gen-cpp/DebugProtoTest_types.h"
|
||||
#include <thrift/protocol/TDebugProtocol.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
#define BOOST_TEST_MODULE DebugProtoTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace thrift::test::debug;
|
||||
|
||||
static std::auto_ptr<OneOfEach> ooe;
|
||||
static ::apache::thrift::stdcxx::shared_ptr<OneOfEach> ooe;
|
||||
|
||||
void testCaseSetup_1() {
|
||||
ooe.reset(new OneOfEach);
|
||||
|
@ -80,7 +81,7 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_1) {
|
|||
"Expected:\n" << expected_result << "\nGotten:\n" << result);
|
||||
}
|
||||
|
||||
static std::auto_ptr<Nesting> n;
|
||||
static ::apache::thrift::stdcxx::shared_ptr<Nesting> n;
|
||||
|
||||
void testCaseSetup_2() {
|
||||
testCaseSetup_1();
|
||||
|
@ -148,7 +149,7 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_2) {
|
|||
"Expected:\n" << expected_result << "\nGotten:\n" << result);
|
||||
}
|
||||
|
||||
static std::auto_ptr<HolyMoley> hm;
|
||||
static ::apache::thrift::stdcxx::shared_ptr<HolyMoley> hm;
|
||||
|
||||
void testCaseSetup_3() {
|
||||
testCaseSetup_2();
|
||||
|
|
35
vendor/git.apache.org/thrift.git/lib/cpp/test/EnumTest.cpp
generated
vendored
35
vendor/git.apache.org/thrift.git/lib/cpp/test/EnumTest.cpp
generated
vendored
|
@ -20,9 +20,15 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include "gen-cpp/EnumTest_types.h"
|
||||
|
||||
std::ostream& operator <<(std::ostream& os, const MyEnumWithCustomOstream::type& val)
|
||||
{
|
||||
os << "{" << (int)val << ":CUSTOM!" << "}";
|
||||
return os;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(EnumTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_enum) {
|
||||
BOOST_AUTO_TEST_CASE(test_enum_value) {
|
||||
// Check that all the enum values match what we expect
|
||||
BOOST_CHECK_EQUAL(MyEnum1::ME1_0, 0);
|
||||
BOOST_CHECK_EQUAL(MyEnum1::ME1_1, 1);
|
||||
|
@ -47,9 +53,34 @@ BOOST_AUTO_TEST_CASE(test_enum) {
|
|||
BOOST_CHECK_EQUAL(MyEnum4::ME4_A, 0x7ffffffd);
|
||||
BOOST_CHECK_EQUAL(MyEnum4::ME4_B, 0x7ffffffe);
|
||||
BOOST_CHECK_EQUAL(MyEnum4::ME4_C, 0x7fffffff);
|
||||
|
||||
BOOST_CHECK_EQUAL(MyEnum5::e1, 0);
|
||||
BOOST_CHECK_EQUAL(MyEnum5::e2, 42);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_enum_constant) {
|
||||
template <class _T>
|
||||
std::string EnumToString(_T e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << e;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_enum_ostream)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(EnumToString(MyEnum1::ME1_0), "ME1_0");
|
||||
BOOST_CHECK_EQUAL(EnumToString(MyEnum5::e2), "e2");
|
||||
BOOST_CHECK_EQUAL(EnumToString(MyEnum3::ME3_N1), "ME3_N1");
|
||||
BOOST_CHECK_EQUAL(EnumToString(MyEnumWithCustomOstream::CustoM2), "{2:CUSTOM!}");
|
||||
|
||||
// some invalid or unknown value
|
||||
MyEnum5::type uut = (MyEnum5::type)44;
|
||||
BOOST_CHECK_EQUAL(EnumToString(uut), "44");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_enum_constant)
|
||||
{
|
||||
MyStruct ms;
|
||||
BOOST_CHECK_EQUAL(ms.me2_2, 2);
|
||||
BOOST_CHECK_EQUAL(ms.me3_n2, -2);
|
||||
|
|
31
vendor/git.apache.org/thrift.git/lib/cpp/test/GenericHelpers.h
generated
vendored
31
vendor/git.apache.org/thrift.git/lib/cpp/test/GenericHelpers.h
generated
vendored
|
@ -20,13 +20,10 @@
|
|||
#ifndef _THRIFT_TEST_GENERICHELPERS_H_
|
||||
#define _THRIFT_TEST_GENERICHELPERS_H_ 1
|
||||
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include <thrift/protocol/TProtocol.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/Thrift.h>
|
||||
|
||||
using boost::shared_ptr;
|
||||
using namespace apache::thrift::protocol;
|
||||
|
||||
/* ClassName Helper for cleaner exceptions */
|
||||
class ClassNames {
|
||||
public:
|
||||
|
@ -66,43 +63,43 @@ class GenericIO {
|
|||
public:
|
||||
/* Write functions */
|
||||
|
||||
static uint32_t write(shared_ptr<TProtocol> proto, const int8_t& val) {
|
||||
static uint32_t write(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, const int8_t& val) {
|
||||
return proto->writeByte(val);
|
||||
}
|
||||
|
||||
static uint32_t write(shared_ptr<TProtocol> proto, const int16_t& val) {
|
||||
static uint32_t write(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, const int16_t& val) {
|
||||
return proto->writeI16(val);
|
||||
}
|
||||
|
||||
static uint32_t write(shared_ptr<TProtocol> proto, const int32_t& val) {
|
||||
static uint32_t write(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, const int32_t& val) {
|
||||
return proto->writeI32(val);
|
||||
}
|
||||
|
||||
static uint32_t write(shared_ptr<TProtocol> proto, const double& val) {
|
||||
static uint32_t write(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, const double& val) {
|
||||
return proto->writeDouble(val);
|
||||
}
|
||||
|
||||
static uint32_t write(shared_ptr<TProtocol> proto, const int64_t& val) {
|
||||
static uint32_t write(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, const int64_t& val) {
|
||||
return proto->writeI64(val);
|
||||
}
|
||||
|
||||
static uint32_t write(shared_ptr<TProtocol> proto, const std::string& val) {
|
||||
static uint32_t write(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, const std::string& val) {
|
||||
return proto->writeString(val);
|
||||
}
|
||||
|
||||
/* Read functions */
|
||||
|
||||
static uint32_t read(shared_ptr<TProtocol> proto, int8_t& val) { return proto->readByte(val); }
|
||||
static uint32_t read(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, int8_t& val) { return proto->readByte(val); }
|
||||
|
||||
static uint32_t read(shared_ptr<TProtocol> proto, int16_t& val) { return proto->readI16(val); }
|
||||
static uint32_t read(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, int16_t& val) { return proto->readI16(val); }
|
||||
|
||||
static uint32_t read(shared_ptr<TProtocol> proto, int32_t& val) { return proto->readI32(val); }
|
||||
static uint32_t read(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, int32_t& val) { return proto->readI32(val); }
|
||||
|
||||
static uint32_t read(shared_ptr<TProtocol> proto, int64_t& val) { return proto->readI64(val); }
|
||||
static uint32_t read(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, int64_t& val) { return proto->readI64(val); }
|
||||
|
||||
static uint32_t read(shared_ptr<TProtocol> proto, double& val) { return proto->readDouble(val); }
|
||||
static uint32_t read(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, double& val) { return proto->readDouble(val); }
|
||||
|
||||
static uint32_t read(shared_ptr<TProtocol> proto, std::string& val) {
|
||||
static uint32_t read(apache::thrift::stdcxx::shared_ptr<apache::thrift::protocol::TProtocol> proto, std::string& val) {
|
||||
return proto->readString(val);
|
||||
}
|
||||
};
|
||||
|
|
41
vendor/git.apache.org/thrift.git/lib/cpp/test/JSONProtoTest.cpp
generated
vendored
41
vendor/git.apache.org/thrift.git/lib/cpp/test/JSONProtoTest.cpp
generated
vendored
|
@ -21,18 +21,20 @@
|
|||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include <thrift/protocol/TJSONProtocol.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include "gen-cpp/DebugProtoTest_types.h"
|
||||
|
||||
#define BOOST_TEST_MODULE JSONProtoTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace thrift::test::debug;
|
||||
using namespace apache::thrift;
|
||||
using apache::thrift::transport::TMemoryBuffer;
|
||||
using apache::thrift::protocol::TJSONProtocol;
|
||||
|
||||
static std::auto_ptr<OneOfEach> ooe;
|
||||
static stdcxx::shared_ptr<OneOfEach> ooe;
|
||||
|
||||
void testCaseSetup_1() {
|
||||
ooe.reset(new OneOfEach);
|
||||
|
@ -65,7 +67,7 @@ BOOST_AUTO_TEST_CASE(test_json_proto_1) {
|
|||
"Expected:\n" << expected_result << "\nGotten:\n" << result);
|
||||
}
|
||||
|
||||
static std::auto_ptr<Nesting> n;
|
||||
static stdcxx::shared_ptr<Nesting> n;
|
||||
|
||||
void testCaseSetup_2() {
|
||||
testCaseSetup_1();
|
||||
|
@ -105,7 +107,7 @@ BOOST_AUTO_TEST_CASE(test_json_proto_2) {
|
|||
"Expected:\n" << expected_result << "\nGotten:\n" << result);
|
||||
}
|
||||
|
||||
static std::auto_ptr<HolyMoley> hm;
|
||||
static stdcxx::shared_ptr<HolyMoley> hm;
|
||||
|
||||
void testCaseSetup_3() {
|
||||
testCaseSetup_2();
|
||||
|
@ -183,8 +185,8 @@ BOOST_AUTO_TEST_CASE(test_json_proto_3) {
|
|||
BOOST_AUTO_TEST_CASE(test_json_proto_4) {
|
||||
testCaseSetup_1();
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
ooe->write(proto.get());
|
||||
OneOfEach ooe2;
|
||||
|
@ -196,8 +198,8 @@ BOOST_AUTO_TEST_CASE(test_json_proto_4) {
|
|||
BOOST_AUTO_TEST_CASE(test_json_proto_5) {
|
||||
testCaseSetup_3();
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
hm->write(proto.get());
|
||||
HolyMoley hm2;
|
||||
|
@ -234,8 +236,8 @@ BOOST_AUTO_TEST_CASE(test_json_proto_6) {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_json_proto_7) {
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
Base64 base;
|
||||
base.a = 123;
|
||||
|
@ -262,9 +264,10 @@ BOOST_AUTO_TEST_CASE(test_json_proto_8) {
|
|||
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
|
||||
"\",3,1,2,3]}}";
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
(uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
const std::size_t bufSiz = strlen(json_string) * sizeof(char);
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
(uint8_t*)(json_string), static_cast<uint32_t>(bufSiz)));
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
OneOfEach ooe2;
|
||||
|
||||
|
@ -291,9 +294,9 @@ BOOST_AUTO_TEST_CASE(test_json_unicode_escaped) {
|
|||
"\",3,1,2,3]}}";
|
||||
const char* expected_zomg_unicode = "\xe0\xb8\x81 \xf0\x9d\x94\xbe";
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
(uint8_t*)(json_string), sizeof(json_string)));
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
OneOfEach ooe2;
|
||||
ooe2.read(proto.get());
|
||||
|
@ -312,9 +315,9 @@ BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_low_surrogate) {
|
|||
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
|
||||
"\",3,1,2,3]}}";
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
(uint8_t*)(json_string), sizeof(json_string)));
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
OneOfEach ooe2;
|
||||
BOOST_CHECK_THROW(ooe2.read(proto.get()),
|
||||
|
@ -330,9 +333,9 @@ BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_hi_surrogate) {
|
|||
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
|
||||
"\",3,1,2,3]}}";
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
(uint8_t*)(json_string), sizeof(json_string)));
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
stdcxx::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
OneOfEach ooe2;
|
||||
BOOST_CHECK_THROW(ooe2.read(proto.get()),
|
||||
|
|
75
vendor/git.apache.org/thrift.git/lib/cpp/test/Makefile.am
generated
vendored
75
vendor/git.apache.org/thrift.git/lib/cpp/test/Makefile.am
generated
vendored
|
@ -18,7 +18,8 @@
|
|||
#
|
||||
AUTOMAKE_OPTIONS = subdir-objects serial-tests
|
||||
|
||||
BUILT_SOURCES = gen-cpp/DebugProtoTest_types.h \
|
||||
BUILT_SOURCES = gen-cpp/AnnotationTest_types.h \
|
||||
gen-cpp/DebugProtoTest_types.h \
|
||||
gen-cpp/EnumTest_types.h \
|
||||
gen-cpp/OptionalRequiredTest_types.h \
|
||||
gen-cpp/Recursive_types.h \
|
||||
|
@ -27,12 +28,19 @@ BUILT_SOURCES = gen-cpp/DebugProtoTest_types.h \
|
|||
gen-cpp/ChildService.h \
|
||||
gen-cpp/EmptyService.h \
|
||||
gen-cpp/ParentService.h \
|
||||
gen-cpp/OneWayTest_types.h \
|
||||
gen-cpp/OneWayService.h \
|
||||
gen-cpp/OneWayTest_constants.h \
|
||||
gen-cpp/proc_types.h
|
||||
|
||||
noinst_LTLIBRARIES = libtestgencpp.la libprocessortest.la
|
||||
nodist_libtestgencpp_la_SOURCES = \
|
||||
gen-cpp/AnnotationTest_types.cpp \
|
||||
gen-cpp/AnnotationTest_types.h \
|
||||
gen-cpp/DebugProtoTest_types.cpp \
|
||||
gen-cpp/DebugProtoTest_types.h \
|
||||
gen-cpp/DoubleConstantsTest_constants.cpp \
|
||||
gen-cpp/DoubleConstantsTest_constants.h \
|
||||
gen-cpp/EnumTest_types.cpp \
|
||||
gen-cpp/EnumTest_types.h \
|
||||
gen-cpp/OptionalRequiredTest_types.cpp \
|
||||
|
@ -45,6 +53,12 @@ nodist_libtestgencpp_la_SOURCES = \
|
|||
gen-cpp/ThriftTest_constants.h \
|
||||
gen-cpp/TypedefTest_types.cpp \
|
||||
gen-cpp/TypedefTest_types.h \
|
||||
gen-cpp/OneWayService.cpp \
|
||||
gen-cpp/OneWayTest_constants.cpp \
|
||||
gen-cpp/OneWayTest_types.h \
|
||||
gen-cpp/OneWayService.h \
|
||||
gen-cpp/OneWayTest_constants.h \
|
||||
gen-cpp/OneWayTest_types.cpp \
|
||||
ThriftTest_extras.cpp \
|
||||
DebugProtoTest_extras.cpp
|
||||
|
||||
|
@ -89,13 +103,16 @@ check_PROGRAMS = \
|
|||
TFileTransportTest \
|
||||
link_test \
|
||||
OpenSSLManualInitTest \
|
||||
EnumTest
|
||||
EnumTest \
|
||||
RenderedDoubleConstantsTest \
|
||||
AnnotationTest
|
||||
|
||||
if AMX_HAVE_LIBEVENT
|
||||
noinst_PROGRAMS += \
|
||||
processor_test
|
||||
check_PROGRAMS += \
|
||||
TNonblockingServerTest
|
||||
TNonblockingServerTest \
|
||||
TNonblockingSSLServerTest
|
||||
endif
|
||||
|
||||
TESTS_ENVIRONMENT= \
|
||||
|
@ -108,6 +125,7 @@ TESTS = \
|
|||
|
||||
UnitTests_SOURCES = \
|
||||
UnitTestMain.cpp \
|
||||
OneWayHTTPTest.cpp \
|
||||
TMemoryBufferTest.cpp \
|
||||
TBufferBaseTest.cpp \
|
||||
Base64Test.cpp \
|
||||
|
@ -119,12 +137,15 @@ UnitTests_SOURCES = \
|
|||
|
||||
if !WITH_BOOSTTHREADS
|
||||
UnitTests_SOURCES += \
|
||||
RWMutexStarveTest.cpp
|
||||
concurrency/MutexTest.cpp \
|
||||
concurrency/RWMutexStarveTest.cpp
|
||||
endif
|
||||
|
||||
UnitTests_LDADD = \
|
||||
libtestgencpp.la \
|
||||
$(BOOST_TEST_LDADD)
|
||||
$(BOOST_TEST_LDADD) \
|
||||
$(BOOST_SYSTEM_LDADD) \
|
||||
$(BOOST_THREAD_LDADD)
|
||||
|
||||
TInterruptTest_SOURCES = \
|
||||
TSocketInterruptTest.cpp \
|
||||
|
@ -178,12 +199,23 @@ ZlibTest_LDADD = \
|
|||
-lz
|
||||
|
||||
EnumTest_SOURCES = \
|
||||
EnumTest.cpp
|
||||
EnumTest.cpp
|
||||
|
||||
EnumTest_LDADD = \
|
||||
libtestgencpp.la \
|
||||
$(BOOST_TEST_LDADD)
|
||||
|
||||
RenderedDoubleConstantsTest_SOURCES = RenderedDoubleConstantsTest.cpp
|
||||
|
||||
RenderedDoubleConstantsTest_LDADD = libtestgencpp.la $(BOOST_TEST_LDADD)
|
||||
|
||||
AnnotationTest_SOURCES = \
|
||||
AnnotationTest.cpp
|
||||
|
||||
AnnotationTest_LDADD = \
|
||||
libtestgencpp.la \
|
||||
$(BOOST_TEST_LDADD)
|
||||
|
||||
TFileTransportTest_SOURCES = \
|
||||
TFileTransportTest.cpp
|
||||
|
||||
|
@ -260,6 +292,21 @@ TNonblockingServerTest_LDADD = libprocessortest.la \
|
|||
$(BOOST_TEST_LDADD) \
|
||||
$(BOOST_LDFLAGS) \
|
||||
$(LIBEVENT_LIBS)
|
||||
#
|
||||
# TNonblockingSSLServerTest
|
||||
#
|
||||
TNonblockingSSLServerTest_SOURCES = TNonblockingSSLServerTest.cpp
|
||||
|
||||
TNonblockingSSLServerTest_LDADD = libprocessortest.la \
|
||||
$(top_builddir)/lib/cpp/libthrift.la \
|
||||
$(top_builddir)/lib/cpp/libthriftnb.la \
|
||||
$(BOOST_TEST_LDADD) \
|
||||
$(BOOST_LDFLAGS) \
|
||||
$(BOOST_FILESYSTEM_LDADD) \
|
||||
$(BOOST_CHRONO_LDADD) \
|
||||
$(BOOST_SYSTEM_LDADD) \
|
||||
$(BOOST_THREAD_LDADD) \
|
||||
$(LIBEVENT_LIBS)
|
||||
|
||||
#
|
||||
# OptionalRequiredTest
|
||||
|
@ -332,11 +379,17 @@ OpenSSLManualInitTest_LDADD = \
|
|||
#
|
||||
# Common thrift code generation rules
|
||||
#
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-cpp/AnnotationTest_constants.cpp gen-cpp/AnnotationTest_constants.h gen-cpp/AnnotationTest_types.cpp gen-cpp/AnnotationTest_types.h: $(top_srcdir)/test/AnnotationTest.thrift
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h: $(top_srcdir)/test/DebugProtoTest.thrift
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
gen-cpp/DoubleConstantsTest_constants.cpp gen-cpp/DoubleConstantsTest_constants.h: $(top_srcdir)/test/DoubleConstantsTest.thrift
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
|
||||
gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h: $(top_srcdir)/test/EnumTest.thrift
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
|
@ -355,10 +408,13 @@ gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp: $(top_srcdir)/test/StressTest.
|
|||
gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h: $(top_srcdir)/test/ThriftTest.thrift
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
gen-cpp/OneWayService.cpp gen-cpp/OneWayTest_constants.cpp gen-cpp/OneWayTest_types.h gen-cpp/OneWayService.h gen-cpp/OneWayTest_constants.h gen-cpp/OneWayTest_types.cpp: OneWayTest.thrift
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cpp/ParentService.h gen-cpp/proc_types.cpp gen-cpp/proc_types.h: processor/proc.thrift
|
||||
$(THRIFT) --gen cpp:templates,cob_style $<
|
||||
|
||||
AM_CPPFLAGS = $(BOOST_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -D__STDC_LIMIT_MACROS -I.
|
||||
AM_CPPFLAGS = $(BOOST_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I.
|
||||
AM_LDFLAGS = $(BOOST_LDFLAGS)
|
||||
AM_CXXFLAGS = -Wall -Wextra -pedantic
|
||||
|
||||
|
@ -371,4 +427,5 @@ EXTRA_DIST = \
|
|||
qt \
|
||||
CMakeLists.txt \
|
||||
DebugProtoTest_extras.cpp \
|
||||
ThriftTest_extras.cpp
|
||||
ThriftTest_extras.cpp \
|
||||
OneWayTest.thrift
|
||||
|
|
242
vendor/git.apache.org/thrift.git/lib/cpp/test/OneWayHTTPTest.cpp
generated
vendored
Normal file
242
vendor/git.apache.org/thrift.git/lib/cpp/test/OneWayHTTPTest.cpp
generated
vendored
Normal file
|
@ -0,0 +1,242 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <iostream>
|
||||
#include <climits>
|
||||
#include <vector>
|
||||
#include <thrift/concurrency/Monitor.h>
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/protocol/TJSONProtocol.h>
|
||||
#include <thrift/server/TThreadedServer.h>
|
||||
#include <thrift/transport/THttpServer.h>
|
||||
#include <thrift/transport/THttpClient.h>
|
||||
#include <thrift/transport/TServerSocket.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include "gen-cpp/OneWayService.h"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(OneWayHTTPTest)
|
||||
|
||||
using namespace apache::thrift;
|
||||
using apache::thrift::protocol::TProtocol;
|
||||
using apache::thrift::protocol::TBinaryProtocol;
|
||||
using apache::thrift::protocol::TBinaryProtocolFactory;
|
||||
using apache::thrift::protocol::TJSONProtocol;
|
||||
using apache::thrift::protocol::TJSONProtocolFactory;
|
||||
using apache::thrift::server::TThreadedServer;
|
||||
using apache::thrift::server::TServerEventHandler;
|
||||
using apache::thrift::transport::TTransport;
|
||||
using apache::thrift::transport::THttpServer;
|
||||
using apache::thrift::transport::THttpServerTransportFactory;
|
||||
using apache::thrift::transport::THttpClient;
|
||||
using apache::thrift::transport::TBufferedTransport;
|
||||
using apache::thrift::transport::TBufferedTransportFactory;
|
||||
using apache::thrift::transport::TMemoryBuffer;
|
||||
using apache::thrift::transport::TServerSocket;
|
||||
using apache::thrift::transport::TSocket;
|
||||
using apache::thrift::transport::TTransportException;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
namespace utf = boost::unit_test;
|
||||
|
||||
// Define this env var to enable some logging (in case you need to debug)
|
||||
#undef ENABLE_STDERR_LOGGING
|
||||
|
||||
class OneWayServiceHandler : public onewaytest::OneWayServiceIf {
|
||||
public:
|
||||
OneWayServiceHandler() {}
|
||||
|
||||
void roundTripRPC() override {
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "roundTripRPC()" << endl;
|
||||
#endif
|
||||
}
|
||||
void oneWayRPC() {
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "oneWayRPC()" << std::endl ;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
class OneWayServiceCloneFactory : virtual public onewaytest::OneWayServiceIfFactory {
|
||||
public:
|
||||
virtual ~OneWayServiceCloneFactory() {}
|
||||
virtual onewaytest::OneWayServiceIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo)
|
||||
{
|
||||
(void)connInfo ;
|
||||
return new OneWayServiceHandler;
|
||||
}
|
||||
virtual void releaseHandler( onewaytest::OneWayServiceIf* handler) {
|
||||
delete handler;
|
||||
}
|
||||
};
|
||||
|
||||
class RPC0ThreadClass {
|
||||
public:
|
||||
RPC0ThreadClass(TThreadedServer& server) : server_(server) { } // Constructor
|
||||
~RPC0ThreadClass() { } // Destructor
|
||||
|
||||
void Run() {
|
||||
server_.serve() ;
|
||||
}
|
||||
TThreadedServer& server_ ;
|
||||
} ;
|
||||
|
||||
using apache::thrift::concurrency::Monitor;
|
||||
using apache::thrift::concurrency::Mutex;
|
||||
using apache::thrift::concurrency::Synchronized;
|
||||
|
||||
// copied from IntegrationTest
|
||||
class TServerReadyEventHandler : public TServerEventHandler, public Monitor {
|
||||
public:
|
||||
TServerReadyEventHandler() : isListening_(false), accepted_(0) {}
|
||||
virtual ~TServerReadyEventHandler() {}
|
||||
virtual void preServe() {
|
||||
Synchronized sync(*this);
|
||||
isListening_ = true;
|
||||
notify();
|
||||
}
|
||||
virtual void* createContext(shared_ptr<TProtocol> input,
|
||||
shared_ptr<TProtocol> output) {
|
||||
Synchronized sync(*this);
|
||||
++accepted_;
|
||||
notify();
|
||||
|
||||
(void)input;
|
||||
(void)output;
|
||||
return NULL;
|
||||
}
|
||||
bool isListening() const { return isListening_; }
|
||||
uint64_t acceptedCount() const { return accepted_; }
|
||||
|
||||
private:
|
||||
bool isListening_;
|
||||
uint64_t accepted_;
|
||||
};
|
||||
|
||||
class TBlockableBufferedTransport : public TBufferedTransport {
|
||||
public:
|
||||
TBlockableBufferedTransport(stdcxx::shared_ptr<TTransport> transport)
|
||||
: TBufferedTransport(transport, 10240),
|
||||
blocked_(false) {
|
||||
}
|
||||
|
||||
uint32_t write_buffer_length() {
|
||||
uint32_t have_bytes = static_cast<uint32_t>(wBase_ - wBuf_.get());
|
||||
return have_bytes ;
|
||||
}
|
||||
|
||||
void block() {
|
||||
blocked_ = true ;
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "block flushing\n" ;
|
||||
#endif
|
||||
}
|
||||
void unblock() {
|
||||
blocked_ = false ;
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "unblock flushing, buffer is\n<<" << std::string((char *)wBuf_.get(), write_buffer_length()) << ">>\n" ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void flush() override {
|
||||
if (blocked_) {
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "flush was blocked\n" ;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
TBufferedTransport::flush() ;
|
||||
}
|
||||
|
||||
bool blocked_ ;
|
||||
} ;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( JSON_BufferedHTTP )
|
||||
{
|
||||
stdcxx::shared_ptr<TServerSocket> ss = stdcxx::make_shared<TServerSocket>(0) ;
|
||||
TThreadedServer server(
|
||||
stdcxx::make_shared<onewaytest::OneWayServiceProcessorFactory>(stdcxx::make_shared<OneWayServiceCloneFactory>()),
|
||||
ss, //port
|
||||
stdcxx::make_shared<THttpServerTransportFactory>(),
|
||||
stdcxx::make_shared<TJSONProtocolFactory>());
|
||||
|
||||
stdcxx::shared_ptr<TServerReadyEventHandler> pEventHandler(new TServerReadyEventHandler) ;
|
||||
server.setServerEventHandler(pEventHandler);
|
||||
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "Starting the server...\n";
|
||||
#endif
|
||||
RPC0ThreadClass t(server) ;
|
||||
boost::thread thread(&RPC0ThreadClass::Run, &t);
|
||||
|
||||
{
|
||||
Synchronized sync(*(pEventHandler.get()));
|
||||
while (!pEventHandler->isListening()) {
|
||||
pEventHandler->wait();
|
||||
}
|
||||
}
|
||||
|
||||
int port = ss->getPort() ;
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "port " << port << endl ;
|
||||
#endif
|
||||
|
||||
{
|
||||
stdcxx::shared_ptr<TSocket> socket(new TSocket("localhost", port));
|
||||
socket->setRecvTimeout(10000) ; // 1000msec should be enough
|
||||
stdcxx::shared_ptr<TBlockableBufferedTransport> blockable_transport(new TBlockableBufferedTransport(socket));
|
||||
stdcxx::shared_ptr<TTransport> transport(new THttpClient(blockable_transport, "localhost", "/service"));
|
||||
stdcxx::shared_ptr<TProtocol> protocol(new TJSONProtocol(transport));
|
||||
onewaytest::OneWayServiceClient client(protocol);
|
||||
|
||||
|
||||
transport->open();
|
||||
client.roundTripRPC();
|
||||
blockable_transport->block() ;
|
||||
uint32_t size0 = blockable_transport->write_buffer_length() ;
|
||||
client.send_oneWayRPC() ;
|
||||
uint32_t size1 = blockable_transport->write_buffer_length() ;
|
||||
client.send_oneWayRPC() ;
|
||||
uint32_t size2 = blockable_transport->write_buffer_length() ;
|
||||
BOOST_CHECK((size1 - size0) == (size2 - size1)) ;
|
||||
blockable_transport->unblock() ;
|
||||
client.send_roundTripRPC() ;
|
||||
blockable_transport->flush() ;
|
||||
try {
|
||||
client.recv_roundTripRPC() ;
|
||||
} catch (TTransportException e) {
|
||||
BOOST_ERROR( "we should not get a transport exception -- this means we failed: " + std::string(e.what()) ) ;
|
||||
}
|
||||
transport->close();
|
||||
}
|
||||
server.stop();
|
||||
thread.join() ;
|
||||
#ifdef ENABLE_STDERR_LOGGING
|
||||
cerr << "finished.\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
46
vendor/git.apache.org/thrift.git/lib/cpp/test/OneWayTest.thrift
generated
vendored
Normal file
46
vendor/git.apache.org/thrift.git/lib/cpp/test/OneWayTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Contains some contributions under the Thrift Software License.
|
||||
* Please see doc/old-thrift-license.txt in the Thrift distribution for
|
||||
* details.
|
||||
*/
|
||||
|
||||
namespace c_glib OneWayTest
|
||||
namespace java onewaytest
|
||||
namespace cpp onewaytest
|
||||
namespace rb Onewaytest
|
||||
namespace perl OneWayTest
|
||||
namespace csharp Onewaytest
|
||||
namespace js OneWayTest
|
||||
namespace st OneWayTest
|
||||
namespace py OneWayTest
|
||||
namespace py.twisted OneWayTest
|
||||
namespace go onewaytest
|
||||
namespace php OneWayTest
|
||||
namespace delphi Onewaytest
|
||||
namespace cocoa OneWayTest
|
||||
namespace lua OneWayTest
|
||||
namespace xsd test (uri = 'http://thrift.apache.org/ns/OneWayTest')
|
||||
namespace netcore ThriftAsync.OneWayTest
|
||||
|
||||
// a minimal Thrift service, for use in OneWayHTTPTtest.cpp
|
||||
service OneWayService {
|
||||
void roundTripRPC(),
|
||||
oneway void oneWayRPC()
|
||||
}
|
1
vendor/git.apache.org/thrift.git/lib/cpp/test/OpenSSLManualInitTest.cpp
generated
vendored
1
vendor/git.apache.org/thrift.git/lib/cpp/test/OpenSSLManualInitTest.cpp
generated
vendored
|
@ -28,7 +28,6 @@
|
|||
#include <openssl/evp.h>
|
||||
#include <thrift/transport/TSSLSocket.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace apache::thrift::transport;
|
||||
|
||||
void make_isolated_sslsocketfactory() {
|
||||
|
|
6
vendor/git.apache.org/thrift.git/lib/cpp/test/OptionalRequiredTest.cpp
generated
vendored
6
vendor/git.apache.org/thrift.git/lib/cpp/test/OptionalRequiredTest.cpp
generated
vendored
|
@ -40,7 +40,7 @@ template<typename Struct>
|
|||
void trywrite(const Struct& s, bool should_work) {
|
||||
bool worked;
|
||||
try {
|
||||
TBinaryProtocol protocol(boost::shared_ptr<TTransport>(new TMemoryBuffer));
|
||||
TBinaryProtocol protocol(stdcxx::shared_ptr<TTransport>(new TMemoryBuffer));
|
||||
s.write(&protocol);
|
||||
worked = true;
|
||||
} catch (TProtocolException & ex) {
|
||||
|
@ -52,7 +52,7 @@ void trywrite(const Struct& s, bool should_work) {
|
|||
|
||||
template <typename Struct1, typename Struct2>
|
||||
void write_to_read(const Struct1& w, Struct2& r) {
|
||||
TBinaryProtocol protocol(boost::shared_ptr<TTransport>(new TMemoryBuffer));
|
||||
TBinaryProtocol protocol(stdcxx::shared_ptr<TTransport>(new TMemoryBuffer));
|
||||
w.write(&protocol);
|
||||
r.read(&protocol);
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE(test_optional_required_11) {
|
|||
o1.im_big.push_back(mymap);
|
||||
BOOST_CHECK(o1 == o2);
|
||||
|
||||
TBinaryProtocol protocol(boost::shared_ptr<TTransport>(new TMemoryBuffer));
|
||||
TBinaryProtocol protocol(stdcxx::shared_ptr<TTransport>(new TMemoryBuffer));
|
||||
o1.write(&protocol);
|
||||
|
||||
o1.im_big.push_back(mymap);
|
||||
|
|
15
vendor/git.apache.org/thrift.git/lib/cpp/test/RecursiveTest.cpp
generated
vendored
15
vendor/git.apache.org/thrift.git/lib/cpp/test/RecursiveTest.cpp
generated
vendored
|
@ -22,20 +22,21 @@
|
|||
*/
|
||||
|
||||
#include "gen-cpp/Recursive_types.h"
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
|
||||
#define BOOST_TEST_MODULE RecursiveTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using apache::thrift::transport::TMemoryBuffer;
|
||||
using apache::thrift::protocol::TBinaryProtocol;
|
||||
using boost::shared_ptr;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_recursive_1) {
|
||||
shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
|
||||
shared_ptr<TBinaryProtocol> prot(new TBinaryProtocol(buf));
|
||||
|
||||
|
||||
RecTree tree;
|
||||
RecTree child;
|
||||
tree.children.push_back(child);
|
||||
|
@ -50,9 +51,9 @@ BOOST_AUTO_TEST_CASE(test_recursive_1) {
|
|||
BOOST_AUTO_TEST_CASE(test_recursive_2) {
|
||||
shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
|
||||
shared_ptr<TBinaryProtocol> prot(new TBinaryProtocol(buf));
|
||||
|
||||
|
||||
RecList l;
|
||||
boost::shared_ptr<RecList> l2(new RecList);
|
||||
shared_ptr<RecList> l2(new RecList);
|
||||
l.nextitem = l2;
|
||||
|
||||
l.write(prot.get());
|
||||
|
@ -68,7 +69,7 @@ BOOST_AUTO_TEST_CASE(test_recursive_3) {
|
|||
shared_ptr<TBinaryProtocol> prot(new TBinaryProtocol(buf));
|
||||
|
||||
CoRec c;
|
||||
boost::shared_ptr<CoRec2> r(new CoRec2);
|
||||
shared_ptr<CoRec2> r(new CoRec2);
|
||||
c.other = r;
|
||||
|
||||
c.write(prot.get());
|
||||
|
@ -82,7 +83,7 @@ BOOST_AUTO_TEST_CASE(test_recursive_4) {
|
|||
shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
|
||||
shared_ptr<TBinaryProtocol> prot(new TBinaryProtocol(buf));
|
||||
|
||||
boost::shared_ptr<RecList> depthLimit(new RecList);
|
||||
shared_ptr<RecList> depthLimit(new RecList);
|
||||
depthLimit->nextitem = depthLimit;
|
||||
BOOST_CHECK_THROW(depthLimit->write(prot.get()),
|
||||
apache::thrift::protocol::TProtocolException);
|
||||
|
|
122
vendor/git.apache.org/thrift.git/lib/cpp/test/RenderedDoubleConstantsTest.cpp
generated
vendored
Normal file
122
vendor/git.apache.org/thrift.git/lib/cpp/test/RenderedDoubleConstantsTest.cpp
generated
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#define EPSILON 0.0000001
|
||||
#include <typeindex>
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
#include "gen-cpp/DoubleConstantsTest_constants.h"
|
||||
using namespace thrift::test;
|
||||
|
||||
#define BOOST_TEST_MODULE RenderedDoubleConstantsTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(RenderedDoubleConstantsTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_rendered_double_constants) {
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT = 1.0;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT = -100.0;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT = 9223372036854775807.0;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT = -9223372036854775807.0;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS = 3.14159265359;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE = 1000000.1;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE = -1000000.1;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE = 1.7e+308;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE = 9223372036854775816.43;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE = -1.7e+308;
|
||||
const double EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE = -9223372036854775816.43;
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE, EPSILON);
|
||||
BOOST_CHECK_CLOSE(
|
||||
g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE, EPSILON);
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST).hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE).hash_code());
|
||||
BOOST_CHECK(
|
||||
typeid(g_DoubleConstantsTest_constants.DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST)
|
||||
.hash_code() ==
|
||||
typeid(EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE).hash_code());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_rendered_double_list) {
|
||||
const std::vector<double> EXPECTED_DOUBLE_LIST{1.0,-100.0,100.0,9223372036854775807.0,-9223372036854775807.0,
|
||||
3.14159265359,1000000.1,-1000000.1,1.7e+308,-1.7e+308,9223372036854775816.43,-9223372036854775816.43};
|
||||
BOOST_CHECK_EQUAL(g_DoubleConstantsTest_constants.DOUBLE_LIST_TEST.size(), EXPECTED_DOUBLE_LIST.size());
|
||||
for (unsigned int i = 0; i < EXPECTED_DOUBLE_LIST.size(); ++i) {
|
||||
BOOST_CHECK_CLOSE(g_DoubleConstantsTest_constants.DOUBLE_LIST_TEST[i], EXPECTED_DOUBLE_LIST[i], EPSILON);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
62
vendor/git.apache.org/thrift.git/lib/cpp/test/SecurityTest.cpp
generated
vendored
62
vendor/git.apache.org/thrift.git/lib/cpp/test/SecurityTest.cpp
generated
vendored
|
@ -19,13 +19,11 @@
|
|||
|
||||
#define BOOST_TEST_MODULE SecurityTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TSSLServerSocket.h>
|
||||
#include <thrift/transport/TSSLSocket.h>
|
||||
#include <thrift/transport/TTransport.h>
|
||||
|
@ -42,6 +40,9 @@ using apache::thrift::transport::TTransport;
|
|||
using apache::thrift::transport::TTransportException;
|
||||
using apache::thrift::transport::TTransportFactory;
|
||||
|
||||
using apache::thrift::stdcxx::bind;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
boost::filesystem::path keyDir;
|
||||
boost::filesystem::path certFile(const std::string& filename)
|
||||
{
|
||||
|
@ -54,36 +55,36 @@ struct GlobalFixture
|
|||
GlobalFixture()
|
||||
{
|
||||
using namespace boost::unit_test::framework;
|
||||
for (int i = 0; i < master_test_suite().argc; ++i)
|
||||
{
|
||||
BOOST_TEST_MESSAGE(boost::format("argv[%1%] = \"%2%\"") % i % master_test_suite().argv[i]);
|
||||
}
|
||||
for (int i = 0; i < master_test_suite().argc; ++i)
|
||||
{
|
||||
BOOST_TEST_MESSAGE(boost::format("argv[%1%] = \"%2%\"") % i % master_test_suite().argv[i]);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
// OpenSSL calls send() without MSG_NOSIGPIPE so writing to a socket that has
|
||||
// disconnected can cause a SIGPIPE signal...
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
// OpenSSL calls send() without MSG_NOSIGPIPE so writing to a socket that has
|
||||
// disconnected can cause a SIGPIPE signal...
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
TSSLSocketFactory::setManualOpenSSLInitialization(true);
|
||||
apache::thrift::transport::initializeOpenSSL();
|
||||
TSSLSocketFactory::setManualOpenSSLInitialization(true);
|
||||
apache::thrift::transport::initializeOpenSSL();
|
||||
|
||||
keyDir = boost::filesystem::current_path().parent_path().parent_path().parent_path() / "test" / "keys";
|
||||
if (!boost::filesystem::exists(certFile("server.crt")))
|
||||
{
|
||||
keyDir = boost::filesystem::path(master_test_suite().argv[master_test_suite().argc - 1]);
|
||||
if (!boost::filesystem::exists(certFile("server.crt")))
|
||||
{
|
||||
throw std::invalid_argument("The last argument to this test must be the directory containing the test certificate(s).");
|
||||
}
|
||||
}
|
||||
keyDir = boost::filesystem::current_path().parent_path().parent_path().parent_path() / "test" / "keys";
|
||||
if (!boost::filesystem::exists(certFile("server.crt")))
|
||||
{
|
||||
keyDir = boost::filesystem::path(master_test_suite().argv[master_test_suite().argc - 1]);
|
||||
if (!boost::filesystem::exists(certFile("server.crt")))
|
||||
{
|
||||
throw std::invalid_argument("The last argument to this test must be the directory containing the test certificate(s).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~GlobalFixture()
|
||||
{
|
||||
apache::thrift::transport::cleanupOpenSSL();
|
||||
apache::thrift::transport::cleanupOpenSSL();
|
||||
#ifdef __linux__
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
@ -102,8 +103,8 @@ struct SecurityFixture
|
|||
{
|
||||
boost::mutex::scoped_lock lock(mMutex);
|
||||
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory;
|
||||
boost::shared_ptr<TSSLServerSocket> pServerSocket;
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory;
|
||||
shared_ptr<TSSLServerSocket> pServerSocket;
|
||||
|
||||
pServerSocketFactory.reset(new TSSLSocketFactory(static_cast<apache::thrift::transport::SSLProtocol>(protocol)));
|
||||
pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||
|
@ -111,7 +112,7 @@ struct SecurityFixture
|
|||
pServerSocketFactory->loadPrivateKey(certFile("server.key").string().c_str());
|
||||
pServerSocketFactory->server(true);
|
||||
pServerSocket.reset(new TSSLServerSocket("localhost", 0, pServerSocketFactory));
|
||||
boost::shared_ptr<TTransport> connectedClient;
|
||||
shared_ptr<TTransport> connectedClient;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -153,8 +154,8 @@ struct SecurityFixture
|
|||
{
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory;
|
||||
boost::shared_ptr<TSSLSocket> pClientSocket;
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory;
|
||||
shared_ptr<TSSLSocket> pClientSocket;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -254,11 +255,12 @@ BOOST_AUTO_TEST_CASE(ssl_security_matrix)
|
|||
% protocol2str(si) % protocol2str(ci));
|
||||
|
||||
mConnected = false;
|
||||
// thread_group manages the thread lifetime - ignore the return value of create_thread
|
||||
boost::thread_group threads;
|
||||
threads.create_thread(boost::bind(&SecurityFixture::server, this, static_cast<apache::thrift::transport::SSLProtocol>(si)));
|
||||
(void)threads.create_thread(bind(&SecurityFixture::server, this, static_cast<apache::thrift::transport::SSLProtocol>(si)));
|
||||
mCVar.wait(lock); // wait for listen() to succeed
|
||||
lock.unlock();
|
||||
threads.create_thread(boost::bind(&SecurityFixture::client, this, static_cast<apache::thrift::transport::SSLProtocol>(ci)));
|
||||
(void)threads.create_thread(bind(&SecurityFixture::client, this, static_cast<apache::thrift::transport::SSLProtocol>(ci)));
|
||||
threads.join_all();
|
||||
|
||||
BOOST_CHECK_MESSAGE(mConnected == matrix[ci][si],
|
||||
|
|
4
vendor/git.apache.org/thrift.git/lib/cpp/test/SpecializationTest.cpp
generated
vendored
4
vendor/git.apache.org/thrift.git/lib/cpp/test/SpecializationTest.cpp
generated
vendored
|
@ -82,8 +82,8 @@ BOOST_AUTO_TEST_CASE(test_specialization_1) {
|
|||
stage2.back().message = "nevermore";
|
||||
hm.bonks["poe"] = stage2;
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
boost::shared_ptr<TProtocol> proto(new MyProtocol(buffer));
|
||||
apache::thrift::stdcxx::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
|
||||
apache::thrift::stdcxx::shared_ptr<TProtocol> proto(new MyProtocol(buffer));
|
||||
|
||||
ooe.write(proto.get());
|
||||
OneOfEach ooe2;
|
||||
|
|
9
vendor/git.apache.org/thrift.git/lib/cpp/test/TBufferBaseTest.cpp
generated
vendored
9
vendor/git.apache.org/thrift.git/lib/cpp/test/TBufferBaseTest.cpp
generated
vendored
|
@ -21,13 +21,14 @@
|
|||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include <thrift/transport/TShortReadTransport.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
using std::string;
|
||||
using boost::shared_ptr;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using apache::thrift::transport::TMemoryBuffer;
|
||||
using apache::thrift::transport::TBufferedTransport;
|
||||
using apache::thrift::transport::TFramedTransport;
|
||||
using apache::thrift::transport::test::TShortReadTransport;
|
||||
using std::string;
|
||||
|
||||
// Shamelessly copied from ZlibTransport. TODO: refactor.
|
||||
unsigned int dist[][5000] = {
|
||||
|
@ -566,7 +567,7 @@ BOOST_AUTO_TEST_CASE( test_FramedTransport_Write_Read ) {
|
|||
for (int d1 = 0; d1 < 3; d1++) {
|
||||
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
|
||||
TFramedTransport trans(buffer, size);
|
||||
uint8_t data_out[1<<15];
|
||||
std::vector<uint8_t> data_out(1<<17, 0);
|
||||
std::vector<int> flush_sizes;
|
||||
|
||||
int write_offset = 0;
|
||||
|
@ -604,7 +605,7 @@ BOOST_AUTO_TEST_CASE( test_FramedTransport_Write_Read ) {
|
|||
}
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned int)read_offset, sizeof(data));
|
||||
BOOST_CHECK(!memcmp(data, data_out, sizeof(data)));
|
||||
BOOST_CHECK(!memcmp(data, &data_out[0], sizeof(data)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
31
vendor/git.apache.org/thrift.git/lib/cpp/test/TFileTransportTest.cpp
generated
vendored
31
vendor/git.apache.org/thrift.git/lib/cpp/test/TFileTransportTest.cpp
generated
vendored
|
@ -53,20 +53,6 @@ FsyncLog* fsync_log;
|
|||
* Helper code
|
||||
**************************************************************************/
|
||||
|
||||
// Provide BOOST_WARN_LT() and BOOST_WARN_GT(), in case we're compiled
|
||||
// with an older version of boost
|
||||
#ifndef BOOST_WARN_LT
|
||||
#define BOOST_WARN_CMP(a, b, op, check_fn) \
|
||||
check_fn((a)op(b), \
|
||||
"check " BOOST_STRINGIZE(a) " " BOOST_STRINGIZE(op) " " BOOST_STRINGIZE( \
|
||||
b) " failed: " BOOST_STRINGIZE(a) "=" \
|
||||
<< (a) << " " BOOST_STRINGIZE(b) "=" << (b))
|
||||
|
||||
#define BOOST_WARN_LT(a, b) BOOST_WARN_CMP(a, b, <, BOOST_WARN_MESSAGE)
|
||||
#define BOOST_WARN_GT(a, b) BOOST_WARN_CMP(a, b, >, BOOST_WARN_MESSAGE)
|
||||
#define BOOST_WARN_LT(a, b) BOOST_WARN_CMP(a, b, <, BOOST_WARN_MESSAGE)
|
||||
#endif // BOOST_WARN_LT
|
||||
|
||||
/**
|
||||
* Class to record calls to fsync
|
||||
*/
|
||||
|
@ -83,7 +69,7 @@ public:
|
|||
void fsync(int fd) {
|
||||
(void)fd;
|
||||
FsyncCall call;
|
||||
gettimeofday(&call.time, NULL);
|
||||
THRIFT_GETTIMEOFDAY(&call.time, NULL);
|
||||
calls_.push_back(call);
|
||||
}
|
||||
|
||||
|
@ -100,6 +86,7 @@ class TempFile {
|
|||
public:
|
||||
TempFile(const char* directory, const char* prefix) {
|
||||
#ifdef __MINGW32__
|
||||
((void)directory);
|
||||
size_t path_len = strlen(prefix) + 8;
|
||||
path_ = new char[path_len];
|
||||
snprintf(path_, path_len, "%sXXXXXX", prefix);
|
||||
|
@ -208,16 +195,16 @@ BOOST_AUTO_TEST_CASE(test_destructor) {
|
|||
struct timeval start;
|
||||
struct timeval end;
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
THRIFT_GETTIMEOFDAY(&start, NULL);
|
||||
delete transport;
|
||||
gettimeofday(&end, NULL);
|
||||
THRIFT_GETTIMEOFDAY(&end, NULL);
|
||||
|
||||
int delta = time_diff(&start, &end);
|
||||
|
||||
// If any attempt takes more than 500ms, treat that as a failure.
|
||||
// Treat this as a fatal failure, so we'll return now instead of
|
||||
// looping over a very slow operation.
|
||||
BOOST_WARN_LT(delta, 500000);
|
||||
BOOST_WARN( delta < 500000 );
|
||||
|
||||
// Normally, it takes less than 100ms on my dev box.
|
||||
// However, if the box is heavily loaded, some of the test runs
|
||||
|
@ -295,7 +282,7 @@ void test_flush_max_us_impl(uint32_t flush_us, uint32_t write_us, uint32_t test_
|
|||
for (FsyncLog::CallList::const_iterator it = calls->begin(); it != calls->end(); ++it) {
|
||||
if (prev_time) {
|
||||
int delta = time_diff(prev_time, &it->time);
|
||||
BOOST_WARN_LT(delta, max_allowed_delta);
|
||||
BOOST_WARN( delta < max_allowed_delta );
|
||||
}
|
||||
prev_time = &it->time;
|
||||
}
|
||||
|
@ -331,13 +318,13 @@ BOOST_AUTO_TEST_CASE(test_noop_flush) {
|
|||
transport.write(buf, 1);
|
||||
|
||||
struct timeval start;
|
||||
gettimeofday(&start, NULL);
|
||||
THRIFT_GETTIMEOFDAY(&start, NULL);
|
||||
|
||||
for (unsigned int n = 0; n < 10; ++n) {
|
||||
transport.flush();
|
||||
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
THRIFT_GETTIMEOFDAY(&now, NULL);
|
||||
|
||||
// Fail if at any point we've been running for longer than half a second.
|
||||
// (With the buggy code, TFileTransport used to take 3 seconds per flush())
|
||||
|
@ -345,7 +332,7 @@ BOOST_AUTO_TEST_CASE(test_noop_flush) {
|
|||
// Use a fatal fail so we break out early, rather than continuing to make
|
||||
// many more slow flush() calls.
|
||||
int delta = time_diff(&start, &now);
|
||||
BOOST_WARN_LT(delta, 2000000);
|
||||
BOOST_WARN( delta < 2000000 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
63
vendor/git.apache.org/thrift.git/lib/cpp/test/TMemoryBufferTest.cpp
generated
vendored
63
vendor/git.apache.org/thrift.git/lib/cpp/test/TMemoryBufferTest.cpp
generated
vendored
|
@ -21,8 +21,9 @@
|
|||
#include <iostream>
|
||||
#include <climits>
|
||||
#include <vector>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include "gen-cpp/ThriftTest_types.h"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TMemoryBufferTest)
|
||||
|
@ -30,7 +31,7 @@ BOOST_AUTO_TEST_SUITE(TMemoryBufferTest)
|
|||
using apache::thrift::protocol::TBinaryProtocol;
|
||||
using apache::thrift::transport::TMemoryBuffer;
|
||||
using apache::thrift::transport::TTransportException;
|
||||
using boost::shared_ptr;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
@ -79,19 +80,11 @@ BOOST_AUTO_TEST_CASE(test_roundtrip) {
|
|||
BOOST_CHECK(a == a2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_copy) {
|
||||
BOOST_AUTO_TEST_CASE(test_readAppendToString) {
|
||||
string* str1 = new string("abcd1234");
|
||||
const char* data1 = str1->data();
|
||||
TMemoryBuffer buf((uint8_t*)str1->data(),
|
||||
static_cast<uint32_t>(str1->length()),
|
||||
TMemoryBuffer::COPY);
|
||||
delete str1;
|
||||
string* str2 = new string("plsreuse");
|
||||
bool obj_reuse = (str1 == str2);
|
||||
bool dat_reuse = (data1 == str2->data());
|
||||
BOOST_TEST_MESSAGE("Object reuse: " << obj_reuse << " Data reuse: " << dat_reuse
|
||||
<< ((obj_reuse && dat_reuse) ? " YAY!" : ""));
|
||||
delete str2;
|
||||
|
||||
string str3 = "wxyz", str4 = "6789";
|
||||
buf.readAppendToString(str3, 4);
|
||||
|
@ -116,4 +109,52 @@ BOOST_AUTO_TEST_CASE(test_exceptions) {
|
|||
BOOST_CHECK_NO_THROW(buf2.write((const uint8_t*)"bar", 3));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_default_maximum_buffer_size)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(std::numeric_limits<uint32_t>::max(), TMemoryBuffer().getMaxBufferSize());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_default_buffer_size)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(1024, TMemoryBuffer().getBufferSize());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_error_set_max_buffer_size_too_small)
|
||||
{
|
||||
TMemoryBuffer buf;
|
||||
BOOST_CHECK_THROW(buf.setMaxBufferSize(buf.getBufferSize() - 1), TTransportException);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_maximum_buffer_size)
|
||||
{
|
||||
TMemoryBuffer buf;
|
||||
buf.setMaxBufferSize(8192);
|
||||
std::vector<uint8_t> small_buff(1);
|
||||
|
||||
for (size_t i = 0; i < 8192; ++i)
|
||||
{
|
||||
buf.write(&small_buff[0], 1);
|
||||
}
|
||||
|
||||
BOOST_CHECK_THROW(buf.write(&small_buff[0], 1), TTransportException);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_memory_buffer_to_get_sizeof_objects)
|
||||
{
|
||||
// This is a demonstration of how to use TMemoryBuffer to determine
|
||||
// the serialized size of a thrift object in the Binary protocol.
|
||||
// See THRIFT-3480
|
||||
|
||||
shared_ptr<TMemoryBuffer> memBuffer(new TMemoryBuffer());
|
||||
shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(memBuffer));
|
||||
|
||||
thrift::test::Xtruct object;
|
||||
object.i32_thing = 10;
|
||||
object.i64_thing = 30;
|
||||
object.string_thing = "who's your daddy?";
|
||||
|
||||
uint32_t size = object.write(binaryProtcol.get());
|
||||
BOOST_CHECK_EQUAL(47, size);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
293
vendor/git.apache.org/thrift.git/lib/cpp/test/TNonblockingSSLServerTest.cpp
generated
vendored
Normal file
293
vendor/git.apache.org/thrift.git/lib/cpp/test/TNonblockingSSLServerTest.cpp
generated
vendored
Normal file
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE TNonblockingSSLServerTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "thrift/server/TNonblockingServer.h"
|
||||
#include "thrift/transport/TSSLSocket.h"
|
||||
#include "thrift/transport/TNonblockingSSLServerSocket.h"
|
||||
|
||||
#include "gen-cpp/ParentService.h"
|
||||
|
||||
#include <event.h>
|
||||
|
||||
using namespace apache::thrift;
|
||||
using apache::thrift::concurrency::Guard;
|
||||
using apache::thrift::concurrency::Monitor;
|
||||
using apache::thrift::concurrency::Mutex;
|
||||
using apache::thrift::server::TServerEventHandler;
|
||||
using apache::thrift::transport::TSSLSocketFactory;
|
||||
using apache::thrift::transport::TSSLSocket;
|
||||
|
||||
struct Handler : public test::ParentServiceIf {
|
||||
void addString(const std::string& s) { strings_.push_back(s); }
|
||||
void getStrings(std::vector<std::string>& _return) { _return = strings_; }
|
||||
std::vector<std::string> strings_;
|
||||
|
||||
// dummy overrides not used in this test
|
||||
int32_t incrementGeneration() { return 0; }
|
||||
int32_t getGeneration() { return 0; }
|
||||
void getDataWait(std::string&, const int32_t) {}
|
||||
void onewayWait() {}
|
||||
void exceptionWait(const std::string&) {}
|
||||
void unexpectedExceptionWait(const std::string&) {}
|
||||
};
|
||||
|
||||
boost::filesystem::path keyDir;
|
||||
boost::filesystem::path certFile(const std::string& filename)
|
||||
{
|
||||
return keyDir / filename;
|
||||
}
|
||||
|
||||
struct GlobalFixtureSSL
|
||||
{
|
||||
GlobalFixtureSSL()
|
||||
{
|
||||
using namespace boost::unit_test::framework;
|
||||
for (int i = 0; i < master_test_suite().argc; ++i)
|
||||
{
|
||||
BOOST_TEST_MESSAGE(boost::format("argv[%1%] = \"%2%\"") % i % master_test_suite().argv[i]);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
// OpenSSL calls send() without MSG_NOSIGPIPE so writing to a socket that has
|
||||
// disconnected can cause a SIGPIPE signal...
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
TSSLSocketFactory::setManualOpenSSLInitialization(true);
|
||||
apache::thrift::transport::initializeOpenSSL();
|
||||
|
||||
keyDir = boost::filesystem::current_path().parent_path().parent_path().parent_path() / "test" / "keys";
|
||||
if (!boost::filesystem::exists(certFile("server.crt")))
|
||||
{
|
||||
keyDir = boost::filesystem::path(master_test_suite().argv[master_test_suite().argc - 1]);
|
||||
if (!boost::filesystem::exists(certFile("server.crt")))
|
||||
{
|
||||
throw std::invalid_argument("The last argument to this test must be the directory containing the test certificate(s).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~GlobalFixtureSSL()
|
||||
{
|
||||
apache::thrift::transport::cleanupOpenSSL();
|
||||
#ifdef __linux__
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#if (BOOST_VERSION >= 105900)
|
||||
BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL);
|
||||
#else
|
||||
BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL)
|
||||
#endif
|
||||
|
||||
stdcxx::shared_ptr<TSSLSocketFactory> createServerSocketFactory() {
|
||||
stdcxx::shared_ptr<TSSLSocketFactory> pServerSocketFactory;
|
||||
|
||||
pServerSocketFactory.reset(new TSSLSocketFactory());
|
||||
pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||
pServerSocketFactory->loadCertificate(certFile("server.crt").string().c_str());
|
||||
pServerSocketFactory->loadPrivateKey(certFile("server.key").string().c_str());
|
||||
pServerSocketFactory->server(true);
|
||||
return pServerSocketFactory;
|
||||
}
|
||||
|
||||
stdcxx::shared_ptr<TSSLSocketFactory> createClientSocketFactory() {
|
||||
stdcxx::shared_ptr<TSSLSocketFactory> pClientSocketFactory;
|
||||
|
||||
pClientSocketFactory.reset(new TSSLSocketFactory());
|
||||
pClientSocketFactory->authenticate(true);
|
||||
pClientSocketFactory->loadCertificate(certFile("client.crt").string().c_str());
|
||||
pClientSocketFactory->loadPrivateKey(certFile("client.key").string().c_str());
|
||||
pClientSocketFactory->loadTrustedCertificates(certFile("CA.pem").string().c_str());
|
||||
return pClientSocketFactory;
|
||||
}
|
||||
|
||||
class Fixture {
|
||||
private:
|
||||
struct ListenEventHandler : public TServerEventHandler {
|
||||
public:
|
||||
ListenEventHandler(Mutex* mutex) : listenMonitor_(mutex), ready_(false) {}
|
||||
|
||||
void preServe() /* override */ {
|
||||
Guard g(listenMonitor_.mutex());
|
||||
ready_ = true;
|
||||
listenMonitor_.notify();
|
||||
}
|
||||
|
||||
Monitor listenMonitor_;
|
||||
bool ready_;
|
||||
};
|
||||
|
||||
struct Runner : public apache::thrift::concurrency::Runnable {
|
||||
int port;
|
||||
stdcxx::shared_ptr<event_base> userEventBase;
|
||||
stdcxx::shared_ptr<TProcessor> processor;
|
||||
stdcxx::shared_ptr<server::TNonblockingServer> server;
|
||||
stdcxx::shared_ptr<ListenEventHandler> listenHandler;
|
||||
stdcxx::shared_ptr<TSSLSocketFactory> pServerSocketFactory;
|
||||
stdcxx::shared_ptr<transport::TNonblockingSSLServerSocket> socket;
|
||||
Mutex mutex_;
|
||||
|
||||
Runner() {
|
||||
listenHandler.reset(new ListenEventHandler(&mutex_));
|
||||
}
|
||||
|
||||
virtual void run() {
|
||||
// When binding to explicit port, allow retrying to workaround bind failures on ports in use
|
||||
int retryCount = port ? 10 : 0;
|
||||
pServerSocketFactory = createServerSocketFactory();
|
||||
startServer(retryCount);
|
||||
}
|
||||
|
||||
void readyBarrier() {
|
||||
// block until server is listening and ready to accept connections
|
||||
Guard g(mutex_);
|
||||
while (!listenHandler->ready_) {
|
||||
listenHandler->listenMonitor_.wait();
|
||||
}
|
||||
}
|
||||
private:
|
||||
void startServer(int retry_count) {
|
||||
try {
|
||||
socket.reset(new transport::TNonblockingSSLServerSocket(port, pServerSocketFactory));
|
||||
server.reset(new server::TNonblockingServer(processor, socket));
|
||||
server->setServerEventHandler(listenHandler);
|
||||
server->setNumIOThreads(1);
|
||||
if (userEventBase) {
|
||||
server->registerEvents(userEventBase.get());
|
||||
}
|
||||
server->serve();
|
||||
} catch (const transport::TTransportException&) {
|
||||
if (retry_count > 0) {
|
||||
++port;
|
||||
startServer(retry_count - 1);
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct EventDeleter {
|
||||
void operator()(event_base* p) { event_base_free(p); }
|
||||
};
|
||||
|
||||
protected:
|
||||
Fixture() : processor(new test::ParentServiceProcessor(stdcxx::make_shared<Handler>())) {}
|
||||
|
||||
~Fixture() {
|
||||
if (server) {
|
||||
server->stop();
|
||||
}
|
||||
if (thread) {
|
||||
thread->join();
|
||||
}
|
||||
}
|
||||
|
||||
void setEventBase(event_base* user_event_base) {
|
||||
userEventBase_.reset(user_event_base, EventDeleter());
|
||||
}
|
||||
|
||||
int startServer(int port) {
|
||||
stdcxx::shared_ptr<Runner> runner(new Runner);
|
||||
runner->port = port;
|
||||
runner->processor = processor;
|
||||
runner->userEventBase = userEventBase_;
|
||||
|
||||
apache::thrift::stdcxx::scoped_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory(
|
||||
#if !USE_BOOST_THREAD && !USE_STD_THREAD
|
||||
concurrency::PlatformThreadFactory::OTHER, concurrency::PlatformThreadFactory::NORMAL,
|
||||
1,
|
||||
#endif
|
||||
false));
|
||||
thread = threadFactory->newThread(runner);
|
||||
thread->start();
|
||||
runner->readyBarrier();
|
||||
|
||||
server = runner->server;
|
||||
return runner->port;
|
||||
}
|
||||
|
||||
bool canCommunicate(int serverPort) {
|
||||
stdcxx::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
stdcxx::shared_ptr<TSSLSocket> socket = pClientSocketFactory->createSocket("localhost", serverPort);
|
||||
socket->open();
|
||||
test::ParentServiceClient client(stdcxx::make_shared<protocol::TBinaryProtocol>(
|
||||
stdcxx::make_shared<transport::TFramedTransport>(socket)));
|
||||
client.addString("foo");
|
||||
std::vector<std::string> strings;
|
||||
client.getStrings(strings);
|
||||
return strings.size() == 1 && !(strings[0].compare("foo"));
|
||||
}
|
||||
|
||||
private:
|
||||
stdcxx::shared_ptr<event_base> userEventBase_;
|
||||
stdcxx::shared_ptr<test::ParentServiceProcessor> processor;
|
||||
protected:
|
||||
stdcxx::shared_ptr<server::TNonblockingServer> server;
|
||||
private:
|
||||
stdcxx::shared_ptr<apache::thrift::concurrency::Thread> thread;
|
||||
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TNonblockingSSLServerTest)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(get_specified_port, Fixture) {
|
||||
int specified_port = startServer(12345);
|
||||
BOOST_REQUIRE_GE(specified_port, 12345);
|
||||
BOOST_REQUIRE_EQUAL(server->getListenPort(), specified_port);
|
||||
BOOST_CHECK(canCommunicate(specified_port));
|
||||
|
||||
server->stop();
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(get_assigned_port, Fixture) {
|
||||
int specified_port = startServer(0);
|
||||
BOOST_REQUIRE_EQUAL(specified_port, 0);
|
||||
int assigned_port = server->getListenPort();
|
||||
BOOST_REQUIRE_NE(assigned_port, 0);
|
||||
BOOST_CHECK(canCommunicate(assigned_port));
|
||||
|
||||
server->stop();
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(provide_event_base, Fixture) {
|
||||
event_base* eb = event_base_new();
|
||||
setEventBase(eb);
|
||||
startServer(0);
|
||||
|
||||
// assert that the server works
|
||||
BOOST_CHECK(canCommunicate(server->getListenPort()));
|
||||
#if LIBEVENT_VERSION_NUMBER > 0x02010400
|
||||
// also assert that the event_base is actually used when it's easy
|
||||
BOOST_CHECK_GT(event_base_get_num_events(eb, EVENT_BASE_COUNT_ADDED), 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
85
vendor/git.apache.org/thrift.git/lib/cpp/test/TNonblockingServerTest.cpp
generated
vendored
85
vendor/git.apache.org/thrift.git/lib/cpp/test/TNonblockingServerTest.cpp
generated
vendored
|
@ -19,15 +19,28 @@
|
|||
|
||||
#define BOOST_TEST_MODULE TNonblockingServerTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
#include "thrift/concurrency/Monitor.h"
|
||||
#include "thrift/concurrency/Thread.h"
|
||||
#include "thrift/server/TNonblockingServer.h"
|
||||
#include "thrift/transport/TNonblockingServerSocket.h"
|
||||
#include "thrift/stdcxx.h"
|
||||
|
||||
#include "gen-cpp/ParentService.h"
|
||||
|
||||
#include <event.h>
|
||||
|
||||
using apache::thrift::concurrency::Guard;
|
||||
using apache::thrift::concurrency::Monitor;
|
||||
using apache::thrift::concurrency::Mutex;
|
||||
using apache::thrift::concurrency::PlatformThreadFactory;
|
||||
using apache::thrift::concurrency::Runnable;
|
||||
using apache::thrift::concurrency::Thread;
|
||||
using apache::thrift::concurrency::ThreadFactory;
|
||||
using apache::thrift::server::TServerEventHandler;
|
||||
using apache::thrift::stdcxx::make_shared;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
using namespace apache::thrift;
|
||||
|
||||
struct Handler : public test::ParentServiceIf {
|
||||
|
@ -46,11 +59,32 @@ struct Handler : public test::ParentServiceIf {
|
|||
|
||||
class Fixture {
|
||||
private:
|
||||
struct Runner : public apache::thrift::concurrency::Runnable {
|
||||
struct ListenEventHandler : public TServerEventHandler {
|
||||
public:
|
||||
ListenEventHandler(Mutex* mutex) : listenMonitor_(mutex), ready_(false) {}
|
||||
|
||||
void preServe() /* override */ {
|
||||
Guard g(listenMonitor_.mutex());
|
||||
ready_ = true;
|
||||
listenMonitor_.notify();
|
||||
}
|
||||
|
||||
Monitor listenMonitor_;
|
||||
bool ready_;
|
||||
};
|
||||
|
||||
struct Runner : public Runnable {
|
||||
int port;
|
||||
boost::shared_ptr<event_base> userEventBase;
|
||||
boost::shared_ptr<TProcessor> processor;
|
||||
boost::shared_ptr<server::TNonblockingServer> server;
|
||||
shared_ptr<event_base> userEventBase;
|
||||
shared_ptr<TProcessor> processor;
|
||||
shared_ptr<server::TNonblockingServer> server;
|
||||
shared_ptr<ListenEventHandler> listenHandler;
|
||||
shared_ptr<transport::TNonblockingServerSocket> socket;
|
||||
Mutex mutex_;
|
||||
|
||||
Runner() {
|
||||
listenHandler.reset(new ListenEventHandler(&mutex_));
|
||||
}
|
||||
|
||||
virtual void run() {
|
||||
// When binding to explicit port, allow retrying to workaround bind failures on ports in use
|
||||
|
@ -58,10 +92,19 @@ private:
|
|||
startServer(retryCount);
|
||||
}
|
||||
|
||||
void readyBarrier() {
|
||||
// block until server is listening and ready to accept connections
|
||||
Guard g(mutex_);
|
||||
while (!listenHandler->ready_) {
|
||||
listenHandler->listenMonitor_.wait();
|
||||
}
|
||||
}
|
||||
private:
|
||||
void startServer(int retry_count) {
|
||||
try {
|
||||
server.reset(new server::TNonblockingServer(processor, port));
|
||||
socket.reset(new transport::TNonblockingServerSocket(port));
|
||||
server.reset(new server::TNonblockingServer(processor, socket));
|
||||
server->setServerEventHandler(listenHandler);
|
||||
if (userEventBase) {
|
||||
server->registerEvents(userEventBase.get());
|
||||
}
|
||||
|
@ -82,7 +125,7 @@ private:
|
|||
};
|
||||
|
||||
protected:
|
||||
Fixture() : processor(new test::ParentServiceProcessor(boost::make_shared<Handler>())) {}
|
||||
Fixture() : processor(new test::ParentServiceProcessor(make_shared<Handler>())) {}
|
||||
|
||||
~Fixture() {
|
||||
if (server) {
|
||||
|
@ -98,31 +141,31 @@ protected:
|
|||
}
|
||||
|
||||
int startServer(int port) {
|
||||
boost::shared_ptr<Runner> runner(new Runner);
|
||||
shared_ptr<Runner> runner(new Runner);
|
||||
runner->port = port;
|
||||
runner->processor = processor;
|
||||
runner->userEventBase = userEventBase_;
|
||||
|
||||
boost::scoped_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory(
|
||||
shared_ptr<ThreadFactory> threadFactory(
|
||||
new PlatformThreadFactory(
|
||||
#if !USE_BOOST_THREAD && !USE_STD_THREAD
|
||||
concurrency::PlatformThreadFactory::OTHER, concurrency::PlatformThreadFactory::NORMAL,
|
||||
PlatformThreadFactory::OTHER, PlatformThreadFactory::NORMAL,
|
||||
1,
|
||||
#endif
|
||||
false));
|
||||
thread = threadFactory->newThread(runner);
|
||||
thread->start();
|
||||
// wait 100 ms for the server to begin listening
|
||||
THRIFT_SLEEP_USEC(100000);
|
||||
runner->readyBarrier();
|
||||
|
||||
server = runner->server;
|
||||
return runner->port;
|
||||
}
|
||||
|
||||
bool canCommunicate(int serverPort) {
|
||||
boost::shared_ptr<transport::TSocket> socket(new transport::TSocket("localhost", serverPort));
|
||||
shared_ptr<transport::TSocket> socket(new transport::TSocket("localhost", serverPort));
|
||||
socket->open();
|
||||
test::ParentServiceClient client(boost::make_shared<protocol::TBinaryProtocol>(
|
||||
boost::make_shared<transport::TFramedTransport>(socket)));
|
||||
test::ParentServiceClient client(make_shared<protocol::TBinaryProtocol>(
|
||||
make_shared<transport::TFramedTransport>(socket)));
|
||||
client.addString("foo");
|
||||
std::vector<std::string> strings;
|
||||
client.getStrings(strings);
|
||||
|
@ -130,12 +173,12 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
boost::shared_ptr<event_base> userEventBase_;
|
||||
boost::shared_ptr<test::ParentServiceProcessor> processor;
|
||||
shared_ptr<event_base> userEventBase_;
|
||||
shared_ptr<test::ParentServiceProcessor> processor;
|
||||
protected:
|
||||
boost::shared_ptr<server::TNonblockingServer> server;
|
||||
shared_ptr<server::TNonblockingServer> server;
|
||||
private:
|
||||
boost::shared_ptr<apache::thrift::concurrency::Thread> thread;
|
||||
shared_ptr<apache::thrift::concurrency::Thread> thread;
|
||||
|
||||
};
|
||||
|
||||
|
@ -148,7 +191,6 @@ BOOST_FIXTURE_TEST_CASE(get_specified_port, Fixture) {
|
|||
BOOST_CHECK(canCommunicate(specified_port));
|
||||
|
||||
server->stop();
|
||||
BOOST_CHECK_EQUAL(server->getListenPort(), specified_port);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(get_assigned_port, Fixture) {
|
||||
|
@ -159,7 +201,6 @@ BOOST_FIXTURE_TEST_CASE(get_assigned_port, Fixture) {
|
|||
BOOST_CHECK(canCommunicate(assigned_port));
|
||||
|
||||
server->stop();
|
||||
BOOST_CHECK_EQUAL(server->getListenPort(), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(provide_event_base, Fixture) {
|
||||
|
|
9
vendor/git.apache.org/thrift.git/lib/cpp/test/TPipeInterruptTest.cpp
generated
vendored
9
vendor/git.apache.org/thrift.git/lib/cpp/test/TPipeInterruptTest.cpp
generated
vendored
|
@ -22,17 +22,18 @@
|
|||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/chrono/duration.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <thrift/transport/TPipe.h>
|
||||
#include <thrift/transport/TPipeServer.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
using apache::thrift::transport::TPipeServer;
|
||||
using apache::thrift::transport::TPipe;
|
||||
using apache::thrift::transport::TTransport;
|
||||
using apache::thrift::transport::TTransportException;
|
||||
using namespace apache::thrift;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TPipeInterruptTest)
|
||||
|
||||
|
@ -51,7 +52,7 @@ static void acceptWorker(TPipeServer *pipe) {
|
|||
{
|
||||
for (;;)
|
||||
{
|
||||
boost::shared_ptr<TTransport> temp = pipe->accept();
|
||||
stdcxx::shared_ptr<TTransport> temp = pipe->accept();
|
||||
}
|
||||
}
|
||||
catch (...) {/*just want to make sure nothing crashes*/ }
|
||||
|
@ -69,8 +70,8 @@ BOOST_AUTO_TEST_CASE(stress_pipe_accept_interruption) {
|
|||
{
|
||||
TPipeServer pipeServer("TPipeInterruptTest");
|
||||
pipeServer.listen();
|
||||
boost::thread acceptThread(boost::bind(acceptWorker, &pipeServer));
|
||||
boost::thread interruptThread(boost::bind(interruptWorker, &pipeServer));
|
||||
boost::thread acceptThread(stdcxx::bind(acceptWorker, &pipeServer));
|
||||
boost::thread interruptThread(stdcxx::bind(interruptWorker, &pipeServer));
|
||||
try
|
||||
{
|
||||
for (;;)
|
||||
|
|
8
vendor/git.apache.org/thrift.git/lib/cpp/test/TPipedTransportTest.cpp
generated
vendored
8
vendor/git.apache.org/thrift.git/lib/cpp/test/TPipedTransportTest.cpp
generated
vendored
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <thrift/Thrift.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TTransportUtils.h>
|
||||
#include <thrift/transport/TBufferTransports.h>
|
||||
|
||||
|
@ -27,11 +28,12 @@
|
|||
using apache::thrift::transport::TTransportException;
|
||||
using apache::thrift::transport::TPipedTransport;
|
||||
using apache::thrift::transport::TMemoryBuffer;
|
||||
using namespace apache::thrift;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_read_write) {
|
||||
boost::shared_ptr<TMemoryBuffer> underlying(new TMemoryBuffer);
|
||||
boost::shared_ptr<TMemoryBuffer> pipe(new TMemoryBuffer);
|
||||
boost::shared_ptr<TPipedTransport> trans(new TPipedTransport(underlying, pipe));
|
||||
stdcxx::shared_ptr<TMemoryBuffer> underlying(new TMemoryBuffer);
|
||||
stdcxx::shared_ptr<TMemoryBuffer> pipe(new TMemoryBuffer);
|
||||
stdcxx::shared_ptr<TPipedTransport> trans(new TPipedTransport(underlying, pipe));
|
||||
|
||||
uint8_t buffer[4];
|
||||
|
||||
|
|
80
vendor/git.apache.org/thrift.git/lib/cpp/test/TSSLSocketInterruptTest.cpp
generated
vendored
80
vendor/git.apache.org/thrift.git/lib/cpp/test/TSSLSocketInterruptTest.cpp
generated
vendored
|
@ -19,13 +19,12 @@
|
|||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/chrono/duration.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/transport/TSSLSocket.h>
|
||||
#include <thrift/transport/TSSLServerSocket.h>
|
||||
#ifdef __linux__
|
||||
|
@ -38,6 +37,9 @@ using apache::thrift::transport::TTransport;
|
|||
using apache::thrift::transport::TTransportException;
|
||||
using apache::thrift::transport::TSSLSocketFactory;
|
||||
|
||||
using apache::thrift::stdcxx::static_pointer_cast;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TSSLSocketInterruptTest)
|
||||
|
||||
boost::filesystem::path keyDir;
|
||||
|
@ -92,7 +94,7 @@ BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL);
|
|||
BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL)
|
||||
#endif
|
||||
|
||||
void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) {
|
||||
void readerWorker(shared_ptr<TTransport> tt, uint32_t expectedResult) {
|
||||
uint8_t buf[4];
|
||||
try {
|
||||
tt->read(buf, 1);
|
||||
|
@ -102,7 +104,7 @@ void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) {
|
|||
}
|
||||
}
|
||||
|
||||
void readerWorkerMustThrow(boost::shared_ptr<TTransport> tt) {
|
||||
void readerWorkerMustThrow(shared_ptr<TTransport> tt) {
|
||||
try {
|
||||
uint8_t buf[400];
|
||||
tt->read(buf, 1);
|
||||
|
@ -113,8 +115,8 @@ void readerWorkerMustThrow(boost::shared_ptr<TTransport> tt) {
|
|||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<TSSLSocketFactory> createServerSocketFactory() {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory;
|
||||
shared_ptr<TSSLSocketFactory> createServerSocketFactory() {
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory;
|
||||
|
||||
pServerSocketFactory.reset(new TSSLSocketFactory());
|
||||
pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||
|
@ -124,8 +126,8 @@ boost::shared_ptr<TSSLSocketFactory> createServerSocketFactory() {
|
|||
return pServerSocketFactory;
|
||||
}
|
||||
|
||||
boost::shared_ptr<TSSLSocketFactory> createClientSocketFactory() {
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory;
|
||||
shared_ptr<TSSLSocketFactory> createClientSocketFactory() {
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory;
|
||||
|
||||
pClientSocketFactory.reset(new TSSLSocketFactory());
|
||||
pClientSocketFactory->authenticate(true);
|
||||
|
@ -136,15 +138,15 @@ boost::shared_ptr<TSSLSocketFactory> createClientSocketFactory() {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read_while_handshaking) {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
|
||||
sock1.listen();
|
||||
int port = sock1.getPort();
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
clientSock->open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted));
|
||||
shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(apache::thrift::stdcxx::bind(readerWorkerMustThrow, accepted));
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// readThread is practically guaranteed to be blocking now
|
||||
sock1.interruptChildren();
|
||||
|
@ -156,15 +158,15 @@ BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read_while_handshaking) {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read) {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
|
||||
sock1.listen();
|
||||
int port = sock1.getPort();
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
clientSock->open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted));
|
||||
shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(apache::thrift::stdcxx::bind(readerWorkerMustThrow, accepted));
|
||||
clientSock->write((const uint8_t*)"0", 1);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// readThread is practically guaranteed to be blocking now
|
||||
|
@ -177,17 +179,17 @@ BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read) {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_read) {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
|
||||
sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
|
||||
sock1.listen();
|
||||
int port = sock1.getPort();
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
clientSock->open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::static_pointer_cast<TSSLSocket>(accepted)->setRecvTimeout(1000);
|
||||
boost::thread readThread(boost::bind(readerWorker, accepted, 0));
|
||||
shared_ptr<TTransport> accepted = sock1.accept();
|
||||
static_pointer_cast<TSSLSocket>(accepted)->setRecvTimeout(1000);
|
||||
boost::thread readThread(apache::thrift::stdcxx::bind(readerWorker, accepted, 0));
|
||||
clientSock->write((const uint8_t*)"0", 1);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// readThread is practically guaranteed to be blocking here
|
||||
|
@ -203,24 +205,24 @@ BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_read) {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ssl_cannot_change_after_listen) {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
|
||||
sock1.listen();
|
||||
BOOST_CHECK_THROW(sock1.setInterruptableChildren(false), std::logic_error);
|
||||
sock1.close();
|
||||
}
|
||||
|
||||
void peekerWorker(boost::shared_ptr<TTransport> tt, bool expectedResult) {
|
||||
void peekerWorker(shared_ptr<TTransport> tt, bool expectedResult) {
|
||||
uint8_t buf[400];
|
||||
try {
|
||||
tt->read(buf, 1);
|
||||
tt->peek();
|
||||
BOOST_CHECK_EQUAL(expectedResult, tt->peek());
|
||||
} catch (const TTransportException& tx) {
|
||||
BOOST_CHECK_EQUAL(TTransportException::TIMED_OUT, tx.getType());
|
||||
}
|
||||
}
|
||||
|
||||
void peekerWorkerInterrupt(boost::shared_ptr<TTransport> tt) {
|
||||
void peekerWorkerInterrupt(shared_ptr<TTransport> tt) {
|
||||
uint8_t buf[400];
|
||||
try {
|
||||
tt->read(buf, 1);
|
||||
|
@ -231,15 +233,15 @@ void peekerWorkerInterrupt(boost::shared_ptr<TTransport> tt) {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_peek) {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
|
||||
sock1.listen();
|
||||
int port = sock1.getPort();
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
clientSock->open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread peekThread(boost::bind(peekerWorkerInterrupt, accepted));
|
||||
shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread peekThread(apache::thrift::stdcxx::bind(peekerWorkerInterrupt, accepted));
|
||||
clientSock->write((const uint8_t*)"0", 1);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// peekThread is practically guaranteed to be blocking now
|
||||
|
@ -252,17 +254,17 @@ BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_peek) {
|
|||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_peek) {
|
||||
boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
|
||||
TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
|
||||
sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
|
||||
sock1.listen();
|
||||
int port = sock1.getPort();
|
||||
boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
|
||||
shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
|
||||
clientSock->open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::static_pointer_cast<TSSLSocket>(accepted)->setRecvTimeout(1000);
|
||||
boost::thread peekThread(boost::bind(peekerWorker, accepted, false));
|
||||
shared_ptr<TTransport> accepted = sock1.accept();
|
||||
static_pointer_cast<TSSLSocket>(accepted)->setRecvTimeout(1000);
|
||||
boost::thread peekThread(apache::thrift::stdcxx::bind(peekerWorker, accepted, false));
|
||||
clientSock->write((const uint8_t*)"0", 1);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// peekThread is practically guaranteed to be blocking now
|
||||
|
|
108
vendor/git.apache.org/thrift.git/lib/cpp/test/TServerIntegrationTest.cpp
generated
vendored
108
vendor/git.apache.org/thrift.git/lib/cpp/test/TServerIntegrationTest.cpp
generated
vendored
|
@ -20,16 +20,14 @@
|
|||
#define BOOST_TEST_MODULE TServerIntegrationTest
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/atomic.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <thrift/server/TSimpleServer.h>
|
||||
#include <thrift/server/TThreadPoolServer.h>
|
||||
#include <thrift/server/TThreadedServer.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/transport/TServerSocket.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
|
@ -57,6 +55,9 @@ using apache::thrift::server::TServerEventHandler;
|
|||
using apache::thrift::server::TSimpleServer;
|
||||
using apache::thrift::server::TThreadPoolServer;
|
||||
using apache::thrift::server::TThreadedServer;
|
||||
using apache::thrift::stdcxx::dynamic_pointer_cast;
|
||||
using apache::thrift::stdcxx::make_shared;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using apache::thrift::test::ParentServiceClient;
|
||||
using apache::thrift::test::ParentServiceIf;
|
||||
using apache::thrift::test::ParentServiceIfFactory;
|
||||
|
@ -79,8 +80,8 @@ public:
|
|||
isListening_ = true;
|
||||
notify();
|
||||
}
|
||||
virtual void* createContext(boost::shared_ptr<TProtocol> input,
|
||||
boost::shared_ptr<TProtocol> output) {
|
||||
virtual void* createContext(shared_ptr<TProtocol> input,
|
||||
shared_ptr<TProtocol> output) {
|
||||
Synchronized sync(*this);
|
||||
++accepted_;
|
||||
notify();
|
||||
|
@ -149,26 +150,26 @@ void autoSocketCloser(TSocket* pSock) {
|
|||
template <class TServerType>
|
||||
class TServerIntegrationTestFixture {
|
||||
public:
|
||||
TServerIntegrationTestFixture(const boost::shared_ptr<TProcessorFactory>& _processorFactory)
|
||||
TServerIntegrationTestFixture(const shared_ptr<TProcessorFactory>& _processorFactory)
|
||||
: pServer(new TServerType(_processorFactory,
|
||||
boost::shared_ptr<TServerTransport>(
|
||||
shared_ptr<TServerTransport>(
|
||||
new TServerSocket("localhost", 0)),
|
||||
boost::shared_ptr<TTransportFactory>(new TTransportFactory),
|
||||
boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))),
|
||||
pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)),
|
||||
shared_ptr<TTransportFactory>(new TTransportFactory),
|
||||
shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))),
|
||||
pEventHandler(shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)),
|
||||
bStressDone(false),
|
||||
bStressConnectionCount(0),
|
||||
bStressRequestCount(0) {
|
||||
pServer->setServerEventHandler(pEventHandler);
|
||||
}
|
||||
|
||||
TServerIntegrationTestFixture(const boost::shared_ptr<TProcessor>& _processor)
|
||||
TServerIntegrationTestFixture(const shared_ptr<TProcessor>& _processor)
|
||||
: pServer(
|
||||
new TServerType(_processor,
|
||||
boost::shared_ptr<TServerTransport>(new TServerSocket("localhost", 0)),
|
||||
boost::shared_ptr<TTransportFactory>(new TTransportFactory),
|
||||
boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))),
|
||||
pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)),
|
||||
shared_ptr<TServerTransport>(new TServerSocket("localhost", 0)),
|
||||
shared_ptr<TTransportFactory>(new TTransportFactory),
|
||||
shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))),
|
||||
pEventHandler(shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)),
|
||||
bStressDone(false),
|
||||
bStressConnectionCount(0),
|
||||
bStressRequestCount(0) {
|
||||
|
@ -176,7 +177,7 @@ public:
|
|||
}
|
||||
|
||||
void startServer() {
|
||||
pServerThread.reset(new boost::thread(boost::bind(&TServerType::serve, pServer.get())));
|
||||
pServerThread.reset(new boost::thread(apache::thrift::stdcxx::bind(&TServerType::serve, pServer.get())));
|
||||
|
||||
// block until listen() completes so clients will be able to connect
|
||||
Synchronized sync(*(pEventHandler.get()));
|
||||
|
@ -222,19 +223,19 @@ public:
|
|||
|
||||
startServer();
|
||||
|
||||
std::vector<boost::shared_ptr<TSocket> > holdSockets;
|
||||
std::vector<boost::shared_ptr<boost::thread> > holdThreads;
|
||||
std::vector<shared_ptr<TSocket> > holdSockets;
|
||||
std::vector<shared_ptr<boost::thread> > holdThreads;
|
||||
|
||||
for (int64_t i = 0; i < numToMake; ++i) {
|
||||
boost::shared_ptr<TSocket> pClientSock(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
holdSockets.push_back(pClientSock);
|
||||
boost::shared_ptr<TProtocol> pClientProtocol(new TBinaryProtocol(pClientSock));
|
||||
shared_ptr<TProtocol> pClientProtocol(new TBinaryProtocol(pClientSock));
|
||||
ParentServiceClient client(pClientProtocol);
|
||||
pClientSock->open();
|
||||
client.incrementGeneration();
|
||||
holdThreads.push_back(boost::shared_ptr<boost::thread>(
|
||||
new boost::thread(boost::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
holdThreads.push_back(shared_ptr<boost::thread>(
|
||||
new boost::thread(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
this,
|
||||
pClientSock,
|
||||
milliseconds(10 * numToMake)))));
|
||||
|
@ -242,7 +243,7 @@ public:
|
|||
|
||||
BOOST_CHECK_EQUAL(expectedHWM, pServer->getConcurrentClientCountHWM());
|
||||
|
||||
BOOST_FOREACH (boost::shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); }
|
||||
BOOST_FOREACH (shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); }
|
||||
holdThreads.clear();
|
||||
holdSockets.clear();
|
||||
|
||||
|
@ -254,7 +255,7 @@ public:
|
|||
* \param[in] toClose the connection to close
|
||||
* \param[in] after the delay to impose
|
||||
*/
|
||||
void delayClose(boost::shared_ptr<TTransport> toClose, boost::posix_time::time_duration after) {
|
||||
void delayClose(shared_ptr<TTransport> toClose, boost::posix_time::time_duration after) {
|
||||
boost::this_thread::sleep(after);
|
||||
toClose->close();
|
||||
}
|
||||
|
@ -264,6 +265,7 @@ public:
|
|||
*/
|
||||
int getServerPort() {
|
||||
TServerSocket* pSock = dynamic_cast<TServerSocket*>(pServer->getServerTransport().get());
|
||||
if (!pSock) { throw std::logic_error("how come?"); }
|
||||
return pSock->getPort();
|
||||
}
|
||||
|
||||
|
@ -279,10 +281,10 @@ public:
|
|||
|
||||
startServer();
|
||||
|
||||
std::vector<boost::shared_ptr<boost::thread> > holdThreads;
|
||||
std::vector<shared_ptr<boost::thread> > holdThreads;
|
||||
for (int64_t i = 0; i < numToMake; ++i) {
|
||||
holdThreads.push_back(boost::shared_ptr<boost::thread>(
|
||||
new boost::thread(boost::bind(&TServerIntegrationTestFixture::stressor, this))));
|
||||
holdThreads.push_back(shared_ptr<boost::thread>(
|
||||
new boost::thread(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::stressor, this))));
|
||||
}
|
||||
|
||||
boost::this_thread::sleep(duration);
|
||||
|
@ -291,7 +293,7 @@ public:
|
|||
BOOST_TEST_MESSAGE(boost::format(" serviced %1% connections (HWM %2%) totaling %3% requests")
|
||||
% bStressConnectionCount % pServer->getConcurrentClientCountHWM() % bStressRequestCount);
|
||||
|
||||
BOOST_FOREACH (boost::shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); }
|
||||
BOOST_FOREACH (shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); }
|
||||
holdThreads.clear();
|
||||
|
||||
BOOST_CHECK(bStressRequestCount > 0);
|
||||
|
@ -304,8 +306,8 @@ public:
|
|||
*/
|
||||
void stressor() {
|
||||
while (!bStressDone) {
|
||||
boost::shared_ptr<TSocket> pSocket(new TSocket("localhost", getServerPort()), autoSocketCloser);
|
||||
boost::shared_ptr<TProtocol> pProtocol(new TBinaryProtocol(pSocket));
|
||||
shared_ptr<TSocket> pSocket(new TSocket("localhost", getServerPort()), autoSocketCloser);
|
||||
shared_ptr<TProtocol> pProtocol(new TBinaryProtocol(pSocket));
|
||||
ParentServiceClient client(pProtocol);
|
||||
pSocket->open();
|
||||
bStressConnectionCount.fetch_add(1, boost::memory_order_relaxed);
|
||||
|
@ -316,10 +318,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<TServerType> pServer;
|
||||
boost::shared_ptr<TServerReadyEventHandler> pEventHandler;
|
||||
boost::shared_ptr<boost::thread> pServerThread;
|
||||
bool bStressDone;
|
||||
shared_ptr<TServerType> pServer;
|
||||
shared_ptr<TServerReadyEventHandler> pEventHandler;
|
||||
shared_ptr<boost::thread> pServerThread;
|
||||
boost::atomic<bool> bStressDone;
|
||||
boost::atomic_int64_t bStressConnectionCount;
|
||||
boost::atomic_int64_t bStressRequestCount;
|
||||
};
|
||||
|
@ -329,9 +331,9 @@ class TServerIntegrationProcessorFactoryTestFixture
|
|||
: public TServerIntegrationTestFixture<TServerType> {
|
||||
public:
|
||||
TServerIntegrationProcessorFactoryTestFixture()
|
||||
: TServerIntegrationTestFixture<TServerType>(boost::make_shared<ParentServiceProcessorFactory>(
|
||||
boost::make_shared<ParentServiceIfSingletonFactory>(
|
||||
boost::make_shared<ParentHandler>()))) {}
|
||||
: TServerIntegrationTestFixture<TServerType>(make_shared<ParentServiceProcessorFactory>(
|
||||
make_shared<ParentServiceIfSingletonFactory>(
|
||||
make_shared<ParentHandler>()))) {}
|
||||
};
|
||||
|
||||
template <class TServerType>
|
||||
|
@ -339,7 +341,7 @@ class TServerIntegrationProcessorTestFixture : public TServerIntegrationTestFixt
|
|||
public:
|
||||
TServerIntegrationProcessorTestFixture()
|
||||
: TServerIntegrationTestFixture<TServerType>(
|
||||
boost::make_shared<ParentServiceProcessor>(boost::make_shared<ParentHandler>())) {}
|
||||
make_shared<ParentServiceProcessor>(make_shared<ParentHandler>())) {}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(constructors)
|
||||
|
@ -376,7 +378,7 @@ BOOST_FIXTURE_TEST_CASE(test_threaded_stress,
|
|||
BOOST_FIXTURE_TEST_CASE(test_threadpool_factory,
|
||||
TServerIntegrationProcessorFactoryTestFixture<TThreadPoolServer>) {
|
||||
pServer->getThreadManager()->threadFactory(
|
||||
boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory));
|
||||
pServer->getThreadManager()->start();
|
||||
|
||||
|
@ -391,7 +393,7 @@ BOOST_FIXTURE_TEST_CASE(test_threadpool_factory,
|
|||
BOOST_FIXTURE_TEST_CASE(test_threadpool,
|
||||
TServerIntegrationProcessorTestFixture<TThreadPoolServer>) {
|
||||
pServer->getThreadManager()->threadFactory(
|
||||
boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory));
|
||||
pServer->getThreadManager()->start();
|
||||
|
||||
|
@ -406,7 +408,7 @@ BOOST_FIXTURE_TEST_CASE(test_threadpool,
|
|||
BOOST_FIXTURE_TEST_CASE(test_threadpool_bound,
|
||||
TServerIntegrationProcessorTestFixture<TThreadPoolServer>) {
|
||||
pServer->getThreadManager()->threadFactory(
|
||||
boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory));
|
||||
pServer->getThreadManager()->start();
|
||||
pServer->setConcurrentClientLimit(4);
|
||||
|
@ -417,7 +419,7 @@ BOOST_FIXTURE_TEST_CASE(test_threadpool_bound,
|
|||
BOOST_FIXTURE_TEST_CASE(test_threadpool_stress,
|
||||
TServerIntegrationProcessorTestFixture<TThreadPoolServer>) {
|
||||
pServer->getThreadManager()->threadFactory(
|
||||
boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
shared_ptr<apache::thrift::concurrency::ThreadFactory>(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory));
|
||||
pServer->getThreadManager()->start();
|
||||
|
||||
|
@ -435,11 +437,11 @@ BOOST_AUTO_TEST_CASE(test_stop_with_interruptable_clients_connected) {
|
|||
|
||||
startServer();
|
||||
|
||||
boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock1->open();
|
||||
|
||||
boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock2->open();
|
||||
|
||||
|
@ -461,27 +463,27 @@ BOOST_AUTO_TEST_CASE(test_stop_with_uninterruptable_clients_connected) {
|
|||
// disconnect.
|
||||
BOOST_TEST_MESSAGE("Testing stop with uninterruptable clients");
|
||||
|
||||
boost::dynamic_pointer_cast<TServerSocket>(pServer->getServerTransport())
|
||||
dynamic_pointer_cast<TServerSocket>(pServer->getServerTransport())
|
||||
->setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
|
||||
|
||||
startServer();
|
||||
|
||||
boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock1->open();
|
||||
|
||||
boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock2->open();
|
||||
|
||||
// Ensure they have been accepted
|
||||
blockUntilAccepted(2);
|
||||
|
||||
boost::thread t1(boost::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
boost::thread t1(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
this,
|
||||
pClientSock1,
|
||||
milliseconds(250)));
|
||||
boost::thread t2(boost::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
boost::thread t2(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
this,
|
||||
pClientSock2,
|
||||
milliseconds(250)));
|
||||
|
@ -502,24 +504,24 @@ BOOST_AUTO_TEST_CASE(test_concurrent_client_limit) {
|
|||
BOOST_CHECK_EQUAL(0, pServer->getConcurrentClientCount());
|
||||
BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientLimit());
|
||||
|
||||
boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock1->open();
|
||||
blockUntilAccepted(1);
|
||||
BOOST_CHECK_EQUAL(1, pServer->getConcurrentClientCount());
|
||||
|
||||
boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock2->open();
|
||||
blockUntilAccepted(2);
|
||||
BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount());
|
||||
|
||||
// a third client cannot connect until one of the other two closes
|
||||
boost::thread t2(boost::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
boost::thread t2(apache::thrift::stdcxx::bind(&TServerIntegrationTestFixture::delayClose,
|
||||
this,
|
||||
pClientSock2,
|
||||
milliseconds(250)));
|
||||
boost::shared_ptr<TSocket> pClientSock3(new TSocket("localhost", getServerPort()),
|
||||
shared_ptr<TSocket> pClientSock3(new TSocket("localhost", getServerPort()),
|
||||
autoSocketCloser);
|
||||
pClientSock2->open();
|
||||
blockUntilAccepted(2);
|
||||
|
|
4
vendor/git.apache.org/thrift.git/lib/cpp/test/TServerSocketTest.cpp
generated
vendored
4
vendor/git.apache.org/thrift.git/lib/cpp/test/TServerSocketTest.cpp
generated
vendored
|
@ -20,6 +20,7 @@
|
|||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/transport/TServerSocket.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
#include "TTransportCheckThrow.h"
|
||||
#include <iostream>
|
||||
|
||||
|
@ -27,6 +28,7 @@ using apache::thrift::transport::TServerSocket;
|
|||
using apache::thrift::transport::TSocket;
|
||||
using apache::thrift::transport::TTransport;
|
||||
using apache::thrift::transport::TTransportException;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TServerSocketTest)
|
||||
|
||||
|
@ -36,7 +38,7 @@ BOOST_AUTO_TEST_CASE(test_bind_to_address) {
|
|||
int port = sock1.getPort();
|
||||
TSocket clientSock("localhost", port);
|
||||
clientSock.open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
shared_ptr<TTransport> accepted = sock1.accept();
|
||||
accepted->close();
|
||||
sock1.close();
|
||||
|
||||
|
|
8
vendor/git.apache.org/thrift.git/lib/cpp/test/TServerTransportTest.cpp
generated
vendored
8
vendor/git.apache.org/thrift.git/lib/cpp/test/TServerTransportTest.cpp
generated
vendored
|
@ -20,10 +20,12 @@
|
|||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/transport/TServerTransport.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
using apache::thrift::transport::TServerTransport;
|
||||
using apache::thrift::transport::TTransport;
|
||||
using apache::thrift::transport::TTransportException;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TServerTransportTest)
|
||||
|
||||
|
@ -36,9 +38,9 @@ public:
|
|||
bool valid_;
|
||||
|
||||
protected:
|
||||
boost::shared_ptr<TTransport> acceptImpl() {
|
||||
return valid_ ? boost::shared_ptr<TestTTransport>(new TestTTransport)
|
||||
: boost::shared_ptr<TestTTransport>();
|
||||
shared_ptr<TTransport> acceptImpl() {
|
||||
return valid_ ? shared_ptr<TestTTransport>(new TestTTransport)
|
||||
: shared_ptr<TestTTransport>();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
25
vendor/git.apache.org/thrift.git/lib/cpp/test/TSocketInterruptTest.cpp
generated
vendored
25
vendor/git.apache.org/thrift.git/lib/cpp/test/TSocketInterruptTest.cpp
generated
vendored
|
@ -20,26 +20,27 @@
|
|||
#define BOOST_TEST_MODULE TSocketInterruptTest
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/chrono/duration.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/transport/TServerSocket.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
using apache::thrift::transport::TServerSocket;
|
||||
using apache::thrift::transport::TSocket;
|
||||
using apache::thrift::transport::TTransport;
|
||||
using apache::thrift::transport::TTransportException;
|
||||
using namespace apache::thrift;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TSocketInterruptTest)
|
||||
|
||||
void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) {
|
||||
void readerWorker(stdcxx::shared_ptr<TTransport> tt, uint32_t expectedResult) {
|
||||
uint8_t buf[4];
|
||||
BOOST_CHECK_EQUAL(expectedResult, tt->read(buf, 4));
|
||||
}
|
||||
|
||||
void readerWorkerMustThrow(boost::shared_ptr<TTransport> tt) {
|
||||
void readerWorkerMustThrow(stdcxx::shared_ptr<TTransport> tt) {
|
||||
try {
|
||||
uint8_t buf[4];
|
||||
tt->read(buf, 4);
|
||||
|
@ -55,8 +56,8 @@ BOOST_AUTO_TEST_CASE(test_interruptable_child_read) {
|
|||
int port = sock1.getPort();
|
||||
TSocket clientSock("localhost", port);
|
||||
clientSock.open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted));
|
||||
stdcxx::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(stdcxx::bind(readerWorkerMustThrow, accepted));
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// readThread is practically guaranteed to be blocking now
|
||||
sock1.interruptChildren();
|
||||
|
@ -74,8 +75,8 @@ BOOST_AUTO_TEST_CASE(test_non_interruptable_child_read) {
|
|||
int port = sock1.getPort();
|
||||
TSocket clientSock("localhost", port);
|
||||
clientSock.open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(boost::bind(readerWorker, accepted, 0));
|
||||
stdcxx::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
boost::thread readThread(stdcxx::bind(readerWorker, accepted, 0));
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// readThread is practically guaranteed to be blocking here
|
||||
sock1.interruptChildren();
|
||||
|
@ -96,7 +97,7 @@ BOOST_AUTO_TEST_CASE(test_cannot_change_after_listen) {
|
|||
sock1.close();
|
||||
}
|
||||
|
||||
void peekerWorker(boost::shared_ptr<TTransport> tt, bool expectedResult) {
|
||||
void peekerWorker(stdcxx::shared_ptr<TTransport> tt, bool expectedResult) {
|
||||
BOOST_CHECK_EQUAL(expectedResult, tt->peek());
|
||||
}
|
||||
|
||||
|
@ -106,9 +107,9 @@ BOOST_AUTO_TEST_CASE(test_interruptable_child_peek) {
|
|||
int port = sock1.getPort();
|
||||
TSocket clientSock("localhost", port);
|
||||
clientSock.open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
stdcxx::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
// peek() will return false if child is interrupted
|
||||
boost::thread peekThread(boost::bind(peekerWorker, accepted, false));
|
||||
boost::thread peekThread(stdcxx::bind(peekerWorker, accepted, false));
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// peekThread is practically guaranteed to be blocking now
|
||||
sock1.interruptChildren();
|
||||
|
@ -126,9 +127,9 @@ BOOST_AUTO_TEST_CASE(test_non_interruptable_child_peek) {
|
|||
int port = sock1.getPort();
|
||||
TSocket clientSock("localhost", port);
|
||||
clientSock.open();
|
||||
boost::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
stdcxx::shared_ptr<TTransport> accepted = sock1.accept();
|
||||
// peek() will return false when remote side is closed
|
||||
boost::thread peekThread(boost::bind(peekerWorker, accepted, false));
|
||||
boost::thread peekThread(stdcxx::bind(peekerWorker, accepted, false));
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
// peekThread is practically guaranteed to be blocking now
|
||||
sock1.interruptChildren();
|
||||
|
|
55
vendor/git.apache.org/thrift.git/lib/cpp/test/TransportTest.cpp
generated
vendored
55
vendor/git.apache.org/thrift.git/lib/cpp/test/TransportTest.cpp
generated
vendored
|
@ -26,7 +26,7 @@
|
|||
#endif
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <thrift/cxxfunctional.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
#include <boost/mpl/list.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
|
@ -43,10 +43,12 @@
|
|||
|
||||
#include <thrift/concurrency/FunctionRunner.h>
|
||||
#if _WIN32
|
||||
#include <thrift/transport/TPipe.h>
|
||||
#include <thrift/windows/TWinsockSingleton.h>
|
||||
#endif
|
||||
|
||||
using namespace apache::thrift::transport;
|
||||
using namespace apache::thrift;
|
||||
|
||||
static boost::mt19937 rng;
|
||||
|
||||
|
@ -112,7 +114,7 @@ public:
|
|||
std::string describe() const { return generator_->describe(); }
|
||||
|
||||
private:
|
||||
boost::shared_ptr<SizeGenerator> generator_;
|
||||
stdcxx::shared_ptr<SizeGenerator> generator_;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -135,8 +137,8 @@ public:
|
|||
|
||||
CoupledTransports() : in(), out() {}
|
||||
|
||||
boost::shared_ptr<Transport_> in;
|
||||
boost::shared_ptr<Transport_> out;
|
||||
stdcxx::shared_ptr<Transport_> in;
|
||||
stdcxx::shared_ptr<Transport_> out;
|
||||
|
||||
private:
|
||||
CoupledTransports(const CoupledTransports&);
|
||||
|
@ -153,7 +155,7 @@ public:
|
|||
out = buf;
|
||||
}
|
||||
|
||||
boost::shared_ptr<TMemoryBuffer> buf;
|
||||
stdcxx::shared_ptr<TMemoryBuffer> buf;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -219,6 +221,22 @@ public:
|
|||
out.reset(new TFDTransport(pipes[1], TFDTransport::CLOSE_ON_DESTROY));
|
||||
}
|
||||
};
|
||||
#else
|
||||
/**
|
||||
* Coupled pipe transports
|
||||
*/
|
||||
class CoupledPipeTransports : public CoupledTransports<TPipe> {
|
||||
public:
|
||||
HANDLE hRead;
|
||||
HANDLE hWrite;
|
||||
|
||||
CoupledPipeTransports() {
|
||||
BOOST_REQUIRE(CreatePipe(&hRead, &hWrite, NULL, 1048576 * 2));
|
||||
in.reset(new TPipe(hRead, hWrite));
|
||||
in->open();
|
||||
out = in;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -323,11 +341,11 @@ public:
|
|||
**************************************************************************/
|
||||
|
||||
struct TriggerInfo {
|
||||
TriggerInfo(int seconds, const boost::shared_ptr<TTransport>& transport, uint32_t writeLength)
|
||||
TriggerInfo(int seconds, const stdcxx::shared_ptr<TTransport>& transport, uint32_t writeLength)
|
||||
: timeoutSeconds(seconds), transport(transport), writeLength(writeLength), next(NULL) {}
|
||||
|
||||
int timeoutSeconds;
|
||||
boost::shared_ptr<TTransport> transport;
|
||||
stdcxx::shared_ptr<TTransport> transport;
|
||||
uint32_t writeLength;
|
||||
TriggerInfo* next;
|
||||
};
|
||||
|
@ -402,7 +420,7 @@ void alarm_handler_wrapper() {
|
|||
* to the end.)
|
||||
*/
|
||||
void add_trigger(unsigned int seconds,
|
||||
const boost::shared_ptr<TTransport>& transport,
|
||||
const stdcxx::shared_ptr<TTransport>& transport,
|
||||
uint32_t write_len) {
|
||||
TriggerInfo* info = new TriggerInfo(seconds, transport, write_len);
|
||||
{
|
||||
|
@ -442,7 +460,7 @@ void clear_triggers() {
|
|||
}
|
||||
|
||||
void set_trigger(unsigned int seconds,
|
||||
const boost::shared_ptr<TTransport>& transport,
|
||||
const stdcxx::shared_ptr<TTransport>& transport,
|
||||
uint32_t write_len) {
|
||||
clear_triggers();
|
||||
add_trigger(seconds, transport, write_len);
|
||||
|
@ -840,6 +858,19 @@ public:
|
|||
TEST_RW(CoupledFDTransports, 1024 * 16, 1, 1, rand4k, rand4k, fd_max_outstanding);
|
||||
|
||||
TEST_BLOCKING_BEHAVIOR(CoupledFDTransports);
|
||||
#else
|
||||
// TPipe tests (WIN32 only)
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 1024, 0, 0);
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 256, rand4k, rand4k);
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 256, 167, 163);
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 16, 1, 1);
|
||||
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 256, 0, 0, rand4k, rand4k);
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 256, rand4k, rand4k, rand4k, rand4k);
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 256, 167, 163, rand4k, rand4k);
|
||||
TEST_RW(CoupledPipeTransports, 1024 * 16, 1, 1, rand4k, rand4k);
|
||||
|
||||
TEST_BLOCKING_BEHAVIOR(CoupledPipeTransports);
|
||||
#endif //_WIN32
|
||||
|
||||
// TSocket tests
|
||||
|
@ -945,11 +976,11 @@ private:
|
|||
<< rChunkSizeGen.describe() << ", " << maxOutstanding << ")";
|
||||
|
||||
#if (BOOST_VERSION >= 105900)
|
||||
boost::function<void ()> test_func
|
||||
stdcxx::function<void ()> test_func
|
||||
#else
|
||||
boost::unit_test::callback0<> test_func
|
||||
#endif
|
||||
= apache::thrift::stdcxx::bind(test_rw<CoupledTransports>,
|
||||
= stdcxx::bind(test_rw<CoupledTransports>,
|
||||
totalSize,
|
||||
wSizeGen,
|
||||
rSizeGen,
|
||||
|
@ -995,7 +1026,7 @@ private:
|
|||
**************************************************************************/
|
||||
|
||||
struct global_fixture {
|
||||
boost::shared_ptr<apache::thrift::concurrency::Thread> alarmThread_;
|
||||
stdcxx::shared_ptr<apache::thrift::concurrency::Thread> alarmThread_;
|
||||
global_fixture() {
|
||||
#if _WIN32
|
||||
apache::thrift::transport::TWinsockSingleton::create();
|
||||
|
|
64
vendor/git.apache.org/thrift.git/lib/cpp/test/ZlibTest.cpp
generated
vendored
64
vendor/git.apache.org/thrift.git/lib/cpp/test/ZlibTest.cpp
generated
vendored
|
@ -17,22 +17,27 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE // needed for getopt_long
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1700)
|
||||
// polynomial and std::fill_t warning happens in MSVC 2010, 2013, maybe others
|
||||
// https://svn.boost.org/trac/boost/ticket/11426
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <thrift/cxxfunctional.h>
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/random.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
@ -41,8 +46,9 @@
|
|||
#include <thrift/transport/TBufferTransports.h>
|
||||
#include <thrift/transport/TZlibTransport.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace apache::thrift::transport;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using std::string;
|
||||
|
||||
boost::mt19937 rng;
|
||||
|
||||
|
@ -141,8 +147,8 @@ boost::shared_array<uint8_t> gen_random_buffer(uint32_t buf_len) {
|
|||
*/
|
||||
|
||||
void test_write_then_read(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
zlib_trans->write(buf.get(), buf_len);
|
||||
zlib_trans->finish();
|
||||
|
||||
|
@ -160,8 +166,8 @@ void test_separate_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf
|
|||
// it isn't there. The original implementation complained that
|
||||
// the stream was not complete. I'm about to go fix that.
|
||||
// It worked. Awesome.
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
zlib_trans->write(buf.get(), buf_len);
|
||||
zlib_trans->finish();
|
||||
string tmp_buf;
|
||||
|
@ -180,8 +186,8 @@ void test_separate_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf
|
|||
void test_incomplete_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
|
||||
// Make sure we still get that "not complete" error if
|
||||
// it really isn't complete.
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
zlib_trans->write(buf.get(), buf_len);
|
||||
zlib_trans->finish();
|
||||
string tmp_buf;
|
||||
|
@ -204,11 +210,11 @@ void test_incomplete_checksum(const boost::shared_array<uint8_t> buf, uint32_t b
|
|||
|
||||
void test_read_write_mix(const boost::shared_array<uint8_t> buf,
|
||||
uint32_t buf_len,
|
||||
const boost::shared_ptr<SizeGenerator>& write_gen,
|
||||
const boost::shared_ptr<SizeGenerator>& read_gen) {
|
||||
const shared_ptr<SizeGenerator>& write_gen,
|
||||
const shared_ptr<SizeGenerator>& read_gen) {
|
||||
// Try it with a mix of read/write sizes.
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
unsigned int tot;
|
||||
|
||||
tot = 0;
|
||||
|
@ -243,8 +249,8 @@ void test_read_write_mix(const boost::shared_array<uint8_t> buf,
|
|||
|
||||
void test_invalid_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
|
||||
// Verify checksum checking.
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
zlib_trans->write(buf.get(), buf_len);
|
||||
zlib_trans->finish();
|
||||
string tmp_buf;
|
||||
|
@ -280,8 +286,8 @@ void test_invalid_checksum(const boost::shared_array<uint8_t> buf, uint32_t buf_
|
|||
|
||||
void test_write_after_flush(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
|
||||
// write some data
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
zlib_trans->write(buf.get(), buf_len);
|
||||
|
||||
// call finish()
|
||||
|
@ -316,7 +322,7 @@ void test_write_after_flush(const boost::shared_array<uint8_t> buf, uint32_t buf
|
|||
void test_no_write() {
|
||||
// Verify that no data is written to the underlying transport if we
|
||||
// never write data to the TZlibTransport.
|
||||
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
{
|
||||
// Create a TZlibTransport object, and immediately destroy it
|
||||
// when it goes out of scope.
|
||||
|
@ -326,6 +332,12 @@ void test_no_write() {
|
|||
BOOST_CHECK_EQUAL(membuf->available_read(), (uint32_t)0);
|
||||
}
|
||||
|
||||
void test_get_underlying_transport() {
|
||||
shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
|
||||
shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
|
||||
BOOST_CHECK_EQUAL(membuf.get(), zlib_trans->getUnderlyingTransport().get());
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
|
@ -335,7 +347,8 @@ void test_no_write() {
|
|||
do { \
|
||||
::std::ostringstream name_ss; \
|
||||
name_ss << name << "-" << BOOST_STRINGIZE(_FUNC); \
|
||||
boost::function<void ()> test_func = ::apache::thrift::stdcxx::bind(_FUNC, ##__VA_ARGS__); \
|
||||
::apache::thrift::stdcxx::function<void ()> test_func = \
|
||||
::apache::thrift::stdcxx::bind(_FUNC, ##__VA_ARGS__); \
|
||||
::boost::unit_test::test_case* tc \
|
||||
= ::boost::unit_test::make_test_case(test_func, name_ss.str(), __FILE__, __LINE__); \
|
||||
(suite)->add(tc); \
|
||||
|
@ -363,8 +376,8 @@ void add_tests(boost::unit_test::test_suite* suite,
|
|||
ADD_TEST_CASE(suite, name, test_invalid_checksum, buf, buf_len);
|
||||
ADD_TEST_CASE(suite, name, test_write_after_flush, buf, buf_len);
|
||||
|
||||
boost::shared_ptr<SizeGenerator> size_32k(new ConstantSizeGenerator(1 << 15));
|
||||
boost::shared_ptr<SizeGenerator> size_lognormal(new LogNormalSizeGenerator(20, 30));
|
||||
shared_ptr<SizeGenerator> size_32k(new ConstantSizeGenerator(1 << 15));
|
||||
shared_ptr<SizeGenerator> size_lognormal(new LogNormalSizeGenerator(20, 30));
|
||||
ADD_TEST_CASE(suite, name << "-constant", test_read_write_mix, buf, buf_len, size_32k, size_32k);
|
||||
ADD_TEST_CASE(suite,
|
||||
name << "-lognormal-write",
|
||||
|
@ -394,8 +407,8 @@ void add_tests(boost::unit_test::test_suite* suite,
|
|||
// Because the SizeGenerator makes a copy of the random number generator,
|
||||
// both SizeGenerators should return the exact same set of values, since they
|
||||
// both start with random number generators in the same state.
|
||||
boost::shared_ptr<SizeGenerator> write_size_gen(new LogNormalSizeGenerator(20, 30));
|
||||
boost::shared_ptr<SizeGenerator> read_size_gen(new LogNormalSizeGenerator(20, 30));
|
||||
shared_ptr<SizeGenerator> write_size_gen(new LogNormalSizeGenerator(20, 30));
|
||||
shared_ptr<SizeGenerator> read_size_gen(new LogNormalSizeGenerator(20, 30));
|
||||
ADD_TEST_CASE(suite,
|
||||
name << "-lognormal-same-distribution",
|
||||
test_read_write_mix,
|
||||
|
@ -429,6 +442,7 @@ bool init_unit_test_suite() {
|
|||
add_tests(suite, gen_random_buffer(buf_len), buf_len, "random");
|
||||
|
||||
suite->add(BOOST_TEST_CASE(test_no_write));
|
||||
suite->add(BOOST_TEST_CASE(test_get_underlying_transport));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
123
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/MutexTest.cpp
generated
vendored
Normal file
123
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/MutexTest.cpp
generated
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// This is linked into the UnitTests test executable
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "thrift/concurrency/Exception.h"
|
||||
#include "thrift/concurrency/Mutex.h"
|
||||
|
||||
using boost::unit_test::test_suite;
|
||||
using boost::unit_test::framework::master_test_suite;
|
||||
|
||||
using namespace apache::thrift::concurrency;
|
||||
|
||||
struct LFAT
|
||||
{
|
||||
LFAT()
|
||||
: uut(Mutex::ERRORCHECK_INITIALIZER)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(0, pthread_mutex_init(&mx, 0));
|
||||
BOOST_CHECK_EQUAL(0, pthread_cond_init(&cv, 0));
|
||||
}
|
||||
|
||||
Mutex uut;
|
||||
pthread_mutex_t mx;
|
||||
pthread_cond_t cv;
|
||||
};
|
||||
|
||||
// Helper for testing mutex behavior when locked by another thread
|
||||
void * lockFromAnotherThread(void *ptr)
|
||||
{
|
||||
struct LFAT *lfat = (LFAT *)ptr;
|
||||
BOOST_CHECK_EQUAL (0, pthread_mutex_lock(&lfat->mx)); // synchronize with testing thread
|
||||
BOOST_CHECK_NO_THROW( lfat->uut.lock());
|
||||
BOOST_CHECK_EQUAL (0, pthread_cond_signal(&lfat->cv)); // tell testing thread we have locked the mutex
|
||||
BOOST_CHECK_EQUAL (0, pthread_cond_wait(&lfat->cv, &lfat->mx)); // wait for testing thread to signal condition variable telling us to unlock
|
||||
BOOST_CHECK_NO_THROW( lfat->uut.unlock());
|
||||
return ptr; // testing thread should join to ensure completeness
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(MutexTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(happy_path)
|
||||
{
|
||||
Mutex uut(Mutex::ERRORCHECK_INITIALIZER); // needed to test unlocking twice without undefined behavior
|
||||
|
||||
BOOST_CHECK_NO_THROW( uut.lock());
|
||||
BOOST_CHECK_THROW ( uut.lock(), SystemResourceException); // EDEADLK (this thread owns it)
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(recursive_happy_path)
|
||||
{
|
||||
Mutex uut(Mutex::RECURSIVE_INITIALIZER);
|
||||
|
||||
BOOST_CHECK_NO_THROW( uut.lock());
|
||||
BOOST_CHECK_NO_THROW( uut.lock());
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
BOOST_CHECK_NO_THROW( uut.lock());
|
||||
BOOST_CHECK_NO_THROW( uut.lock());
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
BOOST_CHECK_NO_THROW( uut.lock());
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(trylock)
|
||||
{
|
||||
Mutex uut(Mutex::ADAPTIVE_INITIALIZER); // just using another initializer for coverage
|
||||
|
||||
BOOST_CHECK ( uut.trylock());
|
||||
BOOST_CHECK (!uut.trylock());
|
||||
BOOST_CHECK_NO_THROW( uut.unlock());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(timedlock)
|
||||
{
|
||||
pthread_t th;
|
||||
struct LFAT lfat;
|
||||
|
||||
BOOST_CHECK ( lfat.uut.timedlock(100));
|
||||
BOOST_CHECK_THROW ( lfat.uut.timedlock(100),
|
||||
SystemResourceException); // EDEADLK (current thread owns mutex - logic error)
|
||||
BOOST_CHECK_NO_THROW( lfat.uut.unlock());
|
||||
|
||||
BOOST_CHECK_EQUAL (0, pthread_mutex_lock(&lfat.mx)); // synchronize with helper thread
|
||||
BOOST_CHECK_EQUAL (0, pthread_create(&th, NULL,
|
||||
lockFromAnotherThread, &lfat)); // create helper thread
|
||||
BOOST_CHECK_EQUAL (0, pthread_cond_wait(&lfat.cv, &lfat.mx)); // wait for helper thread to lock mutex
|
||||
|
||||
BOOST_CHECK (!lfat.uut.timedlock(100)); // false: another thread owns the lock
|
||||
|
||||
BOOST_CHECK_EQUAL (0, pthread_cond_signal(&lfat.cv)); // tell helper thread we are done
|
||||
BOOST_CHECK_EQUAL (0, pthread_mutex_unlock(&lfat.mx)); // let helper thread clean up
|
||||
BOOST_CHECK_EQUAL (0, pthread_join(th, 0)); // wait for testing thread to unlock and be done
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(underlying)
|
||||
{
|
||||
Mutex uut;
|
||||
|
||||
BOOST_CHECK ( uut.getUnderlyingImpl());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
|
@ -17,25 +17,23 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
// This is linked into the UnitTests test executable
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "thrift/concurrency/Mutex.h"
|
||||
#include "thrift/concurrency/PosixThreadFactory.h"
|
||||
#include <thrift/stdcxx.h>
|
||||
|
||||
using boost::shared_ptr;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
using boost::unit_test::test_suite;
|
||||
using boost::unit_test::framework::master_test_suite;
|
||||
|
||||
using namespace apache::thrift::concurrency;
|
||||
using namespace std;
|
||||
|
||||
class Locker : public Runnable {
|
||||
protected:
|
||||
Locker(boost::shared_ptr<ReadWriteMutex> rwlock, bool writer)
|
||||
Locker(shared_ptr<ReadWriteMutex> rwlock, bool writer)
|
||||
: rwlock_(rwlock), writer_(writer), started_(false), gotLock_(false), signaled_(false) {}
|
||||
|
||||
public:
|
||||
|
@ -58,7 +56,7 @@ public:
|
|||
void signal() { signaled_ = true; }
|
||||
|
||||
protected:
|
||||
boost::shared_ptr<ReadWriteMutex> rwlock_;
|
||||
shared_ptr<ReadWriteMutex> rwlock_;
|
||||
bool writer_;
|
||||
volatile bool started_;
|
||||
volatile bool gotLock_;
|
||||
|
@ -67,12 +65,12 @@ protected:
|
|||
|
||||
class Reader : public Locker {
|
||||
public:
|
||||
Reader(boost::shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, false) {}
|
||||
Reader(shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, false) {}
|
||||
};
|
||||
|
||||
class Writer : public Locker {
|
||||
public:
|
||||
Writer(boost::shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, true) {}
|
||||
Writer(shared_ptr<ReadWriteMutex> rwlock) : Locker(rwlock, true) {}
|
||||
};
|
||||
|
||||
void test_starve(PosixThreadFactory::POLICY policy) {
|
||||
|
@ -82,15 +80,15 @@ void test_starve(PosixThreadFactory::POLICY policy) {
|
|||
PosixThreadFactory factory(policy);
|
||||
factory.setDetached(false);
|
||||
|
||||
boost::shared_ptr<ReadWriteMutex> rwlock(new NoStarveReadWriteMutex());
|
||||
shared_ptr<ReadWriteMutex> rwlock(new NoStarveReadWriteMutex());
|
||||
|
||||
boost::shared_ptr<Reader> reader1(new Reader(rwlock));
|
||||
boost::shared_ptr<Reader> reader2(new Reader(rwlock));
|
||||
boost::shared_ptr<Writer> writer(new Writer(rwlock));
|
||||
shared_ptr<Reader> reader1(new Reader(rwlock));
|
||||
shared_ptr<Reader> reader2(new Reader(rwlock));
|
||||
shared_ptr<Writer> writer(new Writer(rwlock));
|
||||
|
||||
boost::shared_ptr<Thread> treader1 = factory.newThread(reader1);
|
||||
boost::shared_ptr<Thread> treader2 = factory.newThread(reader2);
|
||||
boost::shared_ptr<Thread> twriter = factory.newThread(writer);
|
||||
shared_ptr<Thread> treader1 = factory.newThread(reader1);
|
||||
shared_ptr<Thread> treader2 = factory.newThread(reader2);
|
||||
shared_ptr<Thread> twriter = factory.newThread(writer);
|
||||
|
||||
// launch a reader and make sure he has the lock
|
||||
treader1->start();
|
53
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/Tests.cpp
generated
vendored
53
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/Tests.cpp
generated
vendored
|
@ -25,6 +25,10 @@
|
|||
#include "TimerManagerTests.h"
|
||||
#include "ThreadManagerTests.h"
|
||||
|
||||
// The test weight, where 10 is 10 times more threads than baseline
|
||||
// and the baseline is optimized for running in valgrind
|
||||
static int WEIGHT = 10;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
std::string arg;
|
||||
|
@ -37,6 +41,11 @@ int main(int argc, char** argv) {
|
|||
args[ix - 1] = std::string(argv[ix]);
|
||||
}
|
||||
|
||||
if (getenv("VALGRIND") != 0) {
|
||||
// lower the scale of every test
|
||||
WEIGHT = 1;
|
||||
}
|
||||
|
||||
bool runAll = args[0].compare("all") == 0;
|
||||
|
||||
if (runAll || args[0].compare("thread-factory") == 0) {
|
||||
|
@ -45,10 +54,10 @@ int main(int argc, char** argv) {
|
|||
|
||||
std::cout << "ThreadFactory tests..." << std::endl;
|
||||
|
||||
int reapLoops = 20;
|
||||
int reapCount = 1000;
|
||||
int reapLoops = 2 * WEIGHT;
|
||||
int reapCount = 100 * WEIGHT;
|
||||
size_t floodLoops = 3;
|
||||
size_t floodCount = 20000;
|
||||
size_t floodCount = 500 * WEIGHT;
|
||||
|
||||
std::cout << "\t\tThreadFactory reap N threads test: N = " << reapLoops << "x" << reapCount << std::endl;
|
||||
|
||||
|
@ -114,6 +123,34 @@ int main(int argc, char** argv) {
|
|||
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\t\tTimerManager test01" << std::endl;
|
||||
|
||||
if (!timerManagerTests.test01()) {
|
||||
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\t\tTimerManager test02" << std::endl;
|
||||
|
||||
if (!timerManagerTests.test02()) {
|
||||
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\t\tTimerManager test03" << std::endl;
|
||||
|
||||
if (!timerManagerTests.test03()) {
|
||||
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\t\tTimerManager test04" << std::endl;
|
||||
|
||||
if (!timerManagerTests.test04()) {
|
||||
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (runAll || args[0].compare("thread-manager") == 0) {
|
||||
|
@ -121,8 +158,8 @@ int main(int argc, char** argv) {
|
|||
std::cout << "ThreadManager tests..." << std::endl;
|
||||
|
||||
{
|
||||
size_t workerCount = 100;
|
||||
size_t taskCount = 50000;
|
||||
size_t workerCount = 10 * WEIGHT;
|
||||
size_t taskCount = 500 * WEIGHT;
|
||||
int64_t delay = 10LL;
|
||||
|
||||
ThreadManagerTests threadManagerTests;
|
||||
|
@ -160,13 +197,13 @@ int main(int argc, char** argv) {
|
|||
|
||||
size_t minWorkerCount = 2;
|
||||
|
||||
size_t maxWorkerCount = 64;
|
||||
size_t maxWorkerCount = 8;
|
||||
|
||||
size_t tasksPerWorker = 1000;
|
||||
size_t tasksPerWorker = 100 * WEIGHT;
|
||||
|
||||
int64_t delay = 5LL;
|
||||
|
||||
for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount *= 4) {
|
||||
for (size_t workerCount = minWorkerCount; workerCount <= maxWorkerCount; workerCount *= 4) {
|
||||
|
||||
size_t taskCount = workerCount * tasksPerWorker;
|
||||
|
||||
|
|
46
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/ThreadFactoryTests.h
generated
vendored
46
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/ThreadFactoryTests.h
generated
vendored
|
@ -21,18 +21,19 @@
|
|||
#include <thrift/concurrency/Thread.h>
|
||||
#include <thrift/concurrency/PlatformThreadFactory.h>
|
||||
#include <thrift/concurrency/Monitor.h>
|
||||
#include <thrift/concurrency/Mutex.h>
|
||||
#include <thrift/concurrency/Util.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace apache {
|
||||
namespace thrift {
|
||||
namespace concurrency {
|
||||
namespace test {
|
||||
|
||||
using boost::shared_ptr;
|
||||
using stdcxx::shared_ptr;
|
||||
using namespace apache::thrift::concurrency;
|
||||
|
||||
/**
|
||||
|
@ -53,39 +54,33 @@ public:
|
|||
|
||||
void run() {
|
||||
Synchronized s(_monitor);
|
||||
|
||||
_count--;
|
||||
|
||||
// std::cout << "\t\t\tthread count: " << _count << std::endl;
|
||||
|
||||
if (_count == 0) {
|
||||
|
||||
if (--_count == 0) {
|
||||
_monitor.notify();
|
||||
}
|
||||
}
|
||||
|
||||
Monitor& _monitor;
|
||||
|
||||
int& _count;
|
||||
};
|
||||
|
||||
bool reapNThreads(int loop = 1, int count = 10) {
|
||||
|
||||
PlatformThreadFactory threadFactory = PlatformThreadFactory();
|
||||
|
||||
shared_ptr<Monitor> monitor(new Monitor);
|
||||
|
||||
for (int lix = 0; lix < loop; lix++) {
|
||||
|
||||
int* activeCount = new int(count);
|
||||
|
||||
std::set<shared_ptr<Thread> > threads;
|
||||
int activeCount = 0;
|
||||
|
||||
std::vector<shared_ptr<Thread> > threads;
|
||||
int tix;
|
||||
|
||||
for (tix = 0; tix < count; tix++) {
|
||||
try {
|
||||
threads.insert(
|
||||
threadFactory.newThread(shared_ptr<Runnable>(new ReapNTask(*monitor, *activeCount))));
|
||||
++activeCount;
|
||||
threads.push_back(
|
||||
threadFactory.newThread(shared_ptr<Runnable>(new ReapNTask(*monitor, activeCount))));
|
||||
} catch (SystemResourceException& e) {
|
||||
std::cout << "\t\t\tfailed to create " << lix* count + tix << " thread " << e.what()
|
||||
<< std::endl;
|
||||
|
@ -94,7 +89,7 @@ public:
|
|||
}
|
||||
|
||||
tix = 0;
|
||||
for (std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin();
|
||||
for (std::vector<shared_ptr<Thread> >::const_iterator thread = threads.begin();
|
||||
thread != threads.end();
|
||||
tix++, ++thread) {
|
||||
|
||||
|
@ -109,16 +104,15 @@ public:
|
|||
|
||||
{
|
||||
Synchronized s(*monitor);
|
||||
while (*activeCount > 0) {
|
||||
while (activeCount > 0) {
|
||||
monitor->wait(1000);
|
||||
}
|
||||
}
|
||||
delete activeCount;
|
||||
|
||||
std::cout << "\t\t\treaped " << lix* count << " threads" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "\t\t\tSuccess!" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -253,19 +247,22 @@ public:
|
|||
|
||||
class FloodTask : public Runnable {
|
||||
public:
|
||||
FloodTask(const size_t id) : _id(id) {}
|
||||
FloodTask(const size_t id, Monitor& mon) : _id(id), _mon(mon) {}
|
||||
~FloodTask() {
|
||||
if (_id % 10000 == 0) {
|
||||
Synchronized sync(_mon);
|
||||
std::cout << "\t\tthread " << _id << " done" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void run() {
|
||||
if (_id % 10000 == 0) {
|
||||
Synchronized sync(_mon);
|
||||
std::cout << "\t\tthread " << _id << " started" << std::endl;
|
||||
}
|
||||
}
|
||||
const size_t _id;
|
||||
Monitor& _mon;
|
||||
};
|
||||
|
||||
void foo(PlatformThreadFactory* tf) { (void)tf; }
|
||||
|
@ -273,7 +270,8 @@ public:
|
|||
bool floodNTest(size_t loop = 1, size_t count = 100000) {
|
||||
|
||||
bool success = false;
|
||||
|
||||
Monitor mon;
|
||||
|
||||
for (size_t lix = 0; lix < loop; lix++) {
|
||||
|
||||
PlatformThreadFactory threadFactory = PlatformThreadFactory();
|
||||
|
@ -283,10 +281,8 @@ public:
|
|||
|
||||
try {
|
||||
|
||||
shared_ptr<FloodTask> task(new FloodTask(lix * count + tix));
|
||||
|
||||
shared_ptr<FloodTask> task(new FloodTask(lix * count + tix, mon));
|
||||
shared_ptr<Thread> thread = threadFactory.newThread(task);
|
||||
|
||||
thread->start();
|
||||
|
||||
} catch (TException& e) {
|
||||
|
@ -298,8 +294,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
Synchronized sync(mon);
|
||||
std::cout << "\t\t\tflooded " << (lix + 1) * count << " threads" << std::endl;
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
||||
|
|
6
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/ThreadManagerTests.h
generated
vendored
6
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/ThreadManagerTests.h
generated
vendored
|
@ -36,8 +36,8 @@ namespace test {
|
|||
|
||||
using namespace apache::thrift::concurrency;
|
||||
|
||||
static std::deque<boost::shared_ptr<Runnable> > m_expired;
|
||||
static void expiredNotifier(boost::shared_ptr<Runnable> runnable)
|
||||
static std::deque<stdcxx::shared_ptr<Runnable> > m_expired;
|
||||
static void expiredNotifier(stdcxx::shared_ptr<Runnable> runnable)
|
||||
{
|
||||
m_expired.push_back(runnable);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public:
|
|||
shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
|
||||
|
||||
shared_ptr<PlatformThreadFactory> threadFactory
|
||||
= shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
|
||||
= shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory(false));
|
||||
|
||||
#if !USE_BOOST_THREAD && !USE_STD_THREAD
|
||||
threadFactory->setPriority(PosixThreadFactory::HIGHEST);
|
||||
|
|
166
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/TimerManagerTests.h
generated
vendored
166
vendor/git.apache.org/thrift.git/lib/cpp/test/concurrency/TimerManagerTests.h
generated
vendored
|
@ -79,14 +79,13 @@ public:
|
|||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, 10 * timeout));
|
||||
|
||||
{
|
||||
|
||||
TimerManager timerManager;
|
||||
|
||||
timerManager.threadFactory(shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()));
|
||||
|
||||
timerManager.start();
|
||||
|
||||
assert(timerManager.state() == TimerManager::STARTED);
|
||||
if (timerManager.state() != TimerManager::STARTED) {
|
||||
std::cerr << "timerManager is not in the STARTED state, but should be" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't create task yet, because its constructor sets the expected completion time, and we
|
||||
// need to delay between inserting the two tasks into the run queue.
|
||||
|
@ -94,34 +93,161 @@ public:
|
|||
|
||||
{
|
||||
Synchronized s(_monitor);
|
||||
|
||||
timerManager.add(orphanTask, 10 * timeout);
|
||||
|
||||
try {
|
||||
// Wait for 1 second in order to give timerManager a chance to start sleeping in response
|
||||
// to adding orphanTask. We need to do this so we can verify that adding the second task
|
||||
// kicks the dispatcher out of the current wait and starts the new 1 second wait.
|
||||
_monitor.wait(1000);
|
||||
assert(
|
||||
0 == "ERROR: This wait should time out. TimerManager dispatcher may have a problem.");
|
||||
} catch (TimedOutException&) {
|
||||
}
|
||||
THRIFT_SLEEP_USEC(timeout * 1000);
|
||||
|
||||
task.reset(new TimerManagerTests::Task(_monitor, timeout));
|
||||
|
||||
timerManager.add(task, timeout);
|
||||
|
||||
_monitor.wait();
|
||||
}
|
||||
|
||||
assert(task->_done);
|
||||
if (!task->_done) {
|
||||
std::cerr << "task is not done, but it should have executed" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "\t\t\t" << (task->_success ? "Success" : "Failure") << "!" << std::endl;
|
||||
}
|
||||
|
||||
// timerManager.stop(); This is where it happens via destructor
|
||||
if (orphanTask->_done) {
|
||||
std::cerr << "orphan task is done, but it should not have executed" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(!orphanTask->_done);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test creates two tasks, removes the first one then waits for the second one. It then
|
||||
* verifies that the timer manager properly clean up itself and the remaining orphaned timeout
|
||||
* task when the manager goes out of scope and its destructor is called.
|
||||
*/
|
||||
bool test01(int64_t timeout = 1000LL) {
|
||||
TimerManager timerManager;
|
||||
timerManager.threadFactory(shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()));
|
||||
timerManager.start();
|
||||
assert(timerManager.state() == TimerManager::STARTED);
|
||||
|
||||
Synchronized s(_monitor);
|
||||
|
||||
// Setup the two tasks
|
||||
shared_ptr<TimerManagerTests::Task> taskToRemove
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout / 2));
|
||||
timerManager.add(taskToRemove, taskToRemove->_timeout);
|
||||
|
||||
shared_ptr<TimerManagerTests::Task> task
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout));
|
||||
timerManager.add(task, task->_timeout);
|
||||
|
||||
// Remove one task and wait until the other has completed
|
||||
timerManager.remove(taskToRemove);
|
||||
_monitor.wait(timeout * 2);
|
||||
|
||||
assert(!taskToRemove->_done);
|
||||
assert(task->_done);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test creates two tasks with the same callback and another one, then removes the two
|
||||
* duplicated then waits for the last one. It then verifies that the timer manager properly
|
||||
* clean up itself and the remaining orphaned timeout task when the manager goes out of scope
|
||||
* and its destructor is called.
|
||||
*/
|
||||
bool test02(int64_t timeout = 1000LL) {
|
||||
TimerManager timerManager;
|
||||
timerManager.threadFactory(shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()));
|
||||
timerManager.start();
|
||||
assert(timerManager.state() == TimerManager::STARTED);
|
||||
|
||||
Synchronized s(_monitor);
|
||||
|
||||
// Setup the one tasks and add it twice
|
||||
shared_ptr<TimerManagerTests::Task> taskToRemove
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout / 3));
|
||||
timerManager.add(taskToRemove, taskToRemove->_timeout);
|
||||
timerManager.add(taskToRemove, taskToRemove->_timeout * 2);
|
||||
|
||||
shared_ptr<TimerManagerTests::Task> task
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout));
|
||||
timerManager.add(task, task->_timeout);
|
||||
|
||||
// Remove the first task (e.g. two timers) and wait until the other has completed
|
||||
timerManager.remove(taskToRemove);
|
||||
_monitor.wait(timeout * 2);
|
||||
|
||||
assert(!taskToRemove->_done);
|
||||
assert(task->_done);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test creates two tasks, removes the first one then waits for the second one. It then
|
||||
* verifies that the timer manager properly clean up itself and the remaining orphaned timeout
|
||||
* task when the manager goes out of scope and its destructor is called.
|
||||
*/
|
||||
bool test03(int64_t timeout = 1000LL) {
|
||||
TimerManager timerManager;
|
||||
timerManager.threadFactory(shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()));
|
||||
timerManager.start();
|
||||
assert(timerManager.state() == TimerManager::STARTED);
|
||||
|
||||
Synchronized s(_monitor);
|
||||
|
||||
// Setup the two tasks
|
||||
shared_ptr<TimerManagerTests::Task> taskToRemove
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout / 2));
|
||||
TimerManager::Timer timer = timerManager.add(taskToRemove, taskToRemove->_timeout);
|
||||
|
||||
shared_ptr<TimerManagerTests::Task> task
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout));
|
||||
timerManager.add(task, task->_timeout);
|
||||
|
||||
// Remove one task and wait until the other has completed
|
||||
timerManager.remove(timer);
|
||||
_monitor.wait(timeout * 2);
|
||||
|
||||
assert(!taskToRemove->_done);
|
||||
assert(task->_done);
|
||||
|
||||
// Verify behavior when removing the removed task
|
||||
try {
|
||||
timerManager.remove(timer);
|
||||
assert(0 == "ERROR: This remove should send a NoSuchTaskException exception.");
|
||||
} catch (NoSuchTaskException&) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test creates one tasks, and tries to remove it after it has expired.
|
||||
*/
|
||||
bool test04(int64_t timeout = 1000LL) {
|
||||
TimerManager timerManager;
|
||||
timerManager.threadFactory(shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()));
|
||||
timerManager.start();
|
||||
assert(timerManager.state() == TimerManager::STARTED);
|
||||
|
||||
Synchronized s(_monitor);
|
||||
|
||||
// Setup the task
|
||||
shared_ptr<TimerManagerTests::Task> task
|
||||
= shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout / 10));
|
||||
TimerManager::Timer timer = timerManager.add(task, task->_timeout);
|
||||
|
||||
// Wait until the task has completed
|
||||
_monitor.wait(timeout);
|
||||
|
||||
// Verify behavior when removing the expired task
|
||||
try {
|
||||
timerManager.remove(timer);
|
||||
assert(0 == "ERROR: This remove should send a NoSuchTaskException exception.");
|
||||
} catch (NoSuchTaskException&) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
3
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/EventLog.cpp
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/EventLog.cpp
generated
vendored
|
@ -21,7 +21,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace apache::thrift::concurrency;
|
||||
|
||||
namespace {
|
||||
|
@ -82,7 +81,7 @@ EventLog::EventLog() {
|
|||
void EventLog::append(EventType type,
|
||||
uint32_t connectionId,
|
||||
uint32_t callId,
|
||||
const string& message) {
|
||||
const std::string& message) {
|
||||
Synchronized s(monitor_);
|
||||
debug("%d <-- %u, %u, %s \"%s\"", id_, connectionId, callId, type, message.c_str());
|
||||
|
||||
|
|
32
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/Handlers.h
generated
vendored
32
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/Handlers.h
generated
vendored
|
@ -29,7 +29,7 @@ namespace test {
|
|||
|
||||
class ParentHandler : virtual public ParentServiceIf {
|
||||
public:
|
||||
ParentHandler(const boost::shared_ptr<EventLog>& log)
|
||||
ParentHandler(const stdcxx::shared_ptr<EventLog>& log)
|
||||
: triggerMonitor(&mutex_), generation_(0), wait_(false), log_(log) {}
|
||||
|
||||
int32_t incrementGeneration() {
|
||||
|
@ -136,7 +136,7 @@ protected:
|
|||
int32_t generation_;
|
||||
bool wait_;
|
||||
std::vector<std::string> strings_;
|
||||
boost::shared_ptr<EventLog> log_;
|
||||
stdcxx::shared_ptr<EventLog> log_;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -146,7 +146,7 @@ protected:
|
|||
|
||||
class ChildHandler : public ParentHandler, virtual public ChildServiceIf {
|
||||
public:
|
||||
ChildHandler(const boost::shared_ptr<EventLog>& log) : ParentHandler(log), value_(0) {}
|
||||
ChildHandler(const stdcxx::shared_ptr<EventLog>& log) : ParentHandler(log), value_(0) {}
|
||||
|
||||
int32_t setValue(const int32_t value) {
|
||||
concurrency::Guard g(mutex_);
|
||||
|
@ -174,13 +174,13 @@ protected:
|
|||
|
||||
struct ConnContext {
|
||||
public:
|
||||
ConnContext(boost::shared_ptr<protocol::TProtocol> in,
|
||||
boost::shared_ptr<protocol::TProtocol> out,
|
||||
ConnContext(stdcxx::shared_ptr<protocol::TProtocol> in,
|
||||
stdcxx::shared_ptr<protocol::TProtocol> out,
|
||||
uint32_t id)
|
||||
: input(in), output(out), id(id) {}
|
||||
|
||||
boost::shared_ptr<protocol::TProtocol> input;
|
||||
boost::shared_ptr<protocol::TProtocol> output;
|
||||
stdcxx::shared_ptr<protocol::TProtocol> input;
|
||||
stdcxx::shared_ptr<protocol::TProtocol> output;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
|
@ -196,12 +196,12 @@ public:
|
|||
|
||||
class ServerEventHandler : public server::TServerEventHandler {
|
||||
public:
|
||||
ServerEventHandler(const boost::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
|
||||
ServerEventHandler(const stdcxx::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
|
||||
|
||||
virtual void preServe() {}
|
||||
|
||||
virtual void* createContext(boost::shared_ptr<protocol::TProtocol> input,
|
||||
boost::shared_ptr<protocol::TProtocol> output) {
|
||||
virtual void* createContext(stdcxx::shared_ptr<protocol::TProtocol> input,
|
||||
stdcxx::shared_ptr<protocol::TProtocol> output) {
|
||||
ConnContext* context = new ConnContext(input, output, nextId_);
|
||||
++nextId_;
|
||||
log_->append(EventLog::ET_CONN_CREATED, context->id, 0);
|
||||
|
@ -209,8 +209,8 @@ public:
|
|||
}
|
||||
|
||||
virtual void deleteContext(void* serverContext,
|
||||
boost::shared_ptr<protocol::TProtocol> input,
|
||||
boost::shared_ptr<protocol::TProtocol> output) {
|
||||
stdcxx::shared_ptr<protocol::TProtocol> input,
|
||||
stdcxx::shared_ptr<protocol::TProtocol> output) {
|
||||
ConnContext* context = reinterpret_cast<ConnContext*>(serverContext);
|
||||
|
||||
if (input != context->input) {
|
||||
|
@ -226,7 +226,7 @@ public:
|
|||
}
|
||||
|
||||
virtual void processContext(void* serverContext,
|
||||
boost::shared_ptr<transport::TTransport> transport) {
|
||||
stdcxx::shared_ptr<transport::TTransport> transport) {
|
||||
// TODO: We currently don't test the behavior of the processContext()
|
||||
// calls. The various server implementations call processContext() at
|
||||
// slightly different times, and it is too annoying to try and account for
|
||||
|
@ -251,12 +251,12 @@ public:
|
|||
|
||||
protected:
|
||||
uint32_t nextId_;
|
||||
boost::shared_ptr<EventLog> log_;
|
||||
stdcxx::shared_ptr<EventLog> log_;
|
||||
};
|
||||
|
||||
class ProcessorEventHandler : public TProcessorEventHandler {
|
||||
public:
|
||||
ProcessorEventHandler(const boost::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
|
||||
ProcessorEventHandler(const stdcxx::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
|
||||
|
||||
void* getContext(const char* fnName, void* serverContext) {
|
||||
ConnContext* connContext = reinterpret_cast<ConnContext*>(serverContext);
|
||||
|
@ -329,7 +329,7 @@ protected:
|
|||
}
|
||||
|
||||
uint32_t nextId_;
|
||||
boost::shared_ptr<EventLog> log_;
|
||||
stdcxx::shared_ptr<EventLog> log_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
180
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/ProcessorTest.cpp
generated
vendored
180
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/ProcessorTest.cpp
generated
vendored
|
@ -33,21 +33,21 @@
|
|||
#include <thrift/server/TNonblockingServer.h>
|
||||
#include <thrift/server/TSimpleServer.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/transport/TNonblockingServerSocket.h>
|
||||
|
||||
#include "EventLog.h"
|
||||
#include "ServerThread.h"
|
||||
#include "Handlers.h"
|
||||
#include "gen-cpp/ChildService.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace apache::thrift;
|
||||
using namespace apache::thrift::concurrency;
|
||||
using namespace apache::thrift::protocol;
|
||||
using namespace apache::thrift::server;
|
||||
using namespace apache::thrift::transport;
|
||||
|
||||
using namespace apache::thrift::test;
|
||||
using namespace apache::thrift::transport;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
/*
|
||||
* Traits classes that encapsulate how to create various types of servers.
|
||||
|
@ -57,13 +57,13 @@ class TSimpleServerTraits {
|
|||
public:
|
||||
typedef TSimpleServer ServerType;
|
||||
|
||||
boost::shared_ptr<TSimpleServer> createServer(
|
||||
const boost::shared_ptr<TProcessor>& processor,
|
||||
stdcxx::shared_ptr<TSimpleServer> createServer(
|
||||
const stdcxx::shared_ptr<TProcessor>& processor,
|
||||
uint16_t port,
|
||||
const boost::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
boost::shared_ptr<TServerSocket> socket(new TServerSocket(port));
|
||||
return boost::shared_ptr<TSimpleServer>(
|
||||
const stdcxx::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const stdcxx::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
stdcxx::shared_ptr<TServerSocket> socket(new TServerSocket(port));
|
||||
return stdcxx::shared_ptr<TSimpleServer>(
|
||||
new TSimpleServer(processor, socket, transportFactory, protocolFactory));
|
||||
}
|
||||
};
|
||||
|
@ -72,13 +72,13 @@ class TThreadedServerTraits {
|
|||
public:
|
||||
typedef TThreadedServer ServerType;
|
||||
|
||||
boost::shared_ptr<TThreadedServer> createServer(
|
||||
const boost::shared_ptr<TProcessor>& processor,
|
||||
stdcxx::shared_ptr<TThreadedServer> createServer(
|
||||
const stdcxx::shared_ptr<TProcessor>& processor,
|
||||
uint16_t port,
|
||||
const boost::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
boost::shared_ptr<TServerSocket> socket(new TServerSocket(port));
|
||||
return boost::shared_ptr<TThreadedServer>(
|
||||
const stdcxx::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const stdcxx::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
stdcxx::shared_ptr<TServerSocket> socket(new TServerSocket(port));
|
||||
return stdcxx::shared_ptr<TThreadedServer>(
|
||||
new TThreadedServer(processor, socket, transportFactory, protocolFactory));
|
||||
}
|
||||
};
|
||||
|
@ -87,19 +87,19 @@ class TThreadPoolServerTraits {
|
|||
public:
|
||||
typedef TThreadPoolServer ServerType;
|
||||
|
||||
boost::shared_ptr<TThreadPoolServer> createServer(
|
||||
const boost::shared_ptr<TProcessor>& processor,
|
||||
stdcxx::shared_ptr<TThreadPoolServer> createServer(
|
||||
const stdcxx::shared_ptr<TProcessor>& processor,
|
||||
uint16_t port,
|
||||
const boost::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
boost::shared_ptr<TServerSocket> socket(new TServerSocket(port));
|
||||
const stdcxx::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const stdcxx::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
stdcxx::shared_ptr<TServerSocket> socket(new TServerSocket(port));
|
||||
|
||||
boost::shared_ptr<PlatformThreadFactory> threadFactory(new PlatformThreadFactory);
|
||||
boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8);
|
||||
stdcxx::shared_ptr<PlatformThreadFactory> threadFactory(new PlatformThreadFactory);
|
||||
stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8);
|
||||
threadManager->threadFactory(threadFactory);
|
||||
threadManager->start();
|
||||
|
||||
return boost::shared_ptr<TThreadPoolServer>(
|
||||
return stdcxx::shared_ptr<TThreadPoolServer>(
|
||||
new TThreadPoolServer(processor, socket, transportFactory, protocolFactory, threadManager));
|
||||
}
|
||||
};
|
||||
|
@ -108,11 +108,11 @@ class TNonblockingServerTraits {
|
|||
public:
|
||||
typedef TNonblockingServer ServerType;
|
||||
|
||||
boost::shared_ptr<TNonblockingServer> createServer(
|
||||
const boost::shared_ptr<TProcessor>& processor,
|
||||
stdcxx::shared_ptr<TNonblockingServer> createServer(
|
||||
const stdcxx::shared_ptr<TProcessor>& processor,
|
||||
uint16_t port,
|
||||
const boost::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
const stdcxx::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const stdcxx::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
// TNonblockingServer automatically uses TFramedTransport.
|
||||
// Raise an exception if the supplied transport factory is not a
|
||||
// TFramedTransportFactory
|
||||
|
@ -122,13 +122,14 @@ public:
|
|||
throw TException("TNonblockingServer must use TFramedTransport");
|
||||
}
|
||||
|
||||
boost::shared_ptr<PlatformThreadFactory> threadFactory(new PlatformThreadFactory);
|
||||
boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8);
|
||||
stdcxx::shared_ptr<TNonblockingServerSocket> socket(new TNonblockingServerSocket(port));
|
||||
stdcxx::shared_ptr<PlatformThreadFactory> threadFactory(new PlatformThreadFactory);
|
||||
stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8);
|
||||
threadManager->threadFactory(threadFactory);
|
||||
threadManager->start();
|
||||
|
||||
return boost::shared_ptr<TNonblockingServer>(
|
||||
new TNonblockingServer(processor, protocolFactory, port, threadManager));
|
||||
return stdcxx::shared_ptr<TNonblockingServer>(
|
||||
new TNonblockingServer(processor, protocolFactory, socket, threadManager));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -136,11 +137,11 @@ class TNonblockingServerNoThreadsTraits {
|
|||
public:
|
||||
typedef TNonblockingServer ServerType;
|
||||
|
||||
boost::shared_ptr<TNonblockingServer> createServer(
|
||||
const boost::shared_ptr<TProcessor>& processor,
|
||||
stdcxx::shared_ptr<TNonblockingServer> createServer(
|
||||
const stdcxx::shared_ptr<TProcessor>& processor,
|
||||
uint16_t port,
|
||||
const boost::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
const stdcxx::shared_ptr<TTransportFactory>& transportFactory,
|
||||
const stdcxx::shared_ptr<TProtocolFactory>& protocolFactory) {
|
||||
// TNonblockingServer automatically uses TFramedTransport.
|
||||
// Raise an exception if the supplied transport factory is not a
|
||||
// TFramedTransportFactory
|
||||
|
@ -150,10 +151,11 @@ public:
|
|||
throw TException("TNonblockingServer must use TFramedTransport");
|
||||
}
|
||||
|
||||
stdcxx::shared_ptr<TNonblockingServerSocket> socket(new TNonblockingServerSocket(port));
|
||||
// Use a NULL ThreadManager
|
||||
boost::shared_ptr<ThreadManager> threadManager;
|
||||
return boost::shared_ptr<TNonblockingServer>(
|
||||
new TNonblockingServer(processor, protocolFactory, port, threadManager));
|
||||
stdcxx::shared_ptr<ThreadManager> threadManager;
|
||||
return stdcxx::shared_ptr<TNonblockingServer>(
|
||||
new TNonblockingServer(processor, protocolFactory, socket, threadManager));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -242,48 +244,48 @@ public:
|
|||
processor_->setEventHandler(processorEventHandler_);
|
||||
}
|
||||
|
||||
boost::shared_ptr<TServer> createServer(uint16_t port) {
|
||||
stdcxx::shared_ptr<TServer> createServer(uint16_t port) {
|
||||
ServerTraits_ serverTraits;
|
||||
return serverTraits.createServer(processor_, port, transportFactory_, protocolFactory_);
|
||||
}
|
||||
|
||||
boost::shared_ptr<TServerEventHandler> getServerEventHandler() { return serverEventHandler_; }
|
||||
stdcxx::shared_ptr<TServerEventHandler> getServerEventHandler() { return serverEventHandler_; }
|
||||
|
||||
void bindSuccessful(uint16_t port) { port_ = port; }
|
||||
|
||||
uint16_t getPort() const { return port_; }
|
||||
|
||||
const boost::shared_ptr<EventLog>& getLog() const { return log_; }
|
||||
const stdcxx::shared_ptr<EventLog>& getLog() const { return log_; }
|
||||
|
||||
const boost::shared_ptr<Handler>& getHandler() const { return handler_; }
|
||||
const stdcxx::shared_ptr<Handler>& getHandler() const { return handler_; }
|
||||
|
||||
boost::shared_ptr<Client> createClient() {
|
||||
stdcxx::shared_ptr<Client> createClient() {
|
||||
typedef typename ServiceTraits_::Protocol Protocol;
|
||||
|
||||
boost::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", port_));
|
||||
boost::shared_ptr<Transport_> transport(new Transport_(socket));
|
||||
boost::shared_ptr<Protocol> protocol(new Protocol(transport));
|
||||
stdcxx::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", port_));
|
||||
stdcxx::shared_ptr<Transport_> transport(new Transport_(socket));
|
||||
stdcxx::shared_ptr<Protocol> protocol(new Protocol(transport));
|
||||
transport->open();
|
||||
|
||||
boost::shared_ptr<Client> client(new Client(protocol));
|
||||
stdcxx::shared_ptr<Client> client(new Client(protocol));
|
||||
return client;
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t port_;
|
||||
boost::shared_ptr<EventLog> log_;
|
||||
boost::shared_ptr<Handler> handler_;
|
||||
boost::shared_ptr<Processor> processor_;
|
||||
boost::shared_ptr<TTransportFactory> transportFactory_;
|
||||
boost::shared_ptr<TProtocolFactory> protocolFactory_;
|
||||
boost::shared_ptr<TServerEventHandler> serverEventHandler_;
|
||||
boost::shared_ptr<TProcessorEventHandler> processorEventHandler_;
|
||||
stdcxx::shared_ptr<EventLog> log_;
|
||||
stdcxx::shared_ptr<Handler> handler_;
|
||||
stdcxx::shared_ptr<Processor> processor_;
|
||||
stdcxx::shared_ptr<TTransportFactory> transportFactory_;
|
||||
stdcxx::shared_ptr<TProtocolFactory> protocolFactory_;
|
||||
stdcxx::shared_ptr<TServerEventHandler> serverEventHandler_;
|
||||
stdcxx::shared_ptr<TProcessorEventHandler> processorEventHandler_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check that there are no more events in the log
|
||||
*/
|
||||
void checkNoEvents(const boost::shared_ptr<EventLog>& log) {
|
||||
void checkNoEvents(const stdcxx::shared_ptr<EventLog>& log) {
|
||||
// Wait for an event with a very short timeout period. We don't expect
|
||||
// anything to be present, so we will normally wait for the full timeout.
|
||||
// On the other hand, a non-zero timeout is nice since it does give a short
|
||||
|
@ -297,7 +299,7 @@ void checkNoEvents(const boost::shared_ptr<EventLog>& log) {
|
|||
*
|
||||
* Returns the connection ID allocated by the server.
|
||||
*/
|
||||
uint32_t checkNewConnEvents(const boost::shared_ptr<EventLog>& log) {
|
||||
uint32_t checkNewConnEvents(const stdcxx::shared_ptr<EventLog>& log) {
|
||||
// Check for an ET_CONN_CREATED event
|
||||
Event event = log->waitForEvent(2500);
|
||||
BOOST_CHECK_EQUAL(EventLog::ET_CONN_CREATED, event.type);
|
||||
|
@ -312,7 +314,7 @@ uint32_t checkNewConnEvents(const boost::shared_ptr<EventLog>& log) {
|
|||
/**
|
||||
* Check for the events that should be logged when a connection is closed.
|
||||
*/
|
||||
void checkCloseEvents(const boost::shared_ptr<EventLog>& log, uint32_t connId) {
|
||||
void checkCloseEvents(const stdcxx::shared_ptr<EventLog>& log, uint32_t connId) {
|
||||
// Check for an ET_CONN_DESTROYED event
|
||||
Event event = log->waitForEvent();
|
||||
BOOST_CHECK_EQUAL(EventLog::ET_CONN_DESTROYED, event.type);
|
||||
|
@ -330,7 +332,7 @@ void checkCloseEvents(const boost::shared_ptr<EventLog>& log, uint32_t connId) {
|
|||
*
|
||||
* Returns the call ID allocated by the server.
|
||||
*/
|
||||
uint32_t checkCallHandlerEvents(const boost::shared_ptr<EventLog>& log,
|
||||
uint32_t checkCallHandlerEvents(const stdcxx::shared_ptr<EventLog>& log,
|
||||
uint32_t connId,
|
||||
EventType callType,
|
||||
const string& callName) {
|
||||
|
@ -367,7 +369,7 @@ uint32_t checkCallHandlerEvents(const boost::shared_ptr<EventLog>& log,
|
|||
/**
|
||||
* Check for the events that should be after a handler returns.
|
||||
*/
|
||||
void checkCallPostHandlerEvents(const boost::shared_ptr<EventLog>& log,
|
||||
void checkCallPostHandlerEvents(const stdcxx::shared_ptr<EventLog>& log,
|
||||
uint32_t connId,
|
||||
uint32_t callId,
|
||||
const string& callName) {
|
||||
|
@ -407,7 +409,7 @@ void checkCallPostHandlerEvents(const boost::shared_ptr<EventLog>& log,
|
|||
*
|
||||
* Returns the call ID allocated by the server.
|
||||
*/
|
||||
uint32_t checkCallEvents(const boost::shared_ptr<EventLog>& log,
|
||||
uint32_t checkCallEvents(const stdcxx::shared_ptr<EventLog>& log,
|
||||
uint32_t connId,
|
||||
EventType callType,
|
||||
const string& callName) {
|
||||
|
@ -422,8 +424,8 @@ uint32_t checkCallEvents(const boost::shared_ptr<EventLog>& log,
|
|||
*/
|
||||
|
||||
template <typename State_>
|
||||
void testParentService(const boost::shared_ptr<State_>& state) {
|
||||
boost::shared_ptr<typename State_::Client> client = state->createClient();
|
||||
void testParentService(const stdcxx::shared_ptr<State_>& state) {
|
||||
stdcxx::shared_ptr<typename State_::Client> client = state->createClient();
|
||||
|
||||
int32_t gen = client->getGeneration();
|
||||
int32_t newGen = client->incrementGeneration();
|
||||
|
@ -444,8 +446,8 @@ void testParentService(const boost::shared_ptr<State_>& state) {
|
|||
}
|
||||
|
||||
template <typename State_>
|
||||
void testChildService(const boost::shared_ptr<State_>& state) {
|
||||
boost::shared_ptr<typename State_::Client> client = state->createClient();
|
||||
void testChildService(const stdcxx::shared_ptr<State_>& state) {
|
||||
stdcxx::shared_ptr<typename State_::Client> client = state->createClient();
|
||||
|
||||
// Test calling some of the parent methids via the a child client
|
||||
int32_t gen = client->getGeneration();
|
||||
|
@ -466,7 +468,7 @@ void testBasicService() {
|
|||
typedef ServiceState<ServerTraits, ParentServiceTraits<TemplateTraits> > State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
testParentService(state);
|
||||
|
@ -477,7 +479,7 @@ void testInheritedService() {
|
|||
typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
testParentService(state);
|
||||
|
@ -500,10 +502,10 @@ void testEventSequencing() {
|
|||
TBufferedTransport> State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
const boost::shared_ptr<EventLog>& log = state->getLog();
|
||||
const stdcxx::shared_ptr<EventLog>& log = state->getLog();
|
||||
|
||||
// Make sure we're at the end of the log
|
||||
checkNoEvents(log);
|
||||
|
@ -512,7 +514,7 @@ void testEventSequencing() {
|
|||
|
||||
// Make sure createContext() is called after a connection has been
|
||||
// established. We open a plain socket instead of creating a client.
|
||||
boost::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", state->getPort()));
|
||||
stdcxx::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", state->getPort()));
|
||||
socket->open();
|
||||
|
||||
// Make sure the proper events occurred after a new connection
|
||||
|
@ -590,7 +592,7 @@ void testEventSequencing() {
|
|||
checkNoEvents(log);
|
||||
|
||||
// Read the response header
|
||||
std::string responseName;
|
||||
string responseName;
|
||||
int32_t responseSeqid = 0;
|
||||
apache::thrift::protocol::TMessageType responseType;
|
||||
protocol.readMessageBegin(responseName, responseType, responseSeqid);
|
||||
|
@ -633,19 +635,19 @@ void testSeparateConnections() {
|
|||
typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
const boost::shared_ptr<EventLog>& log = state->getLog();
|
||||
const stdcxx::shared_ptr<EventLog>& log = state->getLog();
|
||||
|
||||
// Create a client
|
||||
boost::shared_ptr<typename State::Client> client1 = state->createClient();
|
||||
stdcxx::shared_ptr<typename State::Client> client1 = state->createClient();
|
||||
|
||||
// Make sure the expected events were logged
|
||||
uint32_t client1Id = checkNewConnEvents(log);
|
||||
|
||||
// Create a second client
|
||||
boost::shared_ptr<typename State::Client> client2 = state->createClient();
|
||||
stdcxx::shared_ptr<typename State::Client> client2 = state->createClient();
|
||||
|
||||
// Make sure the expected events were logged
|
||||
uint32_t client2Id = checkNewConnEvents(log);
|
||||
|
@ -681,13 +683,13 @@ void testOnewayCall() {
|
|||
typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
const boost::shared_ptr<EventLog>& log = state->getLog();
|
||||
const stdcxx::shared_ptr<EventLog>& log = state->getLog();
|
||||
|
||||
// Create a client
|
||||
boost::shared_ptr<typename State::Client> client = state->createClient();
|
||||
stdcxx::shared_ptr<typename State::Client> client = state->createClient();
|
||||
uint32_t connId = checkNewConnEvents(log);
|
||||
|
||||
// Make a oneway call
|
||||
|
@ -733,13 +735,13 @@ void testExpectedError() {
|
|||
typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
const boost::shared_ptr<EventLog>& log = state->getLog();
|
||||
const stdcxx::shared_ptr<EventLog>& log = state->getLog();
|
||||
|
||||
// Create a client
|
||||
boost::shared_ptr<typename State::Client> client = state->createClient();
|
||||
stdcxx::shared_ptr<typename State::Client> client = state->createClient();
|
||||
uint32_t connId = checkNewConnEvents(log);
|
||||
|
||||
// Send the exceptionWait() call
|
||||
|
@ -766,8 +768,8 @@ void testExpectedError() {
|
|||
} catch (const MyError& e) {
|
||||
BOOST_CHECK_EQUAL(message, e.message);
|
||||
// Check if std::exception::what() is handled properly
|
||||
size_t message_pos = std::string(e.what()).find("TException - service has thrown: MyError");
|
||||
BOOST_CHECK_NE(message_pos, std::string::npos);
|
||||
size_t message_pos = string(e.what()).find("TException - service has thrown: MyError");
|
||||
BOOST_CHECK_NE(message_pos, string::npos);
|
||||
}
|
||||
|
||||
// Now we should see the events for a normal call finish
|
||||
|
@ -788,13 +790,13 @@ void testUnexpectedError() {
|
|||
typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
|
||||
|
||||
// Start the server
|
||||
boost::shared_ptr<State> state(new State);
|
||||
stdcxx::shared_ptr<State> state(new State);
|
||||
ServerThread serverThread(state, true);
|
||||
|
||||
const boost::shared_ptr<EventLog>& log = state->getLog();
|
||||
const stdcxx::shared_ptr<EventLog>& log = state->getLog();
|
||||
|
||||
// Create a client
|
||||
boost::shared_ptr<typename State::Client> client = state->createClient();
|
||||
stdcxx::shared_ptr<typename State::Client> client = state->createClient();
|
||||
uint32_t connId = checkNewConnEvents(log);
|
||||
|
||||
// Send the unexpectedExceptionWait() call
|
||||
|
@ -910,7 +912,7 @@ DEFINE_NOFRAME_TESTS(TSimpleServer, Untemplated)
|
|||
// For now, it is known not to work correctly with TProcessorEventHandler.
|
||||
#ifdef BOOST_TEST_DYN_LINK
|
||||
bool init_unit_test_suite() {
|
||||
unit_test::framework::master_test_suite().p_name.value = "ProcessorTest";
|
||||
::boost::unit_test::framework::master_test_suite().p_name.value = "ProcessorTest";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -918,10 +920,10 @@ int main( int argc, char* argv[] ) {
|
|||
return ::boost::unit_test::unit_test_main(&init_unit_test_suite,argc,argv);
|
||||
}
|
||||
#else
|
||||
unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
|
||||
::boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
|
||||
THRIFT_UNUSED_VARIABLE(argc);
|
||||
THRIFT_UNUSED_VARIABLE(argv);
|
||||
unit_test::framework::master_test_suite().p_name.value = "ProcessorTest";
|
||||
::boost::unit_test::framework::master_test_suite().p_name.value = "ProcessorTest";
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
|
4
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/ServerThread.cpp
generated
vendored
4
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/ServerThread.cpp
generated
vendored
|
@ -35,6 +35,8 @@ void ServerThread::start() {
|
|||
assert(!running_);
|
||||
running_ = true;
|
||||
|
||||
helper_.reset(new Helper(this));
|
||||
|
||||
// Start the other thread
|
||||
concurrency::PlatformThreadFactory threadFactory;
|
||||
threadFactory.setDetached(false);
|
||||
|
@ -128,7 +130,7 @@ void ServerThread::preServe() {
|
|||
serverState_->bindSuccessful(port_);
|
||||
|
||||
// Set the real server event handler (replacing ourself)
|
||||
boost::shared_ptr<server::TServerEventHandler> serverEventHandler
|
||||
stdcxx::shared_ptr<server::TServerEventHandler> serverEventHandler
|
||||
= serverState_->getServerEventHandler();
|
||||
server_->setServerEventHandler(serverEventHandler);
|
||||
|
||||
|
|
19
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/ServerThread.h
generated
vendored
19
vendor/git.apache.org/thrift.git/lib/cpp/test/processor/ServerThread.h
generated
vendored
|
@ -43,7 +43,7 @@ public:
|
|||
* If the server returned fails to bind to the specified port when serve() is
|
||||
* called on it, createServer() may be called again on a different port.
|
||||
*/
|
||||
virtual boost::shared_ptr<server::TServer> createServer(uint16_t port) = 0;
|
||||
virtual stdcxx::shared_ptr<server::TServer> createServer(uint16_t port) = 0;
|
||||
|
||||
/**
|
||||
* Get the TServerEventHandler to set on the server.
|
||||
|
@ -52,8 +52,8 @@ public:
|
|||
* start serving traffic. It is invoked from the server thread, rather than
|
||||
* the main thread.
|
||||
*/
|
||||
virtual boost::shared_ptr<server::TServerEventHandler> getServerEventHandler() {
|
||||
return boost::shared_ptr<server::TServerEventHandler>();
|
||||
virtual stdcxx::shared_ptr<server::TServerEventHandler> getServerEventHandler() {
|
||||
return stdcxx::shared_ptr<server::TServerEventHandler>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,9 +70,8 @@ public:
|
|||
*/
|
||||
class ServerThread {
|
||||
public:
|
||||
ServerThread(const boost::shared_ptr<ServerState>& state, bool autoStart)
|
||||
: helper_(new Helper(this)),
|
||||
port_(0),
|
||||
ServerThread(const stdcxx::shared_ptr<ServerState>& state, bool autoStart)
|
||||
: port_(0),
|
||||
running_(false),
|
||||
serving_(false),
|
||||
error_(false),
|
||||
|
@ -117,7 +116,7 @@ protected:
|
|||
void run();
|
||||
void preServe();
|
||||
|
||||
boost::shared_ptr<Helper> helper_;
|
||||
stdcxx::shared_ptr<Helper> helper_;
|
||||
|
||||
uint16_t port_;
|
||||
bool running_;
|
||||
|
@ -125,9 +124,9 @@ protected:
|
|||
bool error_;
|
||||
concurrency::Monitor serverMonitor_;
|
||||
|
||||
boost::shared_ptr<ServerState> serverState_;
|
||||
boost::shared_ptr<server::TServer> server_;
|
||||
boost::shared_ptr<concurrency::Thread> thread_;
|
||||
stdcxx::shared_ptr<ServerState> serverState_;
|
||||
stdcxx::shared_ptr<server::TServer> server_;
|
||||
stdcxx::shared_ptr<concurrency::Thread> thread_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
42
vendor/git.apache.org/thrift.git/lib/cpp/test/qt/TQTcpServerTest.cpp
generated
vendored
42
vendor/git.apache.org/thrift.git/lib/cpp/test/qt/TQTcpServerTest.cpp
generated
vendored
|
@ -8,12 +8,12 @@
|
|||
#include <QThread>
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include "thrift/stdcxx.h"
|
||||
#include "thrift/protocol/TBinaryProtocol.h"
|
||||
#include "thrift/async/TAsyncProcessor.h"
|
||||
#include "thrift/qt/TQTcpServer.h"
|
||||
#include "thrift/qt/TQIODeviceTransport.h"
|
||||
|
||||
|
||||
#include "gen-cpp/ParentService.h"
|
||||
#endif
|
||||
|
||||
|
@ -21,25 +21,25 @@ using namespace apache::thrift;
|
|||
|
||||
struct AsyncHandler : public test::ParentServiceCobSvIf {
|
||||
std::vector<std::string> strings;
|
||||
virtual void addString(tcxx::function<void()> cob, const std::string& s) {
|
||||
virtual void addString(stdcxx::function<void()> cob, const std::string& s) {
|
||||
strings.push_back(s);
|
||||
cob();
|
||||
}
|
||||
virtual void getStrings(tcxx::function<void(std::vector<std::string> const& _return)> cob) {
|
||||
virtual void getStrings(stdcxx::function<void(std::vector<std::string> const& _return)> cob) {
|
||||
cob(strings);
|
||||
}
|
||||
|
||||
// Overrides not used in this test
|
||||
virtual void incrementGeneration(tcxx::function<void(int32_t const& _return)> cob) {}
|
||||
virtual void getGeneration(tcxx::function<void(int32_t const& _return)> cob) {}
|
||||
virtual void getDataWait(tcxx::function<void(std::string const& _return)> cob,
|
||||
virtual void incrementGeneration(stdcxx::function<void(int32_t const& _return)> cob) {}
|
||||
virtual void getGeneration(stdcxx::function<void(int32_t const& _return)> cob) {}
|
||||
virtual void getDataWait(stdcxx::function<void(std::string const& _return)> cob,
|
||||
const int32_t length) {}
|
||||
virtual void onewayWait(tcxx::function<void()> cob) {}
|
||||
virtual void onewayWait(stdcxx::function<void()> cob) {}
|
||||
virtual void exceptionWait(
|
||||
tcxx::function<void()> cob,
|
||||
tcxx::function<void(::apache::thrift::TDelayedException* _throw)> /* exn_cob */,
|
||||
stdcxx::function<void()> cob,
|
||||
stdcxx::function<void(::apache::thrift::TDelayedException* _throw)> /* exn_cob */,
|
||||
const std::string& message) {}
|
||||
virtual void unexpectedExceptionWait(tcxx::function<void()> cob, const std::string& message) {}
|
||||
virtual void unexpectedExceptionWait(stdcxx::function<void()> cob, const std::string& message) {}
|
||||
};
|
||||
|
||||
class TQTcpServerTest : public QObject {
|
||||
|
@ -51,18 +51,18 @@ private slots:
|
|||
void test_communicate();
|
||||
|
||||
private:
|
||||
boost::shared_ptr<QThread> serverThread;
|
||||
boost::shared_ptr<async::TQTcpServer> server;
|
||||
boost::shared_ptr<test::ParentServiceClient> client;
|
||||
stdcxx::shared_ptr<QThread> serverThread;
|
||||
stdcxx::shared_ptr<async::TQTcpServer> server;
|
||||
stdcxx::shared_ptr<test::ParentServiceClient> client;
|
||||
};
|
||||
|
||||
void TQTcpServerTest::initTestCase() {
|
||||
// setup server
|
||||
boost::shared_ptr<QTcpServer> serverSocket = boost::make_shared<QTcpServer>();
|
||||
stdcxx::shared_ptr<QTcpServer> serverSocket = stdcxx::make_shared<QTcpServer>();
|
||||
server.reset(new async::TQTcpServer(serverSocket,
|
||||
boost::make_shared<test::ParentServiceAsyncProcessor>(
|
||||
boost::make_shared<AsyncHandler>()),
|
||||
boost::make_shared<protocol::TBinaryProtocolFactory>()));
|
||||
stdcxx::make_shared<test::ParentServiceAsyncProcessor>(
|
||||
stdcxx::make_shared<AsyncHandler>()),
|
||||
stdcxx::make_shared<protocol::TBinaryProtocolFactory>()));
|
||||
QVERIFY(serverSocket->listen(QHostAddress::LocalHost));
|
||||
int port = serverSocket->serverPort();
|
||||
QVERIFY(port > 0);
|
||||
|
@ -74,9 +74,9 @@ void TQTcpServerTest::initTestCase() {
|
|||
serverThread->start();
|
||||
|
||||
// setup client
|
||||
boost::shared_ptr<QTcpSocket> socket = boost::make_shared<QTcpSocket>();
|
||||
client.reset(new test::ParentServiceClient(boost::make_shared<protocol::TBinaryProtocol>(
|
||||
boost::make_shared<transport::TQIODeviceTransport>(socket))));
|
||||
stdcxx::shared_ptr<QTcpSocket> socket = stdcxx::make_shared<QTcpSocket>();
|
||||
client.reset(new test::ParentServiceClient(stdcxx::make_shared<protocol::TBinaryProtocol>(
|
||||
stdcxx::make_shared<transport::TQIODeviceTransport>(socket))));
|
||||
socket->connectToHost(QHostAddress::LocalHost, port);
|
||||
QVERIFY(socket->waitForConnected());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue