2020-09-01 12:08:11 -04:00
|
|
|
// Copyright The OpenTelemetry 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.
|
|
|
|
package jaeger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewAgentClientUDPWithParamsBadHostport(t *testing.T) {
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
2021-04-09 09:56:26 -07:00
|
|
|
Host: "blahblah",
|
|
|
|
Port: "",
|
2020-09-01 12:08:11 -04:00
|
|
|
})
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, agentClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewAgentClientUDPWithParams(t *testing.T) {
|
|
|
|
mockServer, err := newUDPListener()
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer mockServer.Close()
|
2021-04-09 09:56:26 -07:00
|
|
|
host, port, err := net.SplitHostPort(mockServer.LocalAddr().String())
|
|
|
|
assert.NoError(t, err)
|
2020-09-01 12:08:11 -04:00
|
|
|
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
2021-04-09 09:56:26 -07:00
|
|
|
Host: host,
|
|
|
|
Port: port,
|
2020-09-01 12:08:11 -04:00
|
|
|
MaxPacketSize: 25000,
|
|
|
|
AttemptReconnecting: true,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, agentClient)
|
|
|
|
assert.Equal(t, 25000, agentClient.maxPacketSize)
|
|
|
|
|
|
|
|
if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
|
|
|
|
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, agentClient.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewAgentClientUDPWithParamsDefaults(t *testing.T) {
|
|
|
|
mockServer, err := newUDPListener()
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer mockServer.Close()
|
2021-04-09 09:56:26 -07:00
|
|
|
host, port, err := net.SplitHostPort(mockServer.LocalAddr().String())
|
|
|
|
assert.NoError(t, err)
|
2020-09-01 12:08:11 -04:00
|
|
|
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
2021-04-09 09:56:26 -07:00
|
|
|
Host: host,
|
|
|
|
Port: port,
|
2020-09-01 12:08:11 -04:00
|
|
|
AttemptReconnecting: true,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, agentClient)
|
|
|
|
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)
|
|
|
|
|
|
|
|
if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
|
|
|
|
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, agentClient.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewAgentClientUDPWithParamsReconnectingDisabled(t *testing.T) {
|
|
|
|
mockServer, err := newUDPListener()
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer mockServer.Close()
|
2021-04-09 09:56:26 -07:00
|
|
|
host, port, err := net.SplitHostPort(mockServer.LocalAddr().String())
|
|
|
|
assert.NoError(t, err)
|
2020-09-01 12:08:11 -04:00
|
|
|
|
|
|
|
agentClient, err := newAgentClientUDP(agentClientUDPParams{
|
2021-04-09 09:56:26 -07:00
|
|
|
Host: host,
|
|
|
|
Port: port,
|
2020-09-01 12:08:11 -04:00
|
|
|
Logger: nil,
|
|
|
|
AttemptReconnecting: false,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, agentClient)
|
|
|
|
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)
|
|
|
|
|
|
|
|
assert.IsType(t, &net.UDPConn{}, agentClient.connUDP)
|
|
|
|
|
|
|
|
assert.NoError(t, agentClient.Close())
|
|
|
|
}
|