Changed portallocator New() method to Get()

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-05-14 21:59:17 +00:00
parent a76c5e1490
commit 4a3c7e1bb5
3 changed files with 13 additions and 13 deletions

View File

@ -80,8 +80,8 @@ type (
protoMap map[string]*portMap
)
// New returns a new instance of PortAllocator
func New() *PortAllocator {
// Get returns the default instance of PortAllocator
func Get() *PortAllocator {
// Port Allocator is a singleton
// Note: Long term solution will be each PortAllocator will have access to
// the OS so that it can have up to date view of the OS port allocation.

View File

@ -12,7 +12,7 @@ func resetPortAllocator() {
}
func TestRequestNewPort(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
port, err := p.RequestPort(defaultIP, "tcp", 0)
@ -26,7 +26,7 @@ func TestRequestNewPort(t *testing.T) {
}
func TestRequestSpecificPort(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
port, err := p.RequestPort(defaultIP, "tcp", 5000)
@ -40,7 +40,7 @@ func TestRequestSpecificPort(t *testing.T) {
}
func TestReleasePort(t *testing.T) {
p := New()
p := Get()
port, err := p.RequestPort(defaultIP, "tcp", 5000)
if err != nil {
@ -56,7 +56,7 @@ func TestReleasePort(t *testing.T) {
}
func TestReuseReleasedPort(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
port, err := p.RequestPort(defaultIP, "tcp", 5000)
@ -78,7 +78,7 @@ func TestReuseReleasedPort(t *testing.T) {
}
func TestReleaseUnreadledPort(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
port, err := p.RequestPort(defaultIP, "tcp", 5000)
@ -99,13 +99,13 @@ func TestReleaseUnreadledPort(t *testing.T) {
}
func TestUnknowProtocol(t *testing.T) {
if _, err := New().RequestPort(defaultIP, "tcpp", 0); err != ErrUnknownProtocol {
if _, err := Get().RequestPort(defaultIP, "tcpp", 0); err != ErrUnknownProtocol {
t.Fatalf("Expected error %s got %s", ErrUnknownProtocol, err)
}
}
func TestAllocateAllPorts(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
for i := 0; i <= p.End-p.Begin; i++ {
@ -156,7 +156,7 @@ func TestAllocateAllPorts(t *testing.T) {
}
func BenchmarkAllocatePorts(b *testing.B) {
p := New()
p := Get()
defer resetPortAllocator()
for i := 0; i < b.N; i++ {
@ -175,7 +175,7 @@ func BenchmarkAllocatePorts(b *testing.B) {
}
func TestPortAllocation(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
ip := net.ParseIP("192.168.0.1")
@ -237,7 +237,7 @@ func TestPortAllocation(t *testing.T) {
}
func TestNoDuplicateBPR(t *testing.T) {
p := New()
p := Get()
defer resetPortAllocator()
if port, err := p.RequestPort(defaultIP, "tcp", p.Begin); err != nil {

View File

@ -42,7 +42,7 @@ type PortMapper struct {
// New returns a new instance of PortMapper
func New() *PortMapper {
return NewWithPortAllocator(portallocator.New())
return NewWithPortAllocator(portallocator.Get())
}
// NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator