Skip to content

Commit

Permalink
Made suggested changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley committed Aug 5, 2024
1 parent 494ab5c commit 1054348
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
57 changes: 16 additions & 41 deletions tools/traffic/table/blob_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import "errors"

// BlobMetadata encapsulates various information about a blob written by the traffic generator.
type BlobMetadata struct {
// key of the blob, set when the blob is initially uploaded.
key []byte
// Key of the blob, set when the blob is initially uploaded.
Key []byte

// checksum of the blob.
checksum *[16]byte
// BlobIndex of the blob.
BlobIndex uint

// size of the blob, in bytes.
size uint
// Checksum of the blob.
Checksum [16]byte

// blobIndex of the blob.
blobIndex uint
// Size of the blob, in bytes.
Size uint

// remainingReadPermits describes the maximum number of remaining reads permitted against this blob.
// RemainingReadPermits describes the maximum number of remaining reads permitted against this blob.
// If -1 then an unlimited number of reads are permitted.
remainingReadPermits int
RemainingReadPermits int
}

// NewBlobMetadata creates a new BlobMetadata instance. The readPermits parameter describes the maximum number of
// remaining reads permitted against this blob. If -1 then an unlimited number of reads are permitted.
func NewBlobMetadata(
key []byte,
checksum *[16]byte,
checksum [16]byte,
size uint,
blobIndex uint,
readPermits int) (*BlobMetadata, error) {
Expand All @@ -35,35 +35,10 @@ func NewBlobMetadata(
}

return &BlobMetadata{
key: key,
checksum: checksum,
size: size,
blobIndex: blobIndex,
remainingReadPermits: readPermits,
Key: key,
Checksum: checksum,
Size: size,
BlobIndex: blobIndex,
RemainingReadPermits: readPermits,
}, nil
}

// Key returns the key of the blob.
func (blob *BlobMetadata) Key() []byte {
return blob.key
}

// Checksum returns the checksum of the blob.
func (blob *BlobMetadata) Checksum() *[16]byte {
return blob.checksum
}

// Size returns the size of the blob, in bytes.
func (blob *BlobMetadata) Size() uint {
return blob.size
}

// BlobIndex returns the blobIndex of the blob.
func (blob *BlobMetadata) BlobIndex() uint {
return blob.blobIndex
}

// RemainingReadPermits returns the maximum number of remaining reads permitted against this blob.
func (blob *BlobMetadata) RemainingReadPermits() int {
return blob.remainingReadPermits
}
6 changes: 3 additions & 3 deletions tools/traffic/table/blob_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (store *BlobStore) GetNext() *BlobMetadata {
for key, blob := range store.blobs {
// Always return the first blob found.

if blob.remainingReadPermits > 0 {
blob.remainingReadPermits--
if blob.remainingReadPermits == 0 {
if blob.RemainingReadPermits > 0 {
blob.RemainingReadPermits--
if blob.RemainingReadPermits == 0 {
delete(store.blobs, key)
}
}
Expand Down
12 changes: 6 additions & 6 deletions tools/traffic/table/blob_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func randomMetadata(t *testing.T, permits int) *BlobMetadata {
checksum := [16]byte{}
_, _ = rand.Read(key)
_, _ = rand.Read(checksum[:])
metadata, err := NewBlobMetadata(key, &checksum, 1024, 0, permits)
metadata, err := NewBlobMetadata(key, checksum, 1024, 0, permits)
assert.Nil(t, err)

return metadata
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestGetRandomNoRemoval(t *testing.T) {
for i := 0; i < size; i++ {
metadata := randomMetadata(t, -1) // -1 == unlimited permits
table.Add(metadata)
expectedMetadata[string(metadata.key)] = metadata
expectedMetadata[string(metadata.Key)] = metadata
assert.Equal(t, uint(i+1), table.Size())
}

Expand All @@ -66,8 +66,8 @@ func TestGetRandomNoRemoval(t *testing.T) {
for i := 0; i < size*8; i++ {
metadata := table.GetNext()
assert.NotNil(t, metadata)
assert.Equal(t, expectedMetadata[string(metadata.key)], metadata)
randomIndices[string(metadata.key)] = true
assert.Equal(t, expectedMetadata[string(metadata.Key)], metadata)
randomIndices[string(metadata.Key)] = true
}

// Sanity check: ensure that at least 10 different blobs were returned. This check is attempting to verify
Expand All @@ -94,7 +94,7 @@ func TestGetRandomWithRemoval(t *testing.T) {
for i := 0; i < size; i++ {
metadata := randomMetadata(t, permitCount)
table.Add(metadata)
expectedMetadata[string(metadata.Key())] = 0
expectedMetadata[string(metadata.Key)] = 0
assert.Equal(t, uint(i+1), table.Size())
}

Expand All @@ -104,7 +104,7 @@ func TestGetRandomWithRemoval(t *testing.T) {
metadata := table.GetNext()
assert.NotNil(t, metadata)

k := string(metadata.Key())
k := string(metadata.Key)
permitsUsed := expectedMetadata[k] + 1
expectedMetadata[k] = permitsUsed
assert.LessOrEqual(t, permitsUsed, uint(permitCount))
Expand Down

0 comments on commit 1054348

Please sign in to comment.