當前位置: 首頁>>代碼示例>>Golang>>正文


Golang tests.Assert函數代碼示例

本文整理匯總了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)
}
開發者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


注:本文中的github.com/pblcache/pblcache/tests.Assert函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。