本文整理汇总了Golang中github.com/pblcache/pblcache/tests.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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"))
}
示例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)
}
示例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)
}
示例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))
}
示例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)
}
示例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)
}