// This one should be used:
ks := RunFakeKeepServer(StubGetHandler{
c,
- hash+"+K@"+uuid,
+ hash + "+K@" + uuid,
"abc123",
http.StatusOK,
[]byte("foo")})
map[string]string{"x": ks0.url},
map[string]string{uuid: ks.url})
- r, n, uri, err := kc.Get(hash+"+K@"+uuid)
+ r, n, uri, err := kc.Get(hash + "+K@" + uuid)
+ defer r.Close()
+ c.Check(err, Equals, nil)
+ c.Check(n, Equals, int64(3))
+ c.Check(uri, Equals, fmt.Sprintf("%s/%s", ks.url, hash+"+K@"+uuid))
+
+ content, err := ioutil.ReadAll(r)
+ c.Check(err, Equals, nil)
+ c.Check(content, DeepEquals, []byte("foo"))
+}
+
+// Use a service hint to fetch from a local disk service, overriding
+// rendezvous probe order.
+func (s *StandaloneSuite) TestGetWithLocalServiceHint(c *C) {
+ uuid := "zzzzz-bi6l4-zzzzzzzzzzzzzzz"
+ hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
+
+ // This one shouldn't be used, although it appears first in
+ // rendezvous probe order:
+ ks0 := RunFakeKeepServer(StubGetHandler{
+ c,
+ "error if used",
+ "abc123",
+ http.StatusOK,
+ []byte("foo")})
+ defer ks0.listener.Close()
+ // This one should be used:
+ ks := RunFakeKeepServer(StubGetHandler{
+ c,
+ hash + "+K@" + uuid,
+ "abc123",
+ http.StatusOK,
+ []byte("foo")})
+ defer ks.listener.Close()
+
+ arv, err := arvadosclient.MakeArvadosClient()
+ kc, _ := MakeKeepClient(&arv)
+ arv.ApiToken = "abc123"
+ kc.SetServiceRoots(
+ map[string]string{
+ "zzzzz-bi6l4-yyyyyyyyyyyyyyy": ks0.url,
+ "zzzzz-bi6l4-xxxxxxxxxxxxxxx": ks0.url,
+ "zzzzz-bi6l4-wwwwwwwwwwwwwww": ks0.url,
+ uuid: ks.url},
+ map[string]string{
+ "zzzzz-bi6l4-yyyyyyyyyyyyyyy": ks0.url,
+ "zzzzz-bi6l4-xxxxxxxxxxxxxxx": ks0.url,
+ "zzzzz-bi6l4-wwwwwwwwwwwwwww": ks0.url,
+ uuid: ks.url},
+ )
+
+ r, n, uri, err := kc.Get(hash + "+K@" + uuid)
defer r.Close()
c.Check(err, Equals, nil)
c.Check(n, Equals, int64(3))
ksLocal := RunFakeKeepServer(StubGetHandler{
c,
- hash+"+K@"+uuid,
+ hash + "+K@" + uuid,
"abc123",
http.StatusOK,
[]byte("foo")})
defer ksLocal.listener.Close()
ksGateway := RunFakeKeepServer(StubGetHandler{
c,
- hash+"+K@"+uuid,
+ hash + "+K@" + uuid,
"abc123",
http.StatusInternalServerError,
[]byte("Error")})
map[string]string{"zzzzz-bi6l4-keepdisk0000000": ksLocal.url},
map[string]string{uuid: ksGateway.url})
- r, n, uri, err := kc.Get(hash+"+K@"+uuid)
+ r, n, uri, err := kc.Get(hash + "+K@" + uuid)
c.Assert(err, Equals, nil)
defer r.Close()
c.Check(n, Equals, int64(3))
c.Check(l.Hints, DeepEquals, []string{"Aabcde@12345678"})
}
+func (s *StandaloneSuite) TestMakeLocatorPreservesUnrecognizedHints(c *C) {
+ str := "91f372a266fe2bf2823cb8ec7fda31ce+3+Unknown+Kzzzzz+Afoobar"
+ l, err := MakeLocator(str)
+ c.Check(err, Equals, nil)
+ c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce")
+ c.Check(l.Size, Equals, 3)
+ c.Check(l.Hints, DeepEquals, []string{"3", "Unknown", "Kzzzzz", "Afoobar"})
+ c.Check(l.String(), Equals, str)
+}
+
func (s *StandaloneSuite) TestMakeLocatorInvalidInput(c *C) {
_, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31c")
c.Check(err, Equals, InvalidLocatorError)