-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dynamodb] Use batch iterator for writing (#320)
- Loading branch information
1 parent
b6647c8
commit a9b4d59
Showing
8 changed files
with
157 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package lib | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_BatchIterator(t *testing.T) { | ||
{ | ||
// No batches | ||
iter := NewBatchIterator([][]string{}) | ||
assert.False(t, iter.HasNext()) | ||
_, err := iter.Next() | ||
assert.ErrorContains(t, err, "iterator has finished") | ||
} | ||
{ | ||
// One empty batch | ||
iter := NewBatchIterator([][]string{{}}) | ||
assert.True(t, iter.HasNext()) | ||
batch, err := iter.Next() | ||
assert.NoError(t, err) | ||
assert.Empty(t, batch) | ||
assert.False(t, iter.HasNext()) | ||
_, err = iter.Next() | ||
assert.ErrorContains(t, err, "iterator has finished") | ||
} | ||
{ | ||
// Two non-empty batches one empty batch | ||
iter := NewBatchIterator([][]string{{"a", "b"}, {}, {"c", "d"}}) | ||
assert.True(t, iter.HasNext()) | ||
{ | ||
batch, err := iter.Next() | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"a", "b"}, batch) | ||
} | ||
|
||
assert.True(t, iter.HasNext()) | ||
{ | ||
batch, err := iter.Next() | ||
assert.NoError(t, err) | ||
assert.Empty(t, batch) | ||
} | ||
|
||
assert.True(t, iter.HasNext()) | ||
{ | ||
batch, err := iter.Next() | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"c", "d"}, batch) | ||
} | ||
|
||
assert.False(t, iter.HasNext()) | ||
_, err := iter.Next() | ||
assert.ErrorContains(t, err, "iterator has finished") | ||
} | ||
} | ||
|
||
func Test_SingleBatchIterator(t *testing.T) { | ||
{ | ||
// Empty batch | ||
iter := NewSingleBatchIterator([]string{}) | ||
assert.True(t, iter.HasNext()) | ||
batch, err := iter.Next() | ||
assert.NoError(t, err) | ||
assert.Empty(t, batch) | ||
assert.False(t, iter.HasNext()) | ||
_, err = iter.Next() | ||
assert.ErrorContains(t, err, "iterator has finished") | ||
} | ||
{ | ||
// Non-empty batch | ||
iter := NewSingleBatchIterator([]string{"a", "b", "c", "d"}) | ||
assert.True(t, iter.HasNext()) | ||
batch, err := iter.Next() | ||
assert.NoError(t, err) | ||
assert.Equal(t, []string{"a", "b", "c", "d"}, batch) | ||
assert.False(t, iter.HasNext()) | ||
_, err = iter.Next() | ||
assert.ErrorContains(t, err, "iterator has finished") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.