diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-05-01 17:36:31 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-05-01 17:36:31 +0200 |
commit | 742c8f7b09336040d278b7e17ab100f4e1b4de4c (patch) | |
tree | fe22773800b24aa2a38aa6ae8cb2eee0300045c4 | |
parent | some more open tests (diff) |
added test cases for sources
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 4 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store_test.go | 72 |
2 files changed, 58 insertions, 18 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 2266895..9ef1355 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -208,9 +208,9 @@ func (st Store) insertNewHub(tx *bolt.Tx, hubUuid string) (hubId int, err error) func (st Store) insertNewSource(tx *bolt.Tx, src sourceDb) (srcId int, err error) { bf := tx.Bucket([]byte(sourcesFwdBn)) - bf.FillPercent = 1.0 // we only do appends + // br.FillPercent = 1.0 // these appends are not ordered (the key is the slug and not an integer id) br := tx.Bucket([]byte(sourcesRevBn)) - br.FillPercent = 1.0 // we only do appends + br.FillPercent = 1.0 // we only do appends (with ever incrementing interger ids) slug := src.Slug() bSrcId := bf.Get([]byte(slug)) diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go index 180019c..eb3d8a7 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go @@ -58,31 +58,32 @@ var ( ClientData{"172.16.0.2", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/57.0.2987.98 Chrome/57.0.2987.98 Safari/537.36", 6400}} ) -func generateDataUpdateFull(n int) (data []DataUpdateFull) { +func generateTestData(n int) (data []DataUpdateFull, numSrcs int) { hostnames := []string{"streamer1", "streamer2"} contents := []string{"av", "audio"} formats := []string{"webm", "flash", "hls"} qualities := []string{"high", "medium", "low"} - - numcombis := len(hostnames) * len(contents) * len(formats) * len(qualities) - - starttime := time.Now() - duration := int64(15000) tags := []string{"2017", "elevate", "discourse"} + duration := int64(15000) - for i := 0; i < n; i += numcombis { + starttime := time.Now() + numSrcs = len(hostnames) * len(contents) * len(formats) * len(qualities) + if n < 0 { + n = numSrcs + } + for i := 0; i < n; i += numSrcs { for _, hostname := range hostnames { for _, content := range contents { for _, format := range formats { for _, quality := range qualities { d := DataUpdateFull{} - d.Version = 1 + d.Version = ProtocolVersion d.SourceId.Hostname = hostname - d.SourceId.Tags = tags d.SourceId.StreamId.ContentId = content d.SourceId.StreamId.Format = format d.SourceId.StreamId.Quality = quality + d.SourceId.Tags = tags d.DataUpdate.StartTime = starttime d.DataUpdate.Duration = duration @@ -295,7 +296,7 @@ func TestAppendAndFetch(t *testing.T) { defer store.Close() if _, err := store.GetUpdate(17); err != ErrNotFound { - t.Fatalf("fetching not exisiting update should return non-found, error=%v", err) + t.Fatalf("fetching not exisiting update should return not-found, error=%v", err) } upd := updateData @@ -546,6 +547,45 @@ func TestForwardedDataUpdates(t *testing.T) { } } +func TestGetSources(t *testing.T) { + // prepare a new store + os.Remove(testBoltPath) + store, err := NewStore(testBoltPath, false) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + defer store.Close() + + if _, err := store.GetSource(17); err != ErrNotFound { + t.Fatalf("fetching not exisiting source should return not-found, error=%v", err) + } + + // generate/append some data + data, numSrcs := generateTestData(-1) + if err := store.AppendMany(data); err != nil { + t.Fatalf("unexpected error: %v", err) + } + + // fetch first source + src, err := store.GetSource(1) + if err != nil { + t.Fatalf("fetching source failed: %v", err) + } + if !reflect.DeepEqual(data[0].SourceId, src) { + t.Fatalf("failed to fetch source\nactual: %v\nexpected: %v\n", src, data[0].SourceId) + } + + // fetch all the sources + srcList, err := store.GetSources() + if err != nil { + t.Fatalf("fetching sources failed: %v", err) + } + if len(srcList) != numSrcs { + t.Fatalf("wrong number of sources: %d, expected %d", len(srcList), numSrcs) + } + // the result will be orderd using the slug so doing a DeepEqual doesn't work here +} + // // Benchmarking // @@ -554,15 +594,15 @@ func BenchmarkAppendMany(b *testing.B) { os.Remove(testBoltPath) store, err := NewStore(testBoltPath, false) if err != nil { - b.Fatalf("failed to initialize: %v", err) + b.Fatalf("unexpected error: %v", err) } defer store.Close() - data := generateDataUpdateFull(b.N) + data, _ := generateTestData(b.N) b.ResetTimer() if err := store.AppendMany(data); err != nil { - b.Fatalf("failed to append: %v", err) + b.Fatalf("unexpected error: %v", err) } } @@ -570,12 +610,12 @@ func BenchmarkGetUpdatesAfter(b *testing.B) { os.Remove(testBoltPath) store, err := NewStore(testBoltPath, false) if err != nil { - b.Fatalf("failed to initialize: %v", err) + b.Fatalf("unexpected error: %v", err) } defer store.Close() - data := generateDataUpdateFull(b.N) + data, _ := generateTestData(b.N) if err := store.AppendMany(data); err != nil { - b.Fatalf("failed to append: %v", err) + b.Fatalf("unexpected error: %v", err) } b.ResetTimer() |