소스 검색

Changed portallocator New() method to Get()

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Jana Radhakrishnan 10 년 전
부모
커밋
4a3c7e1bb5
3개의 변경된 파일13개의 추가작업 그리고 13개의 파일을 삭제
  1. 2 2
      libnetwork/pkg/portallocator/portallocator.go
  2. 10 10
      libnetwork/pkg/portallocator/portallocator_test.go
  3. 1 1
      libnetwork/portmapper/mapper.go

+ 2 - 2
libnetwork/pkg/portallocator/portallocator.go

@@ -80,8 +80,8 @@ type (
 	protoMap map[string]*portMap
 	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
 	// Port Allocator is a singleton
 	// Note: Long term solution will be each PortAllocator will have access to
 	// 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.
 	// the OS so that it can have up to date view of the OS port allocation.

+ 10 - 10
libnetwork/pkg/portallocator/portallocator_test.go

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

+ 1 - 1
libnetwork/portmapper/mapper.go

@@ -42,7 +42,7 @@ type PortMapper struct {
 
 
 // New returns a new instance of PortMapper
 // New returns a new instance of PortMapper
 func New() *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
 // NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator