This repository was archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathUDPClientTest.php
More file actions
105 lines (92 loc) · 2.99 KB
/
UDPClientTest.php
File metadata and controls
105 lines (92 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Copyright 2018 OpenCensus Authors
*
* Licensed 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.
*/
namespace OpenCensus\Trace\Exporter\Jaeger;
use Jaeger\Thrift\Batch;
use Jaeger\Thrift\Process;
use Jaeger\Thrift\Span;
use Thrift\Protocol\TCompactProtocol;
use Thrift\Transport\TMemoryBuffer;
use Prophecy\Argument;
use PHPUnit\Framework\TestCase;
function socket_create($domain, $type, $protocol)
{
return UDPClientTest::$sockets->socket_create($domain, $type, $protocol);
}
function socket_sendto($socket, $buf, $len, $flags, $addr, $port)
{
return UDPClientTest::$sockets->socket_sendto($socket, $buf, $len, $flags, $addr, $port);
}
function socket_close($socket)
{
return UDPClientTest::$sockets->socket_close($socket);
}
interface SocketHandler
{
public function socket_create($domain, $type, $protocol);
public function socket_sendto($socket, $buf, $len, $flags, $addr, $port);
public function socket_close($socket);
}
class UDPClientTest extends TestCase
{
public static $sockets;
public function setUp()
{
if (!extension_loaded('sockets')) {
$this->markTestSkipped('UDPClient requires sockets extension');
}
parent::setUp();
self::$sockets = null;
}
public function testUsesSockets()
{
$resource = new \stdClass();
$batch = new Batch([
'process' => new Process([
'serviceName' => 'test-app'
]),
'spans' => [
new Span([
'traceIdHigh' => 1234,
'traceIdLow' => 5678,
'spanId' => 9012,
'parentSpanId' => 3456,
'operationName' => 'main',
'flags' => 0,
'startTime' => (int)(microtime(true) * 1000),
'duration' => 1234
])
]
]);
$sockets = $this->prophesize(SocketHandler::class);
$sockets->socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)
->willReturn($resource)
->shouldBeCalled();
$sockets->socket_sendto(
$resource,
Argument::type('string'),
Argument::type('int'),
512,
'1.1.1.1',
1234
)->willReturn(123)->shouldBeCalledTimes(1);
$sockets->socket_close($resource)
->shouldBeCalled();
self::$sockets = $sockets->reveal();
$client = new UDPClient('1.1.1.1', 1234);
$client->emitBatch($batch);
}
}