Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up collaborator feature #713

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,48 +1421,6 @@ func (a *Allocation) CancelRepair() error {
return errors.New("invalid_cancel_repair_request", "No repair in progress for the allocation")
}

func (a *Allocation) AddCollaborator(filePath, collaboratorID string) error {
if !a.isInitialized() {
return notInitialized
}

req := &CollaboratorRequest{
path: filePath,
collaboratorID: collaboratorID,
a: a,
consensus: Consensus{
fullconsensus: a.fullconsensus,
consensusThresh: a.consensusThreshold,
},
}

if req.UpdateCollaboratorToBlobbers() {
return nil
}
return errors.New("add_collaborator_failed", "Failed to add collaborator on all blobbers.")
}

func (a *Allocation) RemoveCollaborator(filePath, collaboratorID string) error {
if !a.isInitialized() {
return notInitialized
}

req := &CollaboratorRequest{
path: filePath,
collaboratorID: collaboratorID,
a: a,
consensus: Consensus{
fullconsensus: a.fullconsensus,
consensusThresh: a.consensusThreshold,
},
}

if req.RemoveCollaboratorFromBlobbers() {
return nil
}
return errors.New("remove_collaborator_failed", "Failed to remove collaborator on all blobbers.")
}

func (a *Allocation) GetMaxWriteReadFromBlobbers(blobbers []*BlobberAllocation) (maxW float64, maxR float64, err error) {
if !a.isInitialized() {
return 0, 0, notInitialized
Expand Down
178 changes: 0 additions & 178 deletions zboxcore/sdk/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,184 +972,6 @@ func TestAllocation_downloadFile(t *testing.T) {
}
}

func TestAllocation_AddCollaborator(t *testing.T) {
var mockClient = mocks.HttpClient{}
zboxutil.Client = &mockClient

client := zclient.GetClient()
client.Wallet = &zcncrypto.Wallet{
ClientID: mockClientId,
ClientKey: mockClientKey,
}

type parameters struct {
filePath string
collaboratorID string
}
tests := []struct {
name string
parameters parameters
setup func(*testing.T, string, *Allocation) (teardown func(*testing.T))
wantErr bool
errMsg string
}{
{
name: "Test_Uninitialized_Failed",
setup: func(t *testing.T, testCaseName string, a *Allocation) (teardown func(t *testing.T)) {
a.initialized = false
return func(t *testing.T) {
a.initialized = true
}
},
wantErr: true,
errMsg: "sdk_not_initialized: Please call InitStorageSDK Init and use GetAllocation to get the allocation object",
},
{
name: "Test_Add_Collaborator_Error_Response_Failed",
parameters: parameters{
filePath: "/1.txt",
collaboratorID: "9bf430d6f086f1bdc2d26ad7a708a0e7958aa9ae20efbc6778450739fb1ca468",
},
setup: func(t *testing.T, testCaseName string, a *Allocation) (teardown func(t *testing.T)) {
setupMockHttpResponse(t, &mockClient, "TestAllocation_AddCollaborator", testCaseName, a, http.MethodPost, http.StatusBadRequest, []byte(""))
return nil
},
wantErr: true,
errMsg: "add_collaborator_failed: Failed to add collaborator on all blobbers.",
},
{
name: "Test_Success",
parameters: parameters{
filePath: "/1.txt",
collaboratorID: "9bf430d6f086f1bdc2d26ad7a708a0e7958aa9ae20efbc6778450739fb1ca468",
},
setup: func(t *testing.T, testCaseName string, a *Allocation) (teardown func(t *testing.T)) {
setupMockHttpResponse(t, &mockClient, "TestAllocation_AddCollaborator", testCaseName, a, http.MethodPost, http.StatusOK, []byte(""))
return nil
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
a := &Allocation{
DataShards: 2,
ParityShards: 2,
FileOptions: 63,
}
a.InitAllocation()
sdkInitialized = true
for i := 0; i < numBlobbers; i++ {
a.Blobbers = append(a.Blobbers, &blockchain.StorageNode{
ID: tt.name + mockBlobberId + strconv.Itoa(i),
Baseurl: "TestAllocation_AddCollaborator" + tt.name + mockBlobberUrl + strconv.Itoa(i),
})
}
if tt.setup != nil {
if teardown := tt.setup(t, tt.name, a); teardown != nil {
defer teardown(t)
}
}
err := a.AddCollaborator(tt.parameters.filePath, tt.parameters.collaboratorID)
require.EqualValues(tt.wantErr, err != nil)
if err != nil {
require.EqualValues(tt.errMsg, errors.Top(err))
return
}
require.NoErrorf(err, "unexpected error: %v", err)
})
}
}

func TestAllocation_RemoveCollaborator(t *testing.T) {
var mockClient = mocks.HttpClient{}
zboxutil.Client = &mockClient

client := zclient.GetClient()
client.Wallet = &zcncrypto.Wallet{
ClientID: mockClientId,
ClientKey: mockClientKey,
}

type parameters struct {
filePath string
collaboratorID string
}
tests := []struct {
name string
parameters parameters
setup func(*testing.T, string, *Allocation) (teardown func(*testing.T))
wantErr bool
errMsg string
}{
{
name: "Test_Uninitialized_Failed",
setup: func(t *testing.T, testCaseName string, a *Allocation) (teardown func(t *testing.T)) {
a.initialized = false
return func(t *testing.T) {
a.initialized = true
}
},
wantErr: true,
errMsg: "sdk_not_initialized: Please call InitStorageSDK Init and use GetAllocation to get the allocation object",
},
{
name: "Test_Remove_Collaborator_Error_Response_Failed",
parameters: parameters{
filePath: "/1.txt",
collaboratorID: "9bf430d6f086f1bdc2d26ad7a708a0e7958aa9ae20efbc6778450739fb1ca468",
},
setup: func(t *testing.T, testCaseName string, a *Allocation) (teardown func(t *testing.T)) {
setupMockHttpResponse(t, &mockClient, "TestAllocation_RemoveCollaborator", testCaseName, a, http.MethodDelete, http.StatusBadRequest, []byte(""))
return nil
},
wantErr: true,
errMsg: "remove_collaborator_failed: Failed to remove collaborator on all blobbers.",
},
{
name: "Test_Success",
parameters: parameters{
filePath: "/1.txt",
collaboratorID: "9bf430d6f086f1bdc2d26ad7a708a0e7958aa9ae20efbc6778450739fb1ca468",
},
setup: func(t *testing.T, testCaseName string, a *Allocation) (teardown func(t *testing.T)) {
setupMockHttpResponse(t, &mockClient, "TestAllocation_RemoveCollaborator", testCaseName, a, http.MethodDelete, http.StatusOK, []byte(""))
return nil
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
a := &Allocation{
DataShards: 2,
ParityShards: 2,
FileOptions: 63,
}
a.InitAllocation()
sdkInitialized = true
for i := 0; i < numBlobbers; i++ {
a.Blobbers = append(a.Blobbers, &blockchain.StorageNode{
ID: tt.name + mockBlobberId + strconv.Itoa(i),
Baseurl: "TestAllocation_RemoveCollaborator" + tt.name + mockBlobberUrl + strconv.Itoa(i),
})
}
if tt.setup != nil {
if teardown := tt.setup(t, tt.name, a); teardown != nil {
defer teardown(t)
}
}
err := a.RemoveCollaborator(tt.parameters.filePath, tt.parameters.collaboratorID)
require.EqualValues(tt.wantErr, err != nil)
if err != nil {
require.EqualValues(tt.errMsg, errors.Top(err))
return
}
require.NoErrorf(err, "unexpected error: %v", err)
})
}
}

func TestAllocation_GetFileMeta(t *testing.T) {
const (
mockType = "f"
Expand Down
132 changes: 0 additions & 132 deletions zboxcore/sdk/collaboratorworker.go

This file was deleted.

Loading