Files
zeekay 873220f90b rebrand: openziti → hanzozt (Hanzo Zero Trust)
Global rebrand of all OpenZiti references to Hanzo ZT:
- Go module paths: github.com/openziti/* → github.com/hanzozt/*
- Docker images: openziti/* → hanzozt/*
- Java packages: org.openziti.* → org.hanzozt.*
- Brand: OpenZiti → Hanzo ZT
- URLs: openziti.io → hanzozt.dev
2026-02-18 16:13:53 -08:00

127 lines
2.3 KiB
Go

package xlink_transport
import (
"crypto/x509"
"fmt"
"net"
"testing"
"time"
"github.com/hanzozt/channel/v4"
"github.com/hanzozt/metrics"
"github.com/stretchr/testify/assert"
)
type testUnderlay struct {
}
func (t testUnderlay) Rx() (*channel.Message, error) {
time.Sleep(time.Hour)
return nil, nil
}
func (t testUnderlay) Tx(*channel.Message) error {
time.Sleep(10 * time.Microsecond)
return nil
}
func (t testUnderlay) Id() string {
return "test"
}
func (t testUnderlay) LogicalName() string {
return "test"
}
func (t testUnderlay) ConnectionId() string {
return "test"
}
func (t testUnderlay) Certificates() []*x509.Certificate {
return nil
}
func (t testUnderlay) Label() string {
return "test"
}
func (t testUnderlay) Close() error {
return nil
}
func (t testUnderlay) IsClosed() bool {
return false
}
func (t testUnderlay) Headers() map[int32][]byte {
return nil
}
func (t testUnderlay) SetWriteTimeout(time.Duration) error {
return nil
}
func (t testUnderlay) SetWriteDeadline(time.Time) error {
return nil
}
func (t testUnderlay) GetLocalAddr() net.Addr {
panic("implement me")
}
func (t testUnderlay) GetRemoteAddr() net.Addr {
panic("implement me")
}
type testUnderlayFactory struct {
underlay testUnderlay
}
func (t testUnderlayFactory) Create(time.Duration) (channel.Underlay, error) {
return t.underlay, nil
}
func Test_Throughput(t *testing.T) {
t.SkipNow()
underlayFactory := testUnderlayFactory{
underlay: testUnderlay{},
}
options := channel.DefaultOptions()
options.OutQueueSize = 64
ch, err := channel.NewChannel("test", underlayFactory, nil, options)
assert.NoError(t, err)
registry := metrics.NewRegistry("test", nil)
drops := registry.Meter("drops")
msgs := registry.Meter("msgs")
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for range ticker.C {
v := registry.Poll().Meters["drops"]
fmt.Printf("drops - m1: %v, count: %v\n", v.M1Rate, v.Count)
v = registry.Poll().Meters["msgs"]
fmt.Printf("msgs - m1: %v, count: %v\n", v.M1Rate, v.Count)
}
}()
go func() {
for {
m := channel.NewMessage(1, nil)
sent, err := ch.TrySend(m)
assert.NoError(t, err)
if !sent {
drops.Mark(1)
}
msgs.Mark(1)
time.Sleep(10 * time.Microsecond)
}
}()
time.Sleep(time.Minute)
}