2 * Copyright (c) 2017 Uber Technologies, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "jaegertracing/net/IPAddress.h"
18 #include "jaegertracing/net/Socket.h"
19 #include "jaegertracing/thrift-gen/jaeger_types.h"
20 #include "jaegertracing/thrift-gen/zipkincore_types.h"
21 #include "jaegertracing/utils/UDPTransporter.h"
23 #include <gtest/gtest.h>
28 namespace jaegertracing
{
31 TEST(UDPSender
, testZipkinMessage
)
33 net::IPAddress serverAddr
;
34 std::promise
<void> started
;
35 std::thread
serverThread([&serverAddr
, &started
]() {
37 socket
.open(AF_INET
, SOCK_DGRAM
);
38 socket
.bind(net::IPAddress::v4("127.0.0.1", 0));
39 ::sockaddr_storage addrStorage
;
40 ::socklen_t addrLen
= sizeof(addrStorage
);
41 const auto returnCode
=
42 ::getsockname(socket
.handle(),
43 reinterpret_cast<::sockaddr
*>(&addrStorage
),
45 ASSERT_EQ(0, returnCode
);
46 serverAddr
= net::IPAddress(addrStorage
, addrLen
);
50 started
.get_future().wait();
51 UDPTransporter
udpClient(serverAddr
, 0);
52 using ZipkinBatch
= std::vector
<twitter::zipkin::thrift::Span
>;
53 ASSERT_THROW(udpClient
.emitZipkinBatch(ZipkinBatch()), std::logic_error
);
57 TEST(UDPSender
, testBigMessage
)
59 net::IPAddress serverAddr
;
60 std::promise
<void> started
;
61 std::thread
serverThread([&serverAddr
, &started
]() {
63 socket
.open(AF_INET
, SOCK_DGRAM
);
64 socket
.bind(net::IPAddress::v4("127.0.0.1", 0));
65 ::sockaddr_storage addrStorage
;
66 ::socklen_t addrLen
= sizeof(addrStorage
);
67 const auto returnCode
=
68 ::getsockname(socket
.handle(),
69 reinterpret_cast<::sockaddr
*>(&addrStorage
),
71 ASSERT_EQ(0, returnCode
);
72 serverAddr
= net::IPAddress(addrStorage
, addrLen
);
76 started
.get_future().wait();
77 UDPTransporter
udpClient(serverAddr
, 1);
78 ASSERT_THROW(udpClient
.emitBatch(thrift::Batch()), std::logic_error
);
83 } // namespace jaegertracing