1
1
/*
2
- * Copyright (c) 2017 Uber Technologies, Inc.
2
+ * Copyright (c) 2017-2018 Uber Technologies, Inc.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
#include " jaegertracing/utils/ErrorUtil.h"
24
24
25
25
namespace jaegertracing {
26
+ namespace {
27
+
28
+ class MockUDPClient : public utils ::UDPClient {
29
+ public:
30
+ enum class ExceptionType { kSystemError , kException , kString };
31
+
32
+ MockUDPClient (const net::IPAddress& serverAddr,
33
+ int maxPacketSize,
34
+ ExceptionType type)
35
+ : UDPClient(serverAddr, maxPacketSize)
36
+ , _type(type)
37
+ {
38
+ }
39
+
40
+ private:
41
+ void emitBatch (const thrift::Batch& batch) override
42
+ {
43
+ switch (_type) {
44
+ case ExceptionType::kSystemError :
45
+ throw std::system_error ();
46
+ case ExceptionType::kException :
47
+ throw std::exception ();
48
+ default :
49
+ assert (_type == ExceptionType::kString );
50
+ throw " error" ;
51
+ }
52
+ }
53
+
54
+ ExceptionType _type;
55
+ };
56
+
57
+ class MockUDPTransport : public UDPTransport {
58
+ public:
59
+ MockUDPTransport (const net::IPAddress& ip,
60
+ int maxPacketSize,
61
+ MockUDPClient::ExceptionType type)
62
+ : UDPTransport(ip, maxPacketSize)
63
+ {
64
+ setClient (std::unique_ptr<utils::UDPClient>(
65
+ new MockUDPClient (ip, maxPacketSize, type)));
66
+ }
67
+ };
68
+
69
+ } // anonymous namespace
26
70
27
71
TEST (UDPTransport, testManyMessages)
28
72
{
@@ -40,4 +84,25 @@ TEST(UDPTransport, testManyMessages)
40
84
}
41
85
}
42
86
87
+ TEST (UDPTransport, testExceptions)
88
+ {
89
+ const auto handle = testutils::TracerUtil::installGlobalTracer ();
90
+ const auto tracer =
91
+ std::static_pointer_cast<const Tracer>(opentracing::Tracer::Global ());
92
+
93
+ Span span (tracer);
94
+ span.SetOperationName (" test" );
95
+
96
+ const MockUDPClient::ExceptionType exceptionTypes[] = {
97
+ MockUDPClient::ExceptionType::kSystemError ,
98
+ MockUDPClient::ExceptionType::kException ,
99
+ MockUDPClient::ExceptionType::kString
100
+ };
101
+ for (auto type : exceptionTypes) {
102
+ MockUDPTransport sender (net::IPAddress (), 0 , type);
103
+ sender.append (span);
104
+ ASSERT_THROW (sender.flush (), Transport::Exception);
105
+ }
106
+ }
107
+
43
108
} // namespace jaegertracing
0 commit comments