[ARVADOS] updated: 29482d2345265284af2291c47a9b10c599aab743
git at public.curoverse.com
git at public.curoverse.com
Sun Dec 27 15:52:49 EST 2015
Summary of changes:
sdk/go/blockdigest/blockdigest.go | 2 +-
sdk/go/manifest/manifest.go | 34 ++++++++++++++++++++--------------
sdk/go/manifest/manifest_test.go | 17 ++++++++++++++---
3 files changed, 35 insertions(+), 18 deletions(-)
via 29482d2345265284af2291c47a9b10c599aab743 (commit)
from 13375ee4058444cdb3389ee089df933c297ef672 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 29482d2345265284af2291c47a9b10c599aab743
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Sun Dec 27 15:52:45 2015 -0500
7816: Improve ManifestStream to hold parsed file token structs instead of strings.
diff --git a/sdk/go/blockdigest/blockdigest.go b/sdk/go/blockdigest/blockdigest.go
index a5a668f..cfc510c 100644
--- a/sdk/go/blockdigest/blockdigest.go
+++ b/sdk/go/blockdigest/blockdigest.go
@@ -9,7 +9,7 @@ import (
)
var LocatorPattern = regexp.MustCompile(
- "^[0-9a-fA-F]{32}\\+[0-9]+(\\+[A-Z][A-Za-z0-9 at _-]+)*$")
+ "^[0-9a-fA-F]{32}\\+[0-9]+(\\+[A-Z][A-Za-z0-9 at _-]*)*$")
// Stores a Block Locator Digest compactly, up to 128 bits.
// Can be used as a map key.
diff --git a/sdk/go/manifest/manifest.go b/sdk/go/manifest/manifest.go
index d4b9830..b7922a8 100644
--- a/sdk/go/manifest/manifest.go
+++ b/sdk/go/manifest/manifest.go
@@ -44,11 +44,17 @@ type FileSegment struct {
Len int
}
+type FileToken struct {
+ SegPos uint64
+ SegLen uint64
+ Name string
+}
+
// Represents a single line from a manifest.
type ManifestStream struct {
StreamName string
Blocks []string
- FileTokens []string
+ FileTokens []FileToken
Err error
}
@@ -97,21 +103,21 @@ func ParseBlockLocator(s string) (b BlockLocator, err error) {
return
}
-func parseFileToken(tok string) (segPos, segLen uint64, name string, err error) {
+func parseFileToken(tok string) (ft FileToken, err error) {
parts := strings.SplitN(tok, ":", 3)
if len(parts) != 3 {
err = ErrInvalidToken
return
}
- segPos, err = strconv.ParseUint(parts[0], 10, 64)
+ ft.SegPos, err = strconv.ParseUint(parts[0], 10, 64)
if err != nil {
return
}
- segLen, err = strconv.ParseUint(parts[1], 10, 64)
+ ft.SegLen, err = strconv.ParseUint(parts[1], 10, 64)
if err != nil {
return
}
- name = UnescapeName(parts[2])
+ ft.Name = UnescapeName(parts[2])
return
}
@@ -129,11 +135,10 @@ func (s *ManifestStream) sendFileSegmentIterByName(filepath string, ch chan<- *F
// This is what streamName+"/"+fileName will look like:
target := "./" + filepath
for _, fTok := range s.FileTokens {
- wantPos, wantLen, name, err := parseFileToken(fTok)
- if err != nil {
- // Skip (!) invalid file tokens.
- continue
- }
+ wantPos := fTok.SegPos
+ wantLen := fTok.SegLen
+ name := fTok.Name
+
if s.StreamName+"/"+name != target {
continue
}
@@ -199,24 +204,25 @@ func parseManifestStream(s string) (m ManifestStream) {
}
}
m.Blocks = tokens[:i]
- m.FileTokens = tokens[i:]
+ fileTokens := tokens[i:]
if len(m.Blocks) == 0 {
m.Err = fmt.Errorf("No block locators found")
return
}
- if len(m.FileTokens) == 0 {
+ if len(fileTokens) == 0 {
m.Err = fmt.Errorf("No file tokens found")
return
}
- for _, ft := range m.FileTokens {
- _, _, _, err := parseFileToken(ft)
+ for _, ft := range fileTokens {
+ pft, err := parseFileToken(ft)
if err != nil {
m.Err = fmt.Errorf("Invalid file token: %s", ft)
break
}
+ m.FileTokens = append(m.FileTokens, pft)
}
return
diff --git a/sdk/go/manifest/manifest_test.go b/sdk/go/manifest/manifest_test.go
index 43c3bd3..c37b74b 100644
--- a/sdk/go/manifest/manifest_test.go
+++ b/sdk/go/manifest/manifest_test.go
@@ -61,10 +61,21 @@ func expectStringSlicesEqual(t *testing.T, actual []string, expected []string) {
}
}
+func expectFileTokensEqual(t *testing.T, actual []FileToken, expected []FileToken) {
+ if len(actual) != len(expected) {
+ t.Fatalf("Expected %v (length %d), but received %v (length %d) instead. %s", expected, len(expected), actual, len(actual), getStackTrace())
+ }
+ for i := range actual {
+ if actual[i] != expected[i] {
+ t.Fatalf("Expected %v but received %v instead (first disagreement at position %d). %s", expected, actual, i, getStackTrace())
+ }
+ }
+}
+
func expectManifestStream(t *testing.T, actual ManifestStream, expected ManifestStream) {
expectEqual(t, actual.StreamName, expected.StreamName)
expectStringSlicesEqual(t, actual.Blocks, expected.Blocks)
- expectStringSlicesEqual(t, actual.FileTokens, expected.FileTokens)
+ expectFileTokensEqual(t, actual.FileTokens, expected.FileTokens)
}
func expectBlockLocator(t *testing.T, actual blockdigest.BlockLocator, expected blockdigest.BlockLocator) {
@@ -77,7 +88,7 @@ func TestParseManifestStreamSimple(t *testing.T) {
m := parseManifestStream(". 365f83f5f808896ec834c8b595288735+2310+K at qr1hi+Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf 0:2310:qr1hi-8i9sb-ienvmpve1a0vpoi.log.txt")
expectManifestStream(t, m, ManifestStream{StreamName: ".",
Blocks: []string{"365f83f5f808896ec834c8b595288735+2310+K at qr1hi+Af0c9a66381f3b028677411926f0be1c6282fe67c@542b5ddf"},
- FileTokens: []string{"0:2310:qr1hi-8i9sb-ienvmpve1a0vpoi.log.txt"}})
+ FileTokens: []FileToken{{0, 2310, "qr1hi-8i9sb-ienvmpve1a0vpoi.log.txt"}}})
}
func TestParseBlockLocatorSimple(t *testing.T) {
@@ -109,7 +120,7 @@ func TestStreamIterShortManifestWithBlankStreams(t *testing.T) {
firstStream,
ManifestStream{StreamName: ".",
Blocks: []string{"b746e3d2104645f2f64cd3cc69dd895d+15693477+E2866e643690156651c03d876e638e674dcd79475 at 5441920c"},
- FileTokens: []string{"0:15893477:chr10_band0_s0_e3000000.fj"}})
+ FileTokens: []FileToken{{0, 15893477, "chr10_band0_s0_e3000000.fj"}}})
received, ok := <-streamIter
if ok {
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list