summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-05-01 03:37:06 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-05-01 03:37:06 +0200
commit9c4da236b82e8ff9dd3f04178d4f29e223c9b961 (patch)
tree4e55bb8b29961d98d4bc872a6d3d6e106ed4c34f
parentsome more tests (diff)
some more tests...
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store_test.go98
1 files changed, 87 insertions, 11 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go
index 1d369de..96f1847 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go
@@ -252,6 +252,8 @@ func TestAppendAndFetch(t *testing.T) {
//
// TODO: more example data and cleanup this copy&paste hell...
+ // TODO: add tests for
+ // * store.GetSource(s)
//
}
@@ -296,13 +298,8 @@ func TestReadOnly(t *testing.T) {
}
func TestGetUpdatesAfter(t *testing.T) {
- // create read-only db from not-existing file must fail
- os.Remove(testBoltPath)
- if _, err := NewStore(testBoltPath, true); err == nil {
- t.Fatalf("creating a read-only database should throw an error")
- }
-
// prepare a store with 3 data-updates
+ os.Remove(testBoltPath)
store, err := NewStore(testBoltPath, false)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -326,6 +323,15 @@ func TestGetUpdatesAfter(t *testing.T) {
upd.StartTime = upd.StartTime.Add(time.Duration(upd.Duration) * time.Millisecond)
}
+ // check if there are 3 updates in store
+ lastId, err := store.GetLastUpdateId()
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if lastId != 3 {
+ t.Fatalf("failed to get last update ID: got %d updates, expected 3", lastId)
+ }
+
// all the updates
updList, err := store.GetUpdatesAfter(-1, -1)
if err != nil {
@@ -377,12 +383,82 @@ func TestGetUpdatesAfter(t *testing.T) {
}
}
+func TestForwardedDataUpdates(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()
+
+ forwardedHub := "05defdfa-e7d1-4ca8-8b5c-02abb0088d29"
+
+ // check if there are no updates in store
+ lastId, err := store.GetLastUpdateForUuid(forwardedHub)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if lastId != 0 {
+ t.Fatalf("failed to get last update ID: got %d updates, expected 0", lastId)
+ }
+
+ // get list of all hubs
+ hubs, err := store.GetHubs()
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if len(hubs) != 1 {
+ t.Fatalf("failed to get hub UUIDs: got %d hubs, expected 1", len(hubs))
+ }
+ if hubs[0] != store.hubUuid {
+ t.Fatalf("fist hub should be the own stores UUID but is: %s", hubs[0])
+ }
+
+ // append 3 forwarded data-updates
+ upd := updateData
+ upd.StartTime = time.Date(2014, time.August, 24, 14, 35, 33, 847000000, time.UTC)
+ upd.Data.Clients = clientsData
+
+ expected := []DataUpdateFull{}
+ for i := 0; i < 3; i = i + 1 {
+ in := DataUpdateFull{0, "", -1, sourceData, upd}
+ in.SourceHubUuid = forwardedHub
+ in.SourceHubDataUpdateId = i + 1
+ if err = store.Append(in); err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ expected = append(expected, in)
+ upd.StartTime = upd.StartTime.Add(time.Duration(upd.Duration) * time.Millisecond)
+ }
+
+ // check if there are 3 updates in store
+ lastId, err = store.GetLastUpdateForUuid(forwardedHub)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if lastId != 3 {
+ t.Fatalf("failed to get last update ID: got %d updates, expected 3", lastId)
+ }
+
+ // get list of all hubs
+ hubs, err = store.GetHubs()
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if len(hubs) != 2 {
+ t.Fatalf("failed to get hub UUIDs: got %d hubs, expected 2", len(hubs))
+ }
+ if hubs[0] != store.hubUuid {
+ t.Fatalf("fist hub should be the own stores UUID but is: %s", hubs[0])
+ }
+ if hubs[1] != forwardedHub {
+ t.Fatalf("second hub UUID is wrong: %s, expected: %s", hubs[1], forwardedHub)
+ }
+}
+
//
-// TODO: add tests for
-// * store.GetHubs
-// * store.GetSource(s)
-// * GetLastUpdateId
-// * GetLastUpdateForUuid
+// Benchmarking
//
func generateDataUpdateFull(n int) (data []DataUpdateFull) {