closes #7710
[arvados.git] / sdk / go / keepclient / keepclient_test.go
index 4acaf70fe46a8a28a6d6614e0b7e7b145306576d..87b9b1d1eb5652a63c9253fa34aa57db60ef054f 100644 (file)
@@ -16,6 +16,7 @@ import (
        "os"
        "strings"
        "testing"
+       "time"
 )
 
 // Gocheck boilerplate
@@ -143,10 +144,9 @@ func (s *StandaloneSuite) TestUploadToStubKeepServer(c *C) {
                make(chan string)}
 
        UploadToStubHelper(c, st,
-               func(kc *KeepClient, url string, reader io.ReadCloser,
-                       writer io.WriteCloser, upload_status chan uploadStatus) {
+               func(kc *KeepClient, url string, reader io.ReadCloser, writer io.WriteCloser, upload_status chan uploadStatus) {
 
-                       go kc.uploadToKeepServer(url, st.expectPath, reader, upload_status, int64(len("foo")), "TestUploadToStubKeepServer")
+                       go kc.uploadToKeepServer(url, st.expectPath, reader, upload_status, int64(len("foo")), 0)
 
                        writer.Write([]byte("foo"))
                        writer.Close()
@@ -178,7 +178,7 @@ func (s *StandaloneSuite) TestUploadToStubKeepServerBufferReader(c *C) {
 
                        br1 := tr.MakeStreamReader()
 
-                       go kc.uploadToKeepServer(url, st.expectPath, br1, upload_status, 3, "TestUploadToStubKeepServerBufferReader")
+                       go kc.uploadToKeepServer(url, st.expectPath, br1, upload_status, 3, 0)
 
                        writer.Write([]byte("foo"))
                        writer.Close()
@@ -238,7 +238,7 @@ func (s *StandaloneSuite) TestFailedUploadToStubKeepServer(c *C) {
                func(kc *KeepClient, url string, reader io.ReadCloser,
                        writer io.WriteCloser, upload_status chan uploadStatus) {
 
-                       go kc.uploadToKeepServer(url, hash, reader, upload_status, 3, "TestFailedUploadToStubKeepServer")
+                       go kc.uploadToKeepServer(url, hash, reader, upload_status, 3, 0)
 
                        writer.Write([]byte("foo"))
                        writer.Close()
@@ -557,8 +557,10 @@ func (s *StandaloneSuite) TestGetFail(c *C) {
        kc.Retries = 0
 
        r, n, url2, err := kc.Get(hash)
-       errNotFound, _ := err.(ErrNotFound)
+       errNotFound, _ := err.(*ErrNotFound)
        c.Check(errNotFound, NotNil)
+       c.Check(strings.Contains(errNotFound.Error(), "HTTP 500"), Equals, true)
+       c.Check(errNotFound.Temporary(), Equals, true)
        c.Check(n, Equals, int64(0))
        c.Check(url2, Equals, "")
        c.Check(r, Equals, nil)
@@ -603,9 +605,10 @@ func (s *StandaloneSuite) TestGetNetError(c *C) {
        kc.SetServiceRoots(map[string]string{"x": "http://localhost:62222"}, nil, nil)
 
        r, n, url2, err := kc.Get(hash)
-       errNotFound, _ := err.(ErrNotFound)
+       errNotFound, _ := err.(*ErrNotFound)
        c.Check(errNotFound, NotNil)
-       c.Check(strings.Contains(err.Error(), "connection refused"), Equals, true)
+       c.Check(strings.Contains(errNotFound.Error(), "connection refused"), Equals, true)
+       c.Check(errNotFound.Temporary(), Equals, true)
        c.Check(n, Equals, int64(0))
        c.Check(url2, Equals, "")
        c.Check(r, Equals, nil)
@@ -892,7 +895,6 @@ func (s *StandaloneSuite) TestPutProxy(c *C) {
        kc, _ := MakeKeepClient(&arv)
 
        kc.Want_replicas = 2
-       kc.Using_proxy = true
        arv.ApiToken = "abc123"
        localRoots := make(map[string]string)
        writableLocalRoots := make(map[string]string)
@@ -925,7 +927,6 @@ func (s *StandaloneSuite) TestPutProxyInsufficientReplicas(c *C) {
        kc, _ := MakeKeepClient(&arv)
 
        kc.Want_replicas = 3
-       kc.Using_proxy = true
        arv.ApiToken = "abc123"
        localRoots := make(map[string]string)
        writableLocalRoots := make(map[string]string)
@@ -1243,3 +1244,48 @@ func (s *StandaloneSuite) TestPutBRetry(c *C) {
        c.Check(hash, Equals, "")
        c.Check(replicas, Equals, 2)
 }
+
+func (s *ServerRequiredSuite) TestMakeKeepClientWithNonDiskTypeService(c *C) {
+       arv, err := arvadosclient.MakeArvadosClient()
+       c.Assert(err, Equals, nil)
+
+       // Add an additional "testblobstore" keepservice
+       blobKeepService := make(arvadosclient.Dict)
+       err = arv.Create("keep_services",
+               arvadosclient.Dict{"keep_service": arvadosclient.Dict{
+                       "service_host": "localhost",
+                       "service_port": "21321",
+                       "service_type": "testblobstore"}},
+               &blobKeepService)
+       c.Assert(err, Equals, nil)
+       defer func() { arv.Delete("keep_services", blobKeepService["uuid"].(string), nil, nil) }()
+
+       // Make a keepclient and ensure that the testblobstore is included
+       kc, err := MakeKeepClient(&arv)
+       c.Assert(err, Equals, nil)
+
+       // verify kc.LocalRoots
+       c.Check(len(kc.LocalRoots()), Equals, 3)
+       for _, root := range kc.LocalRoots() {
+               c.Check(root, Matches, "http://localhost:\\d+")
+       }
+       c.Assert(kc.LocalRoots()[blobKeepService["uuid"].(string)], Not(Equals), "")
+
+       // verify kc.GatewayRoots
+       c.Check(len(kc.GatewayRoots()), Equals, 3)
+       for _, root := range kc.GatewayRoots() {
+               c.Check(root, Matches, "http://localhost:\\d+")
+       }
+       c.Assert(kc.GatewayRoots()[blobKeepService["uuid"].(string)], Not(Equals), "")
+
+       // verify kc.WritableLocalRoots
+       c.Check(len(kc.WritableLocalRoots()), Equals, 3)
+       for _, root := range kc.WritableLocalRoots() {
+               c.Check(root, Matches, "http://localhost:\\d+")
+       }
+       c.Assert(kc.WritableLocalRoots()[blobKeepService["uuid"].(string)], Not(Equals), "")
+
+       c.Assert(kc.replicasPerService, Equals, 0)
+       c.Assert(kc.foundNonDiskSvc, Equals, true)
+       c.Assert(kc.Client.Timeout, Equals, 300*time.Second)
+}