Repository: dragonflyoss/Dragonfly2
Pull request #1424 (2022-06-30 10:58:40)

feat: dfstore closes writer
Signed-off-by: Gaius <gaius.qi@gmail.com>

<!--- Provide a general summary of your changes in the Title above -->

## Description
- Dfstore closes writer.
- Dynconfig removes list bucket.
<!--- Describe your changes in detail -->

## Related Issue
#1249 
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## Screenshots (if appropriate)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation Update (if none of the other choices apply)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.



Patch:
diff --git a/client/config/dynconfig.go b/client/config/dynconfig.go
index b20629e4..0b0c0cc7 100644
--- a/client/config/dynconfig.go
+++ b/client/config/dynconfig.go
@@ -44,7 +44,6 @@ var (
 type DynconfigData struct {
 	Schedulers    []*manager.Scheduler
 	ObjectStorage *manager.ObjectStorage
-	Buckets       []*manager.Bucket
 }
 
 type Dynconfig interface {
@@ -54,9 +53,6 @@ type Dynconfig interface {
 	// Get the dynamic object storage config from manager.
 	GetObjectStorage() (*manager.ObjectStorage, error)
 
-	// Get the dynamic buckets config from manager.
-	GetBuckets() ([]*manager.Bucket, error)
-
 	// Get the dynamic config from manager.
 	Get() (*DynconfigData, error)
 
@@ -126,15 +122,6 @@ func (d *dynconfig) GetObjectStorage() (*manager.ObjectStorage, error) {
 	return data.ObjectStorage, nil
 }
 
-func (d *dynconfig) GetBuckets() ([]*manager.Bucket, error) {
-	data, err := d.Get()
-	if err != nil {
-		return nil, err
-	}
-
-	return data.Buckets, nil
-}
-
 func (d *dynconfig) Get() (*DynconfigData, error) {
 	var data DynconfigData
 	if err := d.Unmarshal(&data); err != nil {
@@ -244,18 +231,8 @@ func (mc *managerClient) Get() (any, error) {
 		return nil, err
 	}
 
-	listBucketsResp, err := mc.ListBuckets(&manager.ListBucketsRequest{
-		SourceType: manager.SourceType_PEER_SOURCE,
-		HostName:   mc.hostOption.Hostname,
-		Ip:         mc.hostOption.AdvertiseIP,
-	})
-	if err != nil {
-		return nil, err
-	}
-
 	return DynconfigData{
 		Schedulers:    listSchedulersResp.Schedulers,
 		ObjectStorage: getObjectStorageResp,
-		Buckets:       listBucketsResp.Buckets,
 	}, nil
 }
diff --git a/client/config/mocks/dynconfig_mock.go b/client/config/mocks/dynconfig_mock.go
index 65a79d40..37a4c8ac 100644
--- a/client/config/mocks/dynconfig_mock.go
+++ b/client/config/mocks/dynconfig_mock.go
@@ -62,21 +62,6 @@ func (mr *MockDynconfigMockRecorder) Get() *gomock.Call {
 	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockDynconfig)(nil).Get))
 }
 
-// GetBuckets mocks base method.
-func (m *MockDynconfig) GetBuckets() ([]*manager.Bucket, error) {
-	m.ctrl.T.Helper()
-	ret := m.ctrl.Call(m, "GetBuckets")
-	ret0, _ := ret[0].([]*manager.Bucket)
-	ret1, _ := ret[1].(error)
-	return ret0, ret1
-}
-
-// GetBuckets indicates an expected call of GetBuckets.
-func (mr *MockDynconfigMockRecorder) GetBuckets() *gomock.Call {
-	mr.mock.ctrl.T.Helper()
-	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBuckets", reflect.TypeOf((*MockDynconfig)(nil).GetBuckets))
-}
-
 // GetObjectStorage mocks base method.
 func (m *MockDynconfig) GetObjectStorage() (*manager.ObjectStorage, error) {
 	m.ctrl.T.Helper()
diff --git a/client/dfstore/dfstore.go b/client/dfstore/dfstore.go
index ff71acb0..e7f548a8 100644
--- a/client/dfstore/dfstore.go
+++ b/client/dfstore/dfstore.go
@@ -258,6 +258,10 @@ func (ds *dfstore) PutObjectRequestWithContext(ctx context.Context, input *PutOj
 		return nil, err
 	}
 
+	if err := writer.Close(); err != nil {
+		return nil, err
+	}
+
 	u, err := url.Parse(ds.endpoint)
 	if err != nil {
 		return nil, err


Test patch:
diff --git a/client/config/dynconfig_test.go b/client/config/dynconfig_test.go
index f0cec2de..00b46e4c 100644
--- a/client/config/dynconfig_test.go
+++ b/client/config/dynconfig_test.go
@@ -59,7 +59,6 @@ func TestDynconfigNewDynconfig(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, err error) {
@@ -80,7 +79,6 @@ func TestDynconfigNewDynconfig(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, err error) {
@@ -137,23 +135,6 @@ func TestDynconfigNewDynconfig(t *testing.T) {
 				assert.NoError(err)
 			},
 		},
-		{
-			name:           "new dynconfig and list buckets error",
-			expire:         10 * time.Millisecond,
-			hostOption:     HostOption{},
-			cleanFileCache: func(t *testing.T) {},
-			mock: func(m *mocks.MockClientMockRecorder) {
-				gomock.InOrder(
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
-				)
-			},
-			expect: func(t *testing.T, err error) {
-				assert := assert.New(t)
-				assert.Errorf(err, "foo")
-			},
-		},
 		{
 			name:   "new dynconfig and expire time is empty",
 			expire: 0,
@@ -212,11 +193,6 @@ func TestDynconfigGet(t *testing.T) {
 				ObjectStorage: &manager.ObjectStorage{
 					Name: "foo",
 				},
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
 			},
 			sleep: func() {},
 			cleanFileCache: func(t *testing.T) {
@@ -236,13 +212,6 @@ func TestDynconfigGet(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.ObjectStorage.Name,
-							},
-						},
-					}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -267,11 +236,6 @@ func TestDynconfigGet(t *testing.T) {
 				ObjectStorage: &manager.ObjectStorage{
 					Name: "foo",
 				},
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
 			},
 			sleep: func() {
 				time.Sleep(100 * time.Millisecond)
@@ -285,7 +249,6 @@ func TestDynconfigGet(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{
 						Schedulers: []*manager.Scheduler{
 							{
@@ -296,13 +259,6 @@ func TestDynconfigGet(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.ObjectStorage.Name,
-							},
-						},
-					}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -327,11 +283,6 @@ func TestDynconfigGet(t *testing.T) {
 				ObjectStorage: &manager.ObjectStorage{
 					Name: "foo",
 				},
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
 			},
 			sleep: func() {
 				time.Sleep(100 * time.Millisecond)
@@ -353,13 +304,6 @@ func TestDynconfigGet(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
 				)
 			},
@@ -385,11 +329,6 @@ func TestDynconfigGet(t *testing.T) {
 				ObjectStorage: &manager.ObjectStorage{
 					Name: "foo",
 				},
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
 			},
 			sleep: func() {
 				time.Sleep(100 * time.Millisecond)
@@ -411,13 +350,6 @@ func TestDynconfigGet(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
 				)
@@ -444,11 +376,6 @@ func TestDynconfigGet(t *testing.T) {
 				ObjectStorage: &manager.ObjectStorage{
 					Name: "foo",
 				},
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
 			},
 			sleep: func() {
 				time.Sleep(100 * time.Millisecond)
@@ -470,13 +397,6 @@ func TestDynconfigGet(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{
 						Schedulers: []*manager.Scheduler{
 							{
@@ -500,66 +420,6 @@ func TestDynconfigGet(t *testing.T) {
 				})
 			},
 		},
-		{
-			name:   "list buckets error",
-			expire: 10 * time.Millisecond,
-			hostOption: HostOption{
-				Hostname: "foo",
-			},
-			data: &DynconfigData{
-				Schedulers: []*manager.Scheduler{
-					{
-						HostName: "foo",
-					},
-				},
-				ObjectStorage: &manager.ObjectStorage{
-					Name: "foo",
-				},
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
-			},
-			sleep: func() {
-				time.Sleep(100 * time.Millisecond)
-			},
-			cleanFileCache: func(t *testing.T) {
-				if err := os.Remove(mockCachePath); err != nil {
-					t.Fatal(err)
-				}
-			},
-			mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
-				gomock.InOrder(
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{
-						Schedulers: []*manager.Scheduler{
-							{
-								HostName: data.Schedulers[0].HostName,
-							},
-						},
-					}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
-						Name: data.ObjectStorage.Name,
-					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
-				)
-			},
-			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
-				assert := assert.New(t)
-				result, err := dynconfig.Get()
-				assert.NoError(err)
-				assert.EqualValues(result, data)
-			},
-		},
 		{
 			name:   "resource is empty",
 			expire: 10 * time.Millisecond,
@@ -569,7 +429,6 @@ func TestDynconfigGet(t *testing.T) {
 			data: &DynconfigData{
 				Schedulers:    []*manager.Scheduler(nil),
 				ObjectStorage: &manager.ObjectStorage{},
-				Buckets:       []*manager.Bucket(nil),
 			},
 			sleep: func() {
 				time.Sleep(100 * time.Millisecond)
@@ -583,10 +442,8 @@ func TestDynconfigGet(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -660,7 +517,6 @@ func TestDynconfigGetSchedulers(t *testing.T) {
 						},
 					}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -695,7 +551,6 @@ func TestDynconfigGetSchedulers(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{
 						Schedulers: []*manager.Scheduler{
 							{
@@ -704,7 +559,6 @@ func TestDynconfigGetSchedulers(t *testing.T) {
 						},
 					}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -745,7 +599,6 @@ func TestDynconfigGetSchedulers(t *testing.T) {
 						},
 					}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
 				)
 			},
@@ -777,10 +630,8 @@ func TestDynconfigGetSchedulers(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -848,7 +699,6 @@ func TestDynconfigGetObjectStorage(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -881,12 +731,10 @@ func TestDynconfigGetObjectStorage(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -921,7 +769,6 @@ func TestDynconfigGetObjectStorage(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
 				)
@@ -958,7 +805,6 @@ func TestDynconfigGetObjectStorage(t *testing.T) {
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{
 						Name: data.ObjectStorage.Name,
 					}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(nil, status.Error(codes.NotFound, "")).Times(1),
 				)
@@ -991,10 +837,8 @@ func TestDynconfigGetObjectStorage(t *testing.T) {
 				gomock.InOrder(
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
 					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
 				)
 			},
 			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
@@ -1024,199 +868,3 @@ func TestDynconfigGetObjectStorage(t *testing.T) {
 		})
 	}
 }
-
-func TestDynconfigGetBuckets(t *testing.T) {
-	mockCacheDir := t.TempDir()
-
-	mockCachePath := filepath.Join(mockCacheDir, cacheFileName)
-	tests := []struct {
-		name           string
-		expire         time.Duration
-		hostOption     HostOption
-		data           *DynconfigData
-		sleep          func()
-		cleanFileCache func(t *testing.T)
-		mock           func(m *mocks.MockClientMockRecorder, data *DynconfigData)
-		expect         func(t *testing.T, dynconfig Dynconfig, data *DynconfigData)
-	}{
-		{
-			name:   "get cache buckets",
-			expire: 10 * time.Second,
-			hostOption: HostOption{
-				Hostname: "foo",
-			},
-			data: &DynconfigData{
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
-			},
-			sleep: func() {},
-			cleanFileCache: func(t *testing.T) {
-				if err := os.Remove(mockCachePath); err != nil {
-					t.Fatal(err)
-				}
-			},
-			mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
-				gomock.InOrder(
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
-				)
-			},
-			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
-				assert := assert.New(t)
-				result, err := dynconfig.GetBuckets()
-				assert.NoError(err)
-				assert.EqualValues(result, data.Buckets)
-			},
-		},
-		{
-			name:   "get buckets",
-			expire: 10 * time.Millisecond,
-			hostOption: HostOption{
-				Hostname: "foo",
-			},
-			data: &DynconfigData{
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
-			},
-			sleep: func() {
-				time.Sleep(100 * time.Millisecond)
-			},
-			cleanFileCache: func(t *testing.T) {
-				if err := os.Remove(mockCachePath); err != nil {
-					t.Fatal(err)
-				}
-			},
-			mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
-				gomock.InOrder(
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
-				)
-			},
-			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
-				assert := assert.New(t)
-				result, err := dynconfig.GetBuckets()
-				assert.NoError(err)
-				assert.EqualValues(result, data.Buckets)
-			},
-		},
-		{
-			name:   "list buckets error",
-			expire: 10 * time.Millisecond,
-			hostOption: HostOption{
-				Hostname: "foo",
-			},
-			data: &DynconfigData{
-				Buckets: []*manager.Bucket{
-					{
-						Name: "foo",
-					},
-				},
-			},
-			sleep: func() {
-				time.Sleep(100 * time.Millisecond)
-			},
-			cleanFileCache: func(t *testing.T) {
-				if err := os.Remove(mockCachePath); err != nil {
-					t.Fatal(err)
-				}
-			},
-			mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
-				gomock.InOrder(
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{
-						Buckets: []*manager.Bucket{
-							{
-								Name: data.Buckets[0].Name,
-							},
-						},
-					}, nil).Times(1),
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(nil, errors.New("foo")).Times(1),
-				)
-			},
-			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
-				assert := assert.New(t)
-				result, err := dynconfig.GetBuckets()
-				assert.NoError(err)
-				assert.EqualValues(result, data.Buckets)
-			},
-		},
-		{
-			name:   "buckets is empty",
-			expire: 10 * time.Millisecond,
-			hostOption: HostOption{
-				Hostname: "foo",
-			},
-			data: &DynconfigData{
-				Buckets: []*manager.Bucket(nil),
-			},
-			sleep: func() {
-				time.Sleep(100 * time.Millisecond)
-			},
-			cleanFileCache: func(t *testing.T) {
-				if err := os.Remove(mockCachePath); err != nil {
-					t.Fatal(err)
-				}
-			},
-			mock: func(m *mocks.MockClientMockRecorder, data *DynconfigData) {
-				gomock.InOrder(
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
-					m.ListSchedulers(gomock.Any()).Return(&manager.ListSchedulersResponse{}, nil).Times(1),
-					m.GetObjectStorage(gomock.Any()).Return(&manager.ObjectStorage{}, nil).Times(1),
-					m.ListBuckets(gomock.Any()).Return(&manager.ListBucketsResponse{}, nil).Times(1),
-				)
-			},
-			expect: func(t *testing.T, dynconfig Dynconfig, data *DynconfigData) {
-				assert := assert.New(t)
-				result, err := dynconfig.GetBuckets()
-				assert.NoError(err)
-				assert.EqualValues(result, data.Buckets)
-			},
-		},
-	}
-
-	for _, tc := range tests {
-		t.Run(tc.name, func(t *testing.T) {
-			ctl := gomock.NewController(t)
-			defer ctl.Finish()
-
-			mockManagerClient := mocks.NewMockClient(ctl)
-			tc.mock(mockManagerClient.EXPECT(), tc.data)
-			dynconfig, err := NewDynconfig(mockManagerClient, mockCacheDir, tc.hostOption, tc.expire)
-			if err != nil {
-				t.Fatal(err)
-			}
-
-			tc.sleep()
-			tc.expect(t, dynconfig, tc.data)
-			tc.cleanFileCache(t)
-		})
-	}
-}