本文整理汇总了Golang中github.com/pblcache/pblcache/tests.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAsuOpenFile
func TestAsuOpenFile(t *testing.T) {
usedirectio := true
asu := NewAsu(usedirectio)
mockfile := tests.NewMockFile()
mockerror := errors.New("Test Error")
directio_set := false
// Mock openFile
defer tests.Patch(&openFile,
func(name string, flag int, perm os.FileMode) (Filer, error) {
directio_set = false
if (flag & cache.OSSYNC) == cache.OSSYNC {
directio_set = true
}
return mockfile, mockerror
}).Restore()
// Call
err := asu.Open("filename")
// Check results
tests.Assert(t, directio_set == true)
tests.Assert(t, err == mockerror)
// Now try without directio set
usedirectio = false
asu = NewAsu(usedirectio)
// Check results
err = asu.Open("filename")
tests.Assert(t, directio_set == false)
tests.Assert(t, err == mockerror)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:35,代码来源:asu_test.go
示例2: TestIoMeterDeltas
func TestIoMeterDeltas(t *testing.T) {
prev := &IoMeter{
Ios: 1000,
Blocks: 5000,
}
prev.Latency.Add(time.Millisecond)
prev.Latency.Add(time.Millisecond)
prev.Latency.Add(time.Millisecond)
prev.Latency.Add(time.Millisecond)
meter := &IoMeter{}
*meter = *prev
meter.Ios += 500
meter.Blocks += 500
meter.Latency.Add(time.Millisecond * 2)
meter.Latency.Add(time.Millisecond * 2)
meter.Latency.Add(time.Millisecond * 2)
meter.Latency.Add(time.Millisecond * 2)
// Test Accessors
tests.Assert(t, meter.MeanLatencyDeltaUsecs(prev) == 2000.0)
tests.Assert(t, meter.IosDelta(prev) == 500)
tests.Assert(t, meter.MeanLatencyUsecs() == 1500.0)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:25,代码来源:iometer_test.go
示例3: TestNullPipeline
func TestNullPipeline(t *testing.T) {
destination := make(chan *Message)
pipe := make(chan *Message)
np := NewNullPipeline(pipe)
defer np.Close()
np.Start()
m := &Message{
Type: MsgPut,
RetChan: destination,
}
// Send message
np.In <- m
// Pipe should be the first to see it
returnedmsg := <-pipe
tests.Assert(t, returnedmsg == m)
// Now we finish the message
m.Done()
// It should arrive at destination
returnedmsg = <-destination
tests.Assert(t, returnedmsg == m)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:27,代码来源:null_test.go
示例4: TestInvalidateMultipleBlocks
func TestInvalidateMultipleBlocks(t *testing.T) {
nc := message.NewNullTerminator()
nc.Start()
defer nc.Close()
c := NewCacheMap(8, 4096, nc.In)
tests.Assert(t, c != nil)
defer c.Close()
// Insert some values in the addressmap
for i := uint32(0); i < 4; i++ {
// The key is block number
c.addressmap[uint64(i)] = i
}
// This value should still be on the addressmap
c.addressmap[8] = 8
iopkt := &message.IoPkt{
Address: 0,
Blocks: 8,
}
c.Invalidate(iopkt)
tests.Assert(t, c.stats.invalidations == uint64(iopkt.Blocks))
tests.Assert(t, c.stats.invalidatehits == 4)
tests.Assert(t, c.addressmap[8] == 8)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:29,代码来源:cachemap_test.go
示例5: TestNewSpcStats
func TestNewSpcStats(t *testing.T) {
s := NewSpcStats()
tests.Assert(t, len(s.Asustats) == 3)
tests.Assert(t, s.Asustats[ASU1] != nil)
tests.Assert(t, s.Asustats[ASU2] != nil)
tests.Assert(t, s.Asustats[ASU3] != nil)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:7,代码来源:spcstats_test.go
示例6: TestNullNewTerminator
func TestNullNewTerminator(t *testing.T) {
np := NewNullTerminator()
defer np.Close()
tests.Assert(t, np.In != nil)
tests.Assert(t, len(np.In) == 0)
tests.Assert(t, np.Out == nil)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:8,代码来源:null_test.go
示例7: TestNullNewPipeline
func TestNullNewPipeline(t *testing.T) {
out := make(chan *Message)
np := NewNullPipeline(out)
defer np.Close()
tests.Assert(t, np.In != nil)
tests.Assert(t, len(np.In) == 0)
tests.Assert(t, np.Out == out)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:9,代码来源:null_test.go
示例8: TestRamHitRate
func TestRamHitRate(t *testing.T) {
s := &logstats{}
ls := s.Stats()
tests.Assert(t, ls.RamHitRate() == 0.0)
s.ramhits = 100
s.totalhits = 200
ls = s.Stats()
tests.Assert(t, ls.RamHitRate() == 0.5)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:10,代码来源:log_stats_test.go
示例9: TestCacheStatsRates
func TestCacheStatsRates(t *testing.T) {
s := &cachestats{}
stats1 := s.stats()
stats2 := s.stats()
tests.Assert(t, stats1.ReadHitRate() == 0.0)
tests.Assert(t, stats1.InvalidateHitRate() == 0.0)
tests.Assert(t, stats1.ReadHitRateDelta(stats2) == 0.0)
tests.Assert(t, stats1.InvalidateHitRateDelta(stats2) == 0.0)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:10,代码来源:stats_test.go
示例10: TestIoPktString
func TestIoPktString(t *testing.T) {
m := NewMsgGet()
iopkt := m.IoPkt()
s := iopkt.String()
tests.Assert(t, strings.Contains(s, "Address"))
tests.Assert(t, strings.Contains(s, "LogBlock"))
tests.Assert(t, strings.Contains(s, "Blocks"))
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:10,代码来源:iopkt_test.go
示例11: TestBufferHitRate
func TestBufferHitRate(t *testing.T) {
s := &logstats{}
ls := s.Stats()
tests.Assert(t, ls.BufferHitRate() == 0.0)
s.bufferhits = 100
s.totalhits = 200
ls = s.Stats()
tests.Assert(t, ls.BufferHitRate() == 0.5)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:10,代码来源:log_stats_test.go
示例12: TestCacheStatsJson
func TestCacheStatsJson(t *testing.T) {
s := &cachestats{
readhits: 1,
invalidatehits: 12,
reads: 123,
evictions: 1234,
invalidations: 12345,
insertions: 123456,
}
// Encode
exportedstats := s.stats()
jsonstats, err := json.Marshal(exportedstats)
tests.Assert(t, err == nil)
// Decode and check with original
decstats := &CacheStats{}
err = json.Unmarshal(jsonstats, &decstats)
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(decstats, exportedstats))
tests.Assert(t, s.readhits == decstats.Readhits)
tests.Assert(t, s.invalidatehits == decstats.Invalidatehits)
tests.Assert(t, s.reads == decstats.Reads)
tests.Assert(t, s.evictions == decstats.Evictions)
tests.Assert(t, s.invalidations == decstats.Invalidations)
tests.Assert(t, s.insertions == decstats.Insertions)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:28,代码来源:stats_test.go
示例13: TestCacheStatsCsvDelta
func TestCacheStatsCsvDelta(t *testing.T) {
s1 := &cachestats{
readhits: 1,
invalidatehits: 12,
reads: 123,
evictions: 1234,
invalidations: 12345,
insertions: 123456,
}
s2 := &cachestats{
readhits: 12,
invalidatehits: 123,
reads: 1234,
evictions: 12345,
invalidations: 123456,
insertions: 1234567,
}
stats1 := s1.stats()
stats2 := s2.stats()
slice := strings.Split(stats2.CsvDelta(stats1), ",")
// 8 elements per csv line + the empty
tests.Assert(t, len(slice) == 9)
tests.Assert(t, slice[0] == fmt.Sprintf("%v", stats2.ReadHitRateDelta(stats1)))
tests.Assert(t, slice[1] == fmt.Sprintf("%v", stats2.InvalidateHitRateDelta(stats1)))
tests.Assert(t, slice[2] == strconv.FormatUint(s2.readhits-s1.readhits, 10))
tests.Assert(t, slice[3] == strconv.FormatUint(s2.invalidatehits-s1.invalidatehits, 10))
tests.Assert(t, slice[4] == strconv.FormatUint(s2.reads-s1.reads, 10))
tests.Assert(t, slice[5] == strconv.FormatUint(s2.insertions-s1.insertions, 10))
tests.Assert(t, slice[6] == strconv.FormatUint(s2.evictions-s1.evictions, 10))
tests.Assert(t, slice[7] == strconv.FormatUint(s2.invalidations-s1.invalidations, 10))
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:33,代码来源:stats_test.go
示例14: TestInvalidateIoPkt
func TestInvalidateIoPkt(t *testing.T) {
c := make(chan *Message)
m := NewMsgGet()
m.RetChan = c
iopkt := m.IoPkt()
tests.Assert(t, iopkt.LogBlock == 0)
tests.Assert(t, iopkt.Buffer == nil)
tests.Assert(t, iopkt.Address == 0)
tests.Assert(t, m.RetChan == c)
tests.Assert(t, m.Type == MsgGet)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:11,代码来源:iopkt_test.go
示例15: TestAddressUtils
func TestAddressUtils(t *testing.T) {
a := Address{
Devid: 9876,
Block: 123456789,
}
merged := Address64(a)
converted := AddressValue(merged)
tests.Assert(t, a.Devid == converted.Devid)
tests.Assert(t, a.Block == converted.Block)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:12,代码来源:addressutils_test.go
示例16: TestMsgIoDone
func TestMsgIoDone(t *testing.T) {
// Channel to send
worker := make(chan *Message)
// Return channel
backhere := make(chan *Message)
// Message
m := NewMsgPut()
m.Priv = &Data{i: 1}
m.RetChan = backhere
// Start 'work' service
go func() {
// Wait for work
msg := <-worker
d := msg.Priv.(*Data)
io := msg.IoPkt()
io.Buffer = []byte("TESTSTRING")
tests.Assert(t, msg.Type == MsgPut)
tests.Assert(t, d.i == 1)
// Increment the offset here to test
d.i += 1
// Return to channel
msg.Done()
}()
// Send to 'work'
worker <- m
// Wait until it is done
rm := <-backhere
// Get the data
newD := rm.Priv.(*Data)
io := rm.IoPkt()
// Check results
tests.Assert(t, newD.i == 2)
tests.Assert(t, string(io.Buffer) == "TESTSTRING")
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:46,代码来源:iopkt_test.go
示例17: TestIoMeterCsvDelta
func TestIoMeterCsvDelta(t *testing.T) {
spc1info := &spc1.Spc1Io{
Asu: 1,
Blocks: 1,
Stream: 2,
Offset: 123456,
When: time.Second * 2,
}
stat := &IoStats{
Io: spc1info,
Start: time.Now(),
Latency: time.Millisecond * 3,
}
// Inster first data point
meter := &IoMeter{}
meter.Collect(stat)
tests.Assert(t, meter.Blocks == 1)
tests.Assert(t, meter.Ios == 1)
tests.Assert(t, meter.Latency.MeanTimeUsecs() == 3000.0)
prev := &IoMeter{}
s := meter.CsvDelta(prev, time.Millisecond)
split := strings.Split(s, ",")
tests.Assert(t, split[0] == "1")
tests.Assert(t, split[1] == "4096")
tests.Assert(t, strings.Contains(split[2], "3.9"))
tests.Assert(t, strings.Contains(split[3], "3000"))
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:31,代码来源:iometer_test.go
示例18: TestAsuSize
func TestAsuSize(t *testing.T) {
usedirectio := false
asu := NewAsu(usedirectio)
// set fake length
asu.len = 1234 * GB / (4 * KB)
tests.Assert(t, float64(1234) == asu.Size())
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:9,代码来源:asu_test.go
示例19: TestNewCacheMap
func TestNewCacheMap(t *testing.T) {
nc := message.NewNullTerminator()
nc.Start()
defer nc.Close()
c := NewCacheMap(8, 4096, nc.In)
tests.Assert(t, c != nil)
c.Close()
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:9,代码来源:cachemap_test.go
示例20: TestLogStatsSegmentReadTimeRecord
func TestLogStatsSegmentReadTimeRecord(t *testing.T) {
s := &logstats{}
s.SegmentReadTimeRecord(50 * 1000)
s.SegmentReadTimeRecord(50 * 1000)
tests.Assert(t, s.readtime.MeanTimeUsecs() == 0.0)
tests.Assert(t, s.segmentreadtime.MeanTimeUsecs() == 50.0)
tests.Assert(t, s.writetime.MeanTimeUsecs() == 0.0)
tests.Assert(t, s.ramhits == 0)
tests.Assert(t, s.storagehits == 0)
tests.Assert(t, s.wraps == 0)
tests.Assert(t, s.seg_skipped == 0)
tests.Assert(t, s.bufferhits == 0)
tests.Assert(t, s.totalhits == 0)
}
开发者ID:chenweicai,项目名称:pblcache,代码行数:16,代码来源:log_stats_test.go
注:本文中的github.com/pblcache/pblcache/tests.Assert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论