Skip to content

Commit d305d9b

Browse files
authored
chunk, storage: storage with multi chunk Set method (ethersphere#1684)
1 parent f527723 commit d305d9b

File tree

7 files changed

+355
-241
lines changed

7 files changed

+355
-241
lines changed

chunk/chunk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ type Store interface {
247247
Put(ctx context.Context, mode ModePut, chs ...Chunk) (exist []bool, err error)
248248
Has(ctx context.Context, addr Address) (yes bool, err error)
249249
HasMulti(ctx context.Context, addrs ...Address) (yes []bool, err error)
250-
Set(ctx context.Context, mode ModeSet, addr Address) (err error)
250+
Set(ctx context.Context, mode ModeSet, addrs ...Address) (err error)
251251
LastPullSubscriptionBinID(bin uint8) (id uint64, err error)
252252
SubscribePull(ctx context.Context, bin uint8, since, until uint64) (c <-chan Descriptor, stop func())
253253
Close() (err error)

storage/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (m *MapChunkStore) HasMulti(ctx context.Context, refs ...Address) (have []b
281281
return have, nil
282282
}
283283

284-
func (m *MapChunkStore) Set(ctx context.Context, mode chunk.ModeSet, addr chunk.Address) (err error) {
284+
func (m *MapChunkStore) Set(ctx context.Context, mode chunk.ModeSet, addrs ...chunk.Address) (err error) {
285285
return nil
286286
}
287287

storage/localstore/localstore_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,33 @@ func chunkAddresses(chunks []chunk.Chunk) []chunk.Address {
204204
return addrs
205205
}
206206

207+
// Standard test cases to validate multi chunk operations.
208+
var multiChunkTestCases = []struct {
209+
name string
210+
count int
211+
}{
212+
{
213+
name: "one",
214+
count: 1,
215+
},
216+
{
217+
name: "two",
218+
count: 2,
219+
},
220+
{
221+
name: "eight",
222+
count: 8,
223+
},
224+
{
225+
name: "hundred",
226+
count: 100,
227+
},
228+
{
229+
name: "thousand",
230+
count: 1000,
231+
},
232+
}
233+
207234
// TestGenerateTestRandomChunk validates that
208235
// generateTestRandomChunk returns random data by comparing
209236
// two generated chunks.

storage/localstore/mode_put_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -318,32 +318,6 @@ func TestModePut_sameChunk(t *testing.T) {
318318
}
319319
}
320320

321-
var multiChunkTestCases = []struct {
322-
name string
323-
count int
324-
}{
325-
{
326-
name: "one",
327-
count: 1,
328-
},
329-
{
330-
name: "two",
331-
count: 2,
332-
},
333-
{
334-
name: "eight",
335-
count: 8,
336-
},
337-
{
338-
name: "hundred",
339-
count: 100,
340-
},
341-
{
342-
name: "thousand",
343-
count: 1000,
344-
},
345-
}
346-
347321
// TestPutDuplicateChunks validates the expected behaviour for
348322
// passing duplicate chunks to the Put method.
349323
func TestPutDuplicateChunks(t *testing.T) {

0 commit comments

Comments
 (0)