accounting: add HasBuffer method to Account
This commit is contained in:
parent
15402e46c9
commit
05ddef117a
2 changed files with 11 additions and 0 deletions
|
@ -109,6 +109,14 @@ func (acc *Account) WithBuffer() *Account {
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasBuffer - returns true if this Account has an AsyncReader with a buffer
|
||||||
|
func (acc *Account) HasBuffer() bool {
|
||||||
|
acc.mu.Lock()
|
||||||
|
defer acc.mu.Unlock()
|
||||||
|
_, ok := acc.in.(*asyncreader.AsyncReader)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// GetReader returns the underlying io.ReadCloser under any Buffer
|
// GetReader returns the underlying io.ReadCloser under any Buffer
|
||||||
func (acc *Account) GetReader() io.ReadCloser {
|
func (acc *Account) GetReader() io.ReadCloser {
|
||||||
acc.mu.Lock()
|
acc.mu.Lock()
|
||||||
|
|
|
@ -37,6 +37,7 @@ func TestNewAccountSizeName(t *testing.T) {
|
||||||
assert.Equal(t, acc, stats.inProgress.get("test"))
|
assert.Equal(t, acc, stats.inProgress.get("test"))
|
||||||
acc.Done()
|
acc.Done()
|
||||||
assert.Nil(t, stats.inProgress.get("test"))
|
assert.Nil(t, stats.inProgress.get("test"))
|
||||||
|
assert.False(t, acc.HasBuffer())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccountWithBuffer(t *testing.T) {
|
func TestAccountWithBuffer(t *testing.T) {
|
||||||
|
@ -44,7 +45,9 @@ func TestAccountWithBuffer(t *testing.T) {
|
||||||
|
|
||||||
stats := NewStats()
|
stats := NewStats()
|
||||||
acc := newAccountSizeName(stats, in, -1, "test")
|
acc := newAccountSizeName(stats, in, -1, "test")
|
||||||
|
assert.False(t, acc.HasBuffer())
|
||||||
acc.WithBuffer()
|
acc.WithBuffer()
|
||||||
|
assert.True(t, acc.HasBuffer())
|
||||||
// should have a buffer for an unknown size
|
// should have a buffer for an unknown size
|
||||||
_, ok := acc.in.(*asyncreader.AsyncReader)
|
_, ok := acc.in.(*asyncreader.AsyncReader)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
Loading…
Reference in a new issue