[ARVADOS] updated: 23ac9d35b87e4930fc01318d44134693f62c1264

git at public.curoverse.com git at public.curoverse.com
Wed Sep 30 11:47:52 EDT 2015


Summary of changes:
 sdk/go/keepclient/keepclient.go      |  4 +-
 services/keepproxy/keepproxy.go      | 18 +++------
 services/keepproxy/keepproxy_test.go | 77 ++++++++++++++++--------------------
 3 files changed, 40 insertions(+), 59 deletions(-)

       via  23ac9d35b87e4930fc01318d44134693f62c1264 (commit)
       via  18686feffd9e3de30184d6667726bcff5db8b820 (commit)
      from  d53271e587b7bdbfe37b8ae8eaf890dd69c2796b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 23ac9d35b87e4930fc01318d44134693f62c1264
Author: radhika <radhika at curoverse.com>
Date:   Wed Sep 30 11:46:41 2015 -0400

    7200: more compact CheckAuthorizationHeader block

diff --git a/services/keepproxy/keepproxy.go b/services/keepproxy/keepproxy.go
index 53bcddf..7900096 100644
--- a/services/keepproxy/keepproxy.go
+++ b/services/keepproxy/keepproxy.go
@@ -515,16 +515,15 @@ func (handler IndexHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques
 
 	kc := *handler.KeepClient
 
-	var pass bool
-	var tok string
-	if pass, tok = CheckAuthorizationHeader(kc, handler.ApiTokenCache, req); !pass {
+	ok, token := CheckAuthorizationHeader(kc, handler.ApiTokenCache, req)
+	if !ok {
 		status, err = http.StatusForbidden, BadAuthorizationHeader
 		return
 	}
 
 	// Copy ArvadosClient struct and use the client's API token
 	arvclient := *kc.Arvados
-	arvclient.ApiToken = tok
+	arvclient.ApiToken = token
 	kc.Arvados = &arvclient
 
 	// Only GET method is supported
@@ -542,7 +541,7 @@ func (handler IndexHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques
 			return
 		}
 
-		_, err := io.Copy(resp, reader)
+		_, err = io.Copy(resp, reader)
 		if err != nil {
 			status = http.StatusBadGateway
 			return

commit 18686feffd9e3de30184d6667726bcff5db8b820
Author: radhika <radhika at curoverse.com>
Date:   Wed Sep 30 11:28:36 2015 -0400

    7200: Use io.Copy instead of reading all bytes and writing to response. Much improved keep proxy test with code reuse.

diff --git a/sdk/go/keepclient/keepclient.go b/sdk/go/keepclient/keepclient.go
index 541ca68..53dfb2b 100644
--- a/sdk/go/keepclient/keepclient.go
+++ b/sdk/go/keepclient/keepclient.go
@@ -218,12 +218,12 @@ func (kc *KeepClient) GetIndex(keepServiceUUID, prefix string) (io.Reader, error
 		return nil, err
 	}
 
+	defer resp.Body.Close()
+
 	if resp.StatusCode != http.StatusOK {
 		return nil, fmt.Errorf("Got http status code: %d", resp.StatusCode)
 	}
 
-	defer resp.Body.Close()
-
 	var respBody []byte
 	respBody, err = ioutil.ReadAll(resp.Body)
 	if err != nil {
diff --git a/services/keepproxy/keepproxy.go b/services/keepproxy/keepproxy.go
index f2a93f1..53bcddf 100644
--- a/services/keepproxy/keepproxy.go
+++ b/services/keepproxy/keepproxy.go
@@ -533,6 +533,7 @@ func (handler IndexHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques
 		return
 	}
 
+	// Get index from all LocalRoots and write to resp
 	var reader io.Reader
 	for uuid := range kc.LocalRoots() {
 		reader, err = kc.GetIndex(uuid, prefix)
@@ -541,15 +542,7 @@ func (handler IndexHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques
 			return
 		}
 
-		var readBytes []byte
-		readBytes, err = ioutil.ReadAll(reader)
-		if err != nil {
-			status = http.StatusBadGateway
-			return
-		}
-
-		// Got index for this server; write to resp
-		_, err := resp.Write(readBytes)
+		_, err := io.Copy(resp, reader)
 		if err != nil {
 			status = http.StatusBadGateway
 			return
diff --git a/services/keepproxy/keepproxy_test.go b/services/keepproxy/keepproxy_test.go
index c623454..6fe8fe7 100644
--- a/services/keepproxy/keepproxy_test.go
+++ b/services/keepproxy/keepproxy_test.go
@@ -418,7 +418,7 @@ func (s *ServerRequiredSuite) TestGetIndex(c *C) {
 	waitForListener()
 	defer closeListener()
 
-	// Write "index-data" blocks
+	// Put "index-data" blocks
 	data := []byte("index-data")
 	hash := fmt.Sprintf("%x", md5.Sum(data))
 
@@ -433,54 +433,43 @@ func (s *ServerRequiredSuite) TestGetIndex(c *C) {
 	all, err := ioutil.ReadAll(reader)
 	c.Check(all, DeepEquals, data)
 
-	// Write some more blocks
-	otherData := []byte("some-more-index-data")
-	otherHash := fmt.Sprintf("%x", md5.Sum(otherData))
-	_, rep, err = kc.PutB(otherData)
+	// Put some more blocks
+	_, rep, err = kc.PutB([]byte("some-more-index-data"))
 	c.Check(err, Equals, nil)
 
-	// GetIndex with no prefix; expect both data and otherData blocks
-	indexReader, err := kc.GetIndex("proxy", "")
-	c.Assert(err, Equals, nil)
-	indexResp, err := ioutil.ReadAll(indexReader)
-	locators := strings.Split(string(indexResp), "\n")
-	matchingLocators := 0
-	otherLocators := 0
-	for _, locator := range locators {
-		if strings.HasPrefix(locator, hash) {
-			matchingLocators++
-		} else if strings.HasPrefix(locator, otherHash) {
-			otherLocators++
-		}
-	}
-	c.Assert(2, Equals, matchingLocators)
-	c.Assert(2, Equals, otherLocators)
-
-	// GetIndex with prefix
-	indexReader, err = kc.GetIndex("proxy", hash[0:3])
-	c.Assert(err, Equals, nil)
-	indexResp, err = ioutil.ReadAll(indexReader)
-	locators = strings.Split(string(indexResp), "\n")
-	totalLocators := 0
-	matchingLocators = 0
-	for _, locator := range locators {
-		if locator != "" {
-			totalLocators++
-		}
-		if strings.HasPrefix(locator, hash[0:3]) {
-			matchingLocators++
+	// Invoke GetIndex
+	for _, spec := range []struct {
+		prefix         string
+		expectTestHash bool
+		expectOther    bool
+	}{
+		{"", true, true},         // with no prefix
+		{hash[:3], true, false},  // with matching prefix
+		{"abcdef", false, false}, // with no such prefix
+	} {
+		indexReader, err := kc.GetIndex("proxy", spec.prefix)
+		c.Assert(err, Equals, nil)
+		indexResp, err := ioutil.ReadAll(indexReader)
+		c.Assert(err, Equals, nil)
+		locators := strings.Split(string(indexResp), "\n")
+		gotTestHash := 0
+		gotOther := 0
+		for _, locator := range locators {
+			if locator == "" {
+				continue
+			}
+			c.Check(locator[:len(spec.prefix)], Equals, spec.prefix)
+			if locator[:32] == hash {
+				gotTestHash++
+			} else {
+				gotOther++
+			}
 		}
+		c.Check(gotTestHash == 2, Equals, spec.expectTestHash)
+		c.Check(gotOther > 0, Equals, spec.expectOther)
 	}
-	c.Assert(2, Equals, matchingLocators)
-	c.Assert(totalLocators, Equals, matchingLocators)
-
-	// GetIndex with valid but no such prefix
-	indexReader, err = kc.GetIndex("proxy", "abcd")
-	c.Assert(err, Equals, nil)
-	indexResp, err = ioutil.ReadAll(indexReader)
-	c.Assert(string(indexResp), Equals, "")
 
 	// GetIndex with invalid prefix
-	indexReader, err = kc.GetIndex("proxy", "xyz")
+	_, err = kc.GetIndex("proxy", "xyz")
 	c.Assert((err != nil), Equals, true)
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list