-
Notifications
You must be signed in to change notification settings - Fork 47
/
parallel-test.go
140 lines (112 loc) · 3.1 KB
/
parallel-test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Test for Cloud Driver Info. Manager of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2020.03.
package main
import (
"fmt"
"sync"
"time"
"strconv"
"runtime"
"github.com/cloud-barista/cb-store/config"
rsid "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
iidm "github.com/cloud-barista/cb-spider/cloud-control-manager/iid-manager"
)
var count = 100
var iidRWLock = new(iidm.IIDRWLOCK)
var waitGroup sync.WaitGroup
var cName = "aws-seoul-config" // Connection Name
var rName = "VM" // Resource Type
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
fmt.Printf("\n\n\n================================== CPU : %v \n", runtime.GOMAXPROCS(0))
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
for i:=0;i<10;i++ {
list()
time.Sleep(1 * time.Second)
}
}()
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
for i:=0; i<count; i++ {
create(strconv.Itoa(i))
}
}()
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
for i:=0; i<count; i++ {
update(strconv.Itoa(i))
}
}()
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
for i:=0; i<count; i++ {
delete(strconv.Itoa(i))
}
}()
waitGroup.Wait()
fmt.Printf("\n\n\n================================== Press any key to clean!!!\n")
fmt.Scanln()
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
for i:=0; i<count; i++ {
delete(strconv.Itoa(i))
}
}()
waitGroup.Wait()
fmt.Printf("\n\n\n================================== Press any key to exit!!!\n")
fmt.Scanln()
}
func create(id string) {
nameID := "powerkim_vm_" + id // NameID
iId := rsid.IID{nameID, ""}
iidInfo, err := iidRWLock.CreateIID(cName, rName, iId)
if err != nil {
config.Cblogger.Error(err)
}
config.Cblogger.Infof(" === %#v\n", iidInfo)
}
func update(id string) {
nameID := "powerkim_vm_" + id // NameID
iId := rsid.IID{nameID, "i-0bc7123b7e5cbf79d"}
iidInfo, err := iidRWLock.UpdateIID(cName, rName, iId)
if err != nil {
config.Cblogger.Error(err)
}
config.Cblogger.Infof(" === %#v\n", iidInfo)
}
func list() {
keyValueList, err2 := iidRWLock.ListIID(cName, rName)
if err2 != nil {
config.Cblogger.Error(err2)
}
for _, keyValue := range keyValueList {
iidInfo, err := iidRWLock.GetIID(cName, rName, keyValue.IId)
if err != nil {
config.Cblogger.Error(err)
}else {
fmt.Printf("{%s, %s}\n", iidInfo.IId.NameId, iidInfo.IId.SystemId)
}
}
}
func delete(id string) {
nameID := "powerkim_vm_" + id // NameID
fmt.Printf(" === DeleteIID %s\n", nameID)
iId := rsid.IID{nameID, ""}
result, err3 := iidRWLock.DeleteIID(cName, rName, iId)
if err3 != nil {
config.Cblogger.Error(err3)
}
//config.Cblogger.Infof(" === DeleteIID %s : %#v\n", nameID, result)
fmt.Printf(" === DeleteIID %s : %#v\n", nameID, result)
}