-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.go
42 lines (36 loc) · 966 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"log"
"sync"
"time"
"github.com/viccon/sturdyc"
)
var ids = []string{"1111", "2222", "3333"}
// launchContainer will simulate having a container that runs
// its own in-memory cache, but shares a distributed storage.
func launchContainer(containerIndex int, storage sturdyc.DistributedStorageWithDeletions) {
apiClient := newAPIClient(storage)
for i := 0; i < 100; i++ {
_, err := apiClient.GetShippingOptions(context.Background(), containerIndex, ids, "asc")
if err != nil {
log.Fatal(err)
}
log.Println("Container", containerIndex, "finished fetching shipping options")
time.Sleep(100 * time.Millisecond)
}
}
func main() {
distributedStorage := newDistributedStorage()
numContainers := 5
wg := &sync.WaitGroup{}
wg.Add(numContainers)
for i := 0; i < numContainers; i++ {
go func() {
launchContainer(i+1, distributedStorage)
wg.Done()
}()
time.Sleep(50 * time.Millisecond)
}
wg.Wait()
}