-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_pool_test.go
53 lines (42 loc) · 1.13 KB
/
resource_pool_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
package basil
import (
. "launchpad.net/gocheck"
)
type RPSuite struct{}
func init() {
Suite(&RPSuite{})
}
type FakeConsumer struct {
UsedMemoryInBytes int
UsedDiskInBytes int
}
func (c *FakeConsumer) CurrentUsage() Usage {
return Usage{
MemoryInBytes: c.UsedMemoryInBytes,
DiskInBytes: c.UsedDiskInBytes,
}
}
func (s *RPSuite) TestResourcePoolAvailableMemory(c *C) {
config := Config{
Capacity: CapacityConfig{
MemoryInBytes: 1 * gigabyte,
DiskInBytes: 1 * gigabyte,
},
}
pool := NewResourcePool(config)
pool.AddConsumer(&FakeConsumer{UsedMemoryInBytes: 42})
pool.AddConsumer(&FakeConsumer{UsedMemoryInBytes: 128})
c.Assert(pool.AvailableMemory(), Equals, (1 * gigabyte) - 42 - 128)
}
func (s *RPSuite) TestResourcePoolAvailableDisk(c *C) {
config := Config{
Capacity: CapacityConfig{
MemoryInBytes: 1 * gigabyte,
DiskInBytes: 1 * gigabyte,
},
}
pool := NewResourcePool(config)
pool.AddConsumer(&FakeConsumer{UsedDiskInBytes: 42})
pool.AddConsumer(&FakeConsumer{UsedDiskInBytes: 128})
c.Assert(pool.AvailableDisk(), Equals, (1 * gigabyte) - 42 - 128)
}