MCPcopy
hub / github.com/chaozh/MIT-6.824 / TestStaticShards

Function TestStaticShards

src/shardkv/test_test.go:26–95  ·  view source on GitHub ↗

test static 2-way sharding, without shard movement.

(t *testing.T)

Source from the content-addressed store, hash-verified

24// test static 2-way sharding, without shard movement.
25//
26func TestStaticShards(t *testing.T) {
27 fmt.Printf("Test: static shards ...\n")
28
29 cfg := make_config(t, 3, false, -1)
30 defer cfg.cleanup()
31
32 ck := cfg.makeClient()
33
34 cfg.join(0)
35 cfg.join(1)
36
37 n := 10
38 ka := make([]string, n)
39 va := make([]string, n)
40 for i := 0; i < n; i++ {
41 ka[i] = strconv.Itoa(i) // ensure multiple shards
42 va[i] = randstring(20)
43 ck.Put(ka[i], va[i])
44 }
45 for i := 0; i < n; i++ {
46 check(t, ck, ka[i], va[i])
47 }
48
49 // make sure that the data really is sharded by
50 // shutting down one shard and checking that some
51 // Get()s don't succeed.
52 cfg.ShutdownGroup(1)
53 cfg.checklogs() // forbid snapshots
54
55 ch := make(chan string)
56 for xi := 0; xi < n; xi++ {
57 ck1 := cfg.makeClient() // only one call allowed per client
58 go func(i int) {
59 v := ck1.Get(ka[i])
60 if v != va[i] {
61 ch <- fmt.Sprintf("Get(%v): expected:\n%v\nreceived:\n%v", ka[i], va[i], v)
62 } else {
63 ch <- ""
64 }
65 }(xi)
66 }
67
68 // wait a bit, only about half the Gets should succeed.
69 ndone := 0
70 done := false
71 for done == false {
72 select {
73 case err := <-ch:
74 if err != "" {
75 t.Fatal(err)
76 }
77 ndone += 1
78 case <-time.After(time.Second * 2):
79 done = true
80 break
81 }
82 }
83

Callers

nothing calls this directly

Calls 11

joinMethod · 0.80
ShutdownGroupMethod · 0.80
checklogsMethod · 0.80
StartGroupMethod · 0.80
make_configFunction · 0.70
randstringFunction · 0.70
checkFunction · 0.70
cleanupMethod · 0.45
makeClientMethod · 0.45
PutMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected