mirror of
https://github.com/kopia/kopia.git
synced 2026-01-28 08:18:58 -05:00
server: implemented 'flush' and 'refresh' API
Added test that verifies that when client performs Flush (which happens at the end of each snapshot and when repository is closed), the server writes new blobs to the storage. Fixes #464
This commit is contained in:
@@ -135,12 +135,18 @@ func (s *Server) handleAPIPossiblyNotConnected(f func(ctx context.Context, r *ht
|
||||
}
|
||||
|
||||
func (s *Server) handleRefresh(ctx context.Context, r *http.Request) (interface{}, *apiError) {
|
||||
log(ctx).Infof("refreshing")
|
||||
if err := s.rep.Refresh(ctx); err != nil {
|
||||
return nil, internalServerError(err)
|
||||
}
|
||||
|
||||
return &serverapi.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *Server) handleFlush(ctx context.Context, r *http.Request) (interface{}, *apiError) {
|
||||
log(ctx).Infof("flushing")
|
||||
if err := s.rep.Flush(ctx); err != nil {
|
||||
return nil, internalServerError(err)
|
||||
}
|
||||
|
||||
return &serverapi.Empty{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ func (r *apiServerRepository) Refresh(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (r *apiServerRepository) Flush(ctx context.Context) error {
|
||||
return nil
|
||||
return r.cli.Post(ctx, "flush", nil, nil)
|
||||
}
|
||||
|
||||
func (r *apiServerRepository) Close(ctx context.Context) error {
|
||||
@@ -126,7 +126,7 @@ func (r *apiServerRepository) Close(ctx context.Context) error {
|
||||
return errors.Wrap(err, "error closing object manager")
|
||||
}
|
||||
|
||||
return nil
|
||||
return r.Flush(ctx)
|
||||
}
|
||||
|
||||
func (r *apiServerRepository) ContentInfo(ctx context.Context, contentID content.ID) (content.Info, error) {
|
||||
|
||||
@@ -33,6 +33,9 @@ func TestAPIServerRepository(t *testing.T) {
|
||||
e1.RunAndExpectSuccess(t, "repo", "connect", "filesystem", "--path", e.RepoDir, "--override-username", "not-foo", "--override-hostname", "bar")
|
||||
e1.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1)
|
||||
|
||||
originalPBlobCount := len(e1.RunAndExpectSuccess(t, "blob", "list", "--prefix=p"))
|
||||
originalQBlobCount := len(e1.RunAndExpectSuccess(t, "blob", "list", "--prefix=q"))
|
||||
|
||||
htpasswordFile := filepath.Join(e.ConfigDir, "htpasswd.txt")
|
||||
ioutil.WriteFile(htpasswordFile, htpasswdFileContents, 0755)
|
||||
|
||||
@@ -81,12 +84,35 @@ func TestAPIServerRepository(t *testing.T) {
|
||||
t.Errorf("invalid number of snapshots for foo@bar")
|
||||
}
|
||||
|
||||
// create very small directory
|
||||
smallDataDir := filepath.Join(sharedTestDataDirBase, "dir-small")
|
||||
|
||||
testenv.CreateDirectoryTree(smallDataDir, testenv.DirectoryTreeOptions{
|
||||
Depth: 1,
|
||||
MaxSubdirsPerDirectory: 1,
|
||||
MaxFilesPerDirectory: 1,
|
||||
MaxFileSize: 100,
|
||||
}, nil)
|
||||
|
||||
// create snapshot of a very small directory using remote repository client
|
||||
e2.RunAndExpectSuccess(t, "snapshot", "create", smallDataDir)
|
||||
|
||||
// make sure snapshot created by the client resulted in blobs being created by the server
|
||||
// as opposed to buffering it in memory
|
||||
if got, want := len(e.RunAndExpectSuccess(t, "blob", "list", "--prefix=p")), originalPBlobCount; got <= want {
|
||||
t.Errorf("unexpected number of P blobs on the server: %v, wanted > %v", got, want)
|
||||
}
|
||||
|
||||
if got, want := len(e.RunAndExpectSuccess(t, "blob", "list", "--prefix=q")), originalQBlobCount; got <= want {
|
||||
t.Errorf("unexpected number of Q blobs on the server: %v, wanted > %v", got, want)
|
||||
}
|
||||
|
||||
// create snapshot using remote repository client
|
||||
e2.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2)
|
||||
|
||||
// now should see two snapshots
|
||||
snapshots = e2.ListSnapshotsAndExpectSuccess(t)
|
||||
if got, want := len(snapshots), 2; got != want {
|
||||
if got, want := len(snapshots), 3; got != want {
|
||||
t.Errorf("invalid number of snapshots for foo@bar")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user