From ca33b7bb759b97839280e655470fba26f25649a2 Mon Sep 17 00:00:00 2001 From: Assaf Ben-Amitai Date: Wed, 2 Feb 2022 11:02:31 +0200 Subject: [PATCH] add stream attrs to GetContainerContents output (#124) --- pkg/dataplane/test/sync_test.go | 49 +++++++++++++++++++++++++++++++++ pkg/dataplane/types.go | 19 +++++++------ 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/pkg/dataplane/test/sync_test.go b/pkg/dataplane/test/sync_test.go index cf0bafc..d677125 100644 --- a/pkg/dataplane/test/sync_test.go +++ b/pkg/dataplane/test/sync_test.go @@ -212,6 +212,55 @@ func (suite *syncContainerTestSuite) TestGetContainerContentsDirsWithAllAttrs() } } +func (suite *syncContainerTestSuite) TestGetContainerContentsStreamDirsWithAllAttrs() { + path := fmt.Sprintf("tmp/test/sync_test/TestGetContainerContentsStreamDirsWithAllAttrs/%d/", time.Now().Unix()) + + const ( + shard_count = 12 + retention_period_hours = 2 + ) + + // Create some stream content (stream directory and shards) + createStreamInput := &v3io.CreateStreamInput{} + for i := 1; i <= 10; i++ { + createStreamInput.Path = fmt.Sprintf("%sstream-%d/", path, i) + createStreamInput.ShardCount = shard_count + createStreamInput.RetentionPeriodHours = retention_period_hours + + // when run against a context + suite.populateDataPlaneInput(&createStreamInput.DataPlaneInput) + err := suite.container.CreateStreamSync(createStreamInput) + suite.Require().NoError(err, "Failed to create test content") + } + + getContainerContentsInput := v3io.GetContainerContentsInput{ + Path: path, + GetAllAttributes: true, + DirectoriesOnly: true, + Limit: 10, + } + + // when run against a context + suite.populateDataPlaneInput(&getContainerContentsInput.DataPlaneInput) + + // get container contents + response, err := suite.container.GetContainerContentsSync(&getContainerContentsInput) + suite.Require().NoError(err, "Failed to get container contents") + response.Release() + + getContainerContentsOutput := response.Output.(*v3io.GetContainerContentsOutput) + suite.Require().Empty(len(getContainerContentsOutput.Contents)) + suite.Require().Equal(10, len(getContainerContentsOutput.CommonPrefixes)) + suite.Require().Equal(path+"stream-9", getContainerContentsOutput.NextMarker) + suite.Require().Equal(false, getContainerContentsOutput.IsTruncated) + + for _, prefix := range getContainerContentsOutput.CommonPrefixes { + validateCommonPrefix(suite, &prefix, true) + suite.Require().Equal(shard_count, prefix.ShardCount) + suite.Require().Equal(retention_period_hours, prefix.RetentionPeriodHours) + } +} + // TODO: fix. Broken with: // Messages: Failed to update test directory // due to: diff --git a/pkg/dataplane/types.go b/pkg/dataplane/types.go index f735db5..0d14d69 100755 --- a/pkg/dataplane/types.go +++ b/pkg/dataplane/types.go @@ -94,14 +94,17 @@ type Content struct { } type CommonPrefix struct { - Prefix string `xml:"Prefix"` // directory name - LastModified string `xml:"LastModified"` // Date in format time.RFC3339: "2019-06-02T14:30:39.18Z" - AccessTime string `xml:"AccessTime"` // Date in format time.RFC3339: "2019-06-02T14:30:39.18Z" - CreatingTime string `xml:"CreatingTime"` // Date in format time.RFC3339: "2019-06-02T14:30:39.18Z" - Mode FileMode `xml:"Mode"` // octal number, e.g. 040775 - GID string `xml:"GID"` // Hexadecimal representation of GID (e.g. "3e8" -> i.e. "0x3e8" == 1000) - UID string `xml:"UID"` // Hexadecimal representation of UID (e.g. "3e8" -> i.e. "0x3e8" == 1000) - InodeNumber *uint64 `xml:"InodeNumber"` // iNode number + Prefix string `xml:"Prefix"` // directory name + LastModified string `xml:"LastModified"` // Date in format time.RFC3339: "2019-06-02T14:30:39.18Z" + AccessTime string `xml:"AccessTime"` // Date in format time.RFC3339: "2019-06-02T14:30:39.18Z" + CreatingTime string `xml:"CreatingTime"` // Date in format time.RFC3339: "2019-06-02T14:30:39.18Z" + Mode FileMode `xml:"Mode"` // octal number, e.g. 040775 + GID string `xml:"GID"` // Hexadecimal representation of GID (e.g. "3e8" -> i.e. "0x3e8" == 1000) + UID string `xml:"UID"` // Hexadecimal representation of UID (e.g. "3e8" -> i.e. "0x3e8" == 1000) + InodeNumber *uint64 `xml:"InodeNumber"` // iNode number + ShardCount int `xml:"ShardCount"` // For stream-dirs only - the number of shards in the stream + RetentionPeriodHours int `xml:"RetentionPeriodHours"` // For stream-dirs only - the shard retention (in hours) + RetentionPeriodSeconds int `xml:"RetentionPeriodSec"` // For stream-dirs only - the shard retention (in seconds) } type FileMode string