Skip to content

Commit 830a9b9

Browse files
committed
Update.
1 parent 358f5b6 commit 830a9b9

File tree

7 files changed

+60
-55
lines changed

7 files changed

+60
-55
lines changed

node/common/guid/guid_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
)
99

1010
func TestInitializeGUID(t *testing.T) {
11-
Init(256, 0, 0)
11+
Init(256, 1, 1)
1212

1313
assert.Equal(t, 256, SizeBits(), "GUID size were not correctly set!")
1414
assert.Equal(t, 256/8, SizeBytes(), "GUID size were not correctly set!")
1515
}
1616

1717
func TestInitializeGUID_Reinitialize(t *testing.T) {
18-
Init(256, 0, 0)
19-
Init(160, 0, 0)
18+
Init(256, 1, 1)
19+
Init(160, 1, 1)
2020

2121
assert.Equal(t, 256, SizeBits(), "GUID size were reinitialized after the first time!")
2222
}

node/common/guid/range.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ func NewGUIDRange(lowerGUID GUID, higherGUID GUID) *Range {
1818
}
1919
}
2020

21-
// GenerateRandom generate random GUID inside the range.
22-
func (r *Range) GenerateRandom() (*GUID, error) {
21+
// GenerateRandomSuperPeer generate random GUID inside the range.
22+
func (r *Range) GenerateRandomSuperPeer() (*GUID, error) {
2323
return r.lowerGUID.GenerateInnerRandomGUIDScaled(*r.higherGUID)
2424
}
2525

26+
func (r *Range) GenerateRandom() (*GUID, error) {
27+
return r.lowerGUID.GenerateInnerRandomGUID(*r.higherGUID)
28+
}
29+
2630
// CreatePartitions returns partitions, set of ranges, of the receiver range.
2731
func (r *Range) CreatePartitions(partitionsPercentage []int) []*Range {
2832
res := make([]*Range, 0)

node/common/guid/range_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestRange_GenerateRandomInside(t *testing.T) {
3030
}
3131
// Hack: Generate several randoms to check in order to improve our statistical success :)
3232
for i := 0; i < 100; i++ {
33-
randGUID, _ := guidRange.GenerateRandom()
33+
randGUID, _ := guidRange.GenerateRandomSuperPeer()
3434

3535
_, exist := acceptableOutputs[randGUID.Int64()]
3636
assert.True(t, exist, "Random GUID is not in acceptable range")

node/common/resources/mapping.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func (m *Mapping) RandGUIDFittestSearch(targetResources Resources) (*guid.GUID,
113113
if err != nil {
114114
return nil, err
115115
}
116-
return m.resourcesRangeMap[float64(fittestRes.CPUClass())][float64(fittestRes.CPUs())][float64(fittestRes.Memory())].GenerateRandom()
116+
return m.resourcesRangeMap[float64(fittestRes.CPUClass())][float64(fittestRes.CPUs())][float64(fittestRes.Memory())].GenerateRandomSuperPeer()
117117
}
118118

119119
func (m *Mapping) RandGUIDHighestSearch(targetResources Resources) (*guid.GUID, error) {
120120
fittestRes, err := m.getHighestResourcesSearch(targetResources)
121121
if err != nil {
122122
return nil, err
123123
}
124-
return m.resourcesRangeMap[float64(fittestRes.CPUClass())][float64(fittestRes.CPUs())][float64(fittestRes.Memory())].GenerateRandom()
124+
return m.resourcesRangeMap[float64(fittestRes.CPUClass())][float64(fittestRes.CPUs())][float64(fittestRes.Memory())].GenerateRandomSuperPeer()
125125
}
126126

127127
// RandGUIDOffer returns a random GUID in the range of the respective "fittest" target resource combination.
@@ -130,7 +130,7 @@ func (m *Mapping) RandGUIDOffer(targetResources Resources) (*guid.GUID, error) {
130130
if err != nil {
131131
return nil, err
132132
}
133-
return m.resourcesRangeMap[float64(fittestRes.CPUClass())][float64(fittestRes.CPUs())][float64(fittestRes.Memory())].GenerateRandom()
133+
return m.resourcesRangeMap[float64(fittestRes.CPUClass())][float64(fittestRes.CPUs())][float64(fittestRes.Memory())].GenerateRandomSuperPeer()
134134
}
135135

136136
// FirstGUIDOffer returns the first GUID that represents the given resources.
@@ -186,7 +186,7 @@ func (m *Mapping) HigherRandGUIDSearch(currentGUID guid.GUID, targetResources Re
186186
firstHit = false
187187
continue
188188
}
189-
return m.resourcesGUIDMap[cpuClassIndex][coresIndex][memoryIndex].GenerateRandom()
189+
return m.resourcesGUIDMap[cpuClassIndex][coresIndex][memoryIndex].GenerateRandomSuperPeer()
190190
}
191191
}
192192
currentMemoryIndex = 0
@@ -214,7 +214,7 @@ func (m *Mapping) LowerRandGUIDSearch(currentGUID guid.GUID, targetResources Res
214214
firstHit = false
215215
continue
216216
}
217-
return m.resourcesGUIDMap[cpuClassIndex][coresIndex][memoryIndex].GenerateRandom()
217+
return m.resourcesGUIDMap[cpuClassIndex][coresIndex][memoryIndex].GenerateRandomSuperPeer()
218218
}
219219
}
220220
if coresIndex == 0 && (cpuClassIndex-1) >= 0 {
@@ -252,7 +252,7 @@ func (m *Mapping) LowerRandGUIDOffer(currentGUID guid.GUID, targetResources Reso
252252
firstHit = false
253253
continue
254254
}
255-
return m.resourcesGUIDMap[cpuClassIndex][coresIndex][memoryIndex].GenerateRandom()
255+
return m.resourcesGUIDMap[cpuClassIndex][coresIndex][memoryIndex].GenerateRandomSuperPeer()
256256
}
257257
}
258258
if coresIndex == 0 && (cpuClassIndex-1) >= 0 {

node/common/resources/mapping_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestNewMapping(t *testing.T) {
10-
guid.Init(16) // Use 16-bit GUID to be easily tested
10+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
1111
resMap := NewResourcesMap(testPartitions)
1212

1313
for i := range resMap.resourcesGUIDMap {
@@ -22,7 +22,7 @@ func TestNewMapping(t *testing.T) {
2222
}
2323

2424
func TestRandGUIDSearch_1(t *testing.T) {
25-
guid.Init(16) // Use 16-bit GUID to be easily tested
25+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
2626
resMap := NewResourcesMap(testPartitions)
2727

2828
for i := 0; i < 100000; i++ {
@@ -36,7 +36,7 @@ func TestRandGUIDSearch_1(t *testing.T) {
3636
}
3737

3838
func TestRandGUIDSearch_2(t *testing.T) {
39-
guid.Init(16) // Use 16-bit GUID to be easily tested
39+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
4040
resMap := NewResourcesMap(testPartitions)
4141

4242
for i := 0; i < 100000; i++ {
@@ -50,7 +50,7 @@ func TestRandGUIDSearch_2(t *testing.T) {
5050
}
5151

5252
func TestRandGUIDSearch_3(t *testing.T) {
53-
guid.Init(16) // Use 16-bit GUID to be easily tested
53+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
5454
resMap := NewResourcesMap(testPartitions)
5555

5656
for i := 0; i < 100000; i++ {
@@ -64,7 +64,7 @@ func TestRandGUIDSearch_3(t *testing.T) {
6464
}
6565

6666
func TestRandGUIDSearch_4(t *testing.T) {
67-
guid.Init(16) // Use 16-bit GUID to be easily tested
67+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
6868
resMap := NewResourcesMap(testPartitions)
6969

7070
for i := 0; i < 100000; i++ {
@@ -78,7 +78,7 @@ func TestRandGUIDSearch_4(t *testing.T) {
7878
}
7979

8080
func TestRandGUIDSearch_5(t *testing.T) {
81-
guid.Init(16) // Use 16-bit GUID to be easily tested
81+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
8282
resMap := NewResourcesMap(testPartitions)
8383

8484
randGUID, err := resMap.RandGUIDFittestSearch(*NewResourcesCPUClass(0, 1, 1512))
@@ -90,7 +90,7 @@ func TestRandGUIDSearch_5(t *testing.T) {
9090
}
9191

9292
func TestRandGUIDSearch_6(t *testing.T) {
93-
guid.Init(16) // Use 16-bit GUID to be easily tested
93+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
9494
resMap := NewResourcesMap(testPartitions)
9595

9696
randGUID, err := resMap.RandGUIDFittestSearch(*NewResourcesCPUClass(1, 2, 1512))
@@ -102,7 +102,7 @@ func TestRandGUIDSearch_6(t *testing.T) {
102102
}
103103

104104
func TestFirstGUIDOffer(t *testing.T) {
105-
guid.Init(16) // Use 16-bit GUID to be easily tested
105+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
106106
resMap := NewResourcesMap(testPartitions)
107107

108108
targetResources := []Resources{
@@ -130,7 +130,7 @@ func TestFirstGUIDOffer(t *testing.T) {
130130
}
131131

132132
func TestLowestResources(t *testing.T) {
133-
guid.Init(16) // Use 16-bit GUID to be easily tested
133+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
134134
resMap := NewResourcesMap(testPartitions)
135135

136136
lowestResources := *resMap.LowestResources()
@@ -139,7 +139,7 @@ func TestLowestResources(t *testing.T) {
139139
}
140140

141141
func TestHigherRandomGUIDSearch_1(t *testing.T) {
142-
guid.Init(16) // Use 16-bit GUID to be easily tested
142+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
143143
resMap := NewResourcesMap(testPartitions)
144144

145145
randGUID, err := resMap.HigherRandGUIDSearch(*guid.NewGUIDInteger(5000), *NewResourcesCPUClass(0, 1, 256))
@@ -196,15 +196,15 @@ func TestHigherRandomGUIDSearch_1(t *testing.T) {
196196
}
197197

198198
func TestHigherRandomGUIDSearch_2(t *testing.T) {
199-
guid.Init(16) // Use 16-bit GUID to be easily tested
199+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
200200
resMap := NewResourcesMap(testPartitions)
201201

202202
_, err := resMap.HigherRandGUIDSearch(*guid.NewGUIDInteger(64000), *NewResourcesCPUClass(0, 1, 256))
203203
assert.Error(t, err, "")
204204
}
205205

206206
func TestHigherRandomGUIDSearch_3(t *testing.T) {
207-
guid.Init(16) // Use 16-bit GUID to be easily tested
207+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
208208
resMap := NewResourcesMap(testPartitions)
209209

210210
randGUID, err := resMap.HigherRandGUIDSearch(*guid.NewGUIDInteger(12287), *NewResourcesCPUClass(0, 1, 550))
@@ -247,7 +247,7 @@ func TestHigherRandomGUIDSearch_3(t *testing.T) {
247247
}
248248

249249
func TestLowerRandomGUID_1(t *testing.T) {
250-
guid.Init(16) // Use 16-bit GUID to be easily tested
250+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
251251
resMap := NewResourcesMap(testPartitions)
252252

253253
randGUID, err := resMap.LowerRandGUIDOffer(*guid.NewGUIDInteger(12287), *NewResourcesCPUClass(0, 1, 1024))
@@ -269,7 +269,7 @@ func TestLowerRandomGUID_1(t *testing.T) {
269269
}
270270

271271
func TestLowerRandomGUIDOffer_2(t *testing.T) {
272-
guid.Init(16) // Use 16-bit GUID to be easily tested
272+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
273273
resMap := NewResourcesMap(testPartitions)
274274

275275
randGUID, err := resMap.LowerRandGUIDOffer(*guid.NewGUIDInteger(20000), *NewResourcesCPUClass(0, 2, 2500))
@@ -298,7 +298,7 @@ func TestLowerRandomGUIDOffer_2(t *testing.T) {
298298
}
299299

300300
func TestLowerRandomGUIDOffer_3(t *testing.T) {
301-
guid.Init(16) // Use 16-bit GUID to be easily tested
301+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
302302
resMap := NewResourcesMap(testPartitions)
303303

304304
randGUID, err := resMap.LowerRandGUIDOffer(*guid.NewGUIDInteger(15000), *NewResourcesCPUClass(0, 2, 1512))
@@ -320,7 +320,7 @@ func TestLowerRandomGUIDOffer_3(t *testing.T) {
320320
}
321321

322322
func TestLowerRandomGUIDOffer_4(t *testing.T) {
323-
guid.Init(16) // Use 16-bit GUID to be easily tested
323+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
324324
resMap := NewResourcesMap(testPartitions)
325325

326326
randGUID, err := resMap.LowerRandGUIDOffer(*guid.NewGUIDInteger(35000), *NewResourcesCPUClass(1, 1, 1512))
@@ -349,7 +349,7 @@ func TestLowerRandomGUIDOffer_4(t *testing.T) {
349349
}
350350

351351
func TestLowerRandomGUIDOffer_5(t *testing.T) {
352-
guid.Init(16) // Use 16-bit GUID to be easily tested
352+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
353353
resMap := NewResourcesMap(testPartitions)
354354

355355
randGUID, err := resMap.LowerRandGUIDOffer(*guid.NewGUIDInteger(50000), *NewResourcesCPUClass(1, 2, 2049))
@@ -399,7 +399,7 @@ func TestLowerRandomGUIDOffer_5(t *testing.T) {
399399
}
400400

401401
func TestLowerPartitionsOffer_1(t *testing.T) {
402-
guid.Init(16) // Use 16-bit GUID to be easily tested
402+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
403403
resMap := NewResourcesMap(testPartitions)
404404

405405
res, err := resMap.LowerPartitionsOffer(*NewResourcesCPUClass(0, 1, 512))
@@ -410,7 +410,7 @@ func TestLowerPartitionsOffer_1(t *testing.T) {
410410
}
411411

412412
func TestLowerPartitionsOffer_2(t *testing.T) {
413-
guid.Init(16) // Use 16-bit GUID to be easily tested
413+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
414414
resMap := NewResourcesMap(testPartitions)
415415

416416
res, err := resMap.LowerPartitionsOffer(*NewResourcesCPUClass(0, 1, 750))
@@ -421,7 +421,7 @@ func TestLowerPartitionsOffer_2(t *testing.T) {
421421
}
422422

423423
func TestLowerPartitionsOffer_3(t *testing.T) {
424-
guid.Init(16) // Use 16-bit GUID to be easily tested
424+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
425425
resMap := NewResourcesMap(testPartitions)
426426

427427
res, err := resMap.LowerPartitionsOffer(*NewResourcesCPUClass(0, 1, 1550))
@@ -432,7 +432,7 @@ func TestLowerPartitionsOffer_3(t *testing.T) {
432432
}
433433

434434
func TestLowerPartitionsOffer_4(t *testing.T) {
435-
guid.Init(16) // Use 16-bit GUID to be easily tested
435+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
436436
resMap := NewResourcesMap(testPartitions)
437437

438438
res, err := resMap.LowerPartitionsOffer(*NewResourcesCPUClass(0, 2, 1550))
@@ -443,7 +443,7 @@ func TestLowerPartitionsOffer_4(t *testing.T) {
443443
}
444444

445445
func TestLowerPartitionsOffer_5(t *testing.T) {
446-
guid.Init(16) // Use 16-bit GUID to be easily tested
446+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
447447
resMap := NewResourcesMap(testPartitions)
448448

449449
res, err := resMap.LowerPartitionsOffer(*NewResourcesCPUClass(0, 2, 2049))
@@ -454,7 +454,7 @@ func TestLowerPartitionsOffer_5(t *testing.T) {
454454
}
455455

456456
func TestLowerPartitionsOffer_6(t *testing.T) {
457-
guid.Init(16) // Use 16-bit GUID to be easily tested
457+
guid.Init(16, 1, 1) // Use 16-bit GUID to be easily tested
458458
resMap := NewResourcesMap(testPartitions)
459459

460460
res, err := resMap.LowerPartitionsOffer(*NewResourcesCPUClass(1, 2, 2049))

node/common/resources/resources.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ func NewResourcesCPUClass(cpuClass int, cpus int, memory int) *Resources {
2121
//
2222
func NewResources(cpus int, memory int) *Resources {
2323
return &Resources{
24-
cpus: cpus,
25-
memory: memory,
24+
cpuClass: 0,
25+
cpus: cpus,
26+
memory: memory,
2627
}
2728
}
2829

0 commit comments

Comments
 (0)