"http://keep.zzzzz.arvadosapi.com:25107/2228819a18d3727630fa30c81853d23f+67108864+K@zzzzz-zzzzz-zzzzzzzzzzzzzzz+A37b6ab198qqqq28d903b975266b23ee711e1852c@55635f73")
}
+
+// Test GetIndex
+// Put one block, with 2 replicas
+// With no prefix (expect the block locator, twice)
+// With an existing prefix (expect the block locator, twice)
+// With a valid but non-existing prefix (expect "\n")
+// With an invalid prefix (expect error)
+func (s *ServerRequiredSuite) TestGetIndex(c *C) {
+ kc := runProxy(c, []string{"keepproxy"}, 28852, false)
+ waitForListener()
+ defer closeListener()
+
+ // Write "index-data" blocks
+ data := []byte("index-data")
+ hash := fmt.Sprintf("%x", md5.Sum(data))
+
+ hash2, rep, err := kc.PutB(data)
+ c.Check(hash2, Matches, fmt.Sprintf(`^%s\+10(\+.+)?$`, hash))
+ c.Check(rep, Equals, 2)
+ c.Check(err, Equals, nil)
+
+ reader, blocklen, _, err := kc.Get(hash)
+ c.Assert(err, Equals, nil)
+ c.Check(blocklen, Equals, int64(10))
+ 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)
+ 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++
+ }
+ }
+ 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")
+ c.Assert((err != nil), Equals, true)
+}