本文整理汇总了Golang中github.com/cockroachdb/cockroach/ts.Stop函数的典型用法代码示例。如果您正苦于以下问题:Golang Stop函数的具体用法?Golang Stop怎么用?Golang Stop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Stop函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRangesResponse
func TestRangesResponse(t *testing.T) {
defer leaktest.AfterTest(t)()
ts := startServer(t)
defer ts.Stop()
var response RangesResponse
if err := getRequestProto(t, ts, statusRangesPrefix+"local", &response); err != nil {
t.Fatal(err)
}
if len(response.Ranges) == 0 {
t.Errorf("didn't get any ranges")
}
for _, ri := range response.Ranges {
// Do some simple validation based on the fact that this is a
// single-node cluster.
if ri.RaftState != "StateLeader" {
t.Errorf("expected to be raft leader but was %s", ri.RaftState)
}
expReplica := roachpb.ReplicaDescriptor{
NodeID: 1,
StoreID: 1,
ReplicaID: 1,
}
if len(ri.Desc.Replicas) != 1 || ri.Desc.Replicas[0] != expReplica {
t.Errorf("unexpected replica list %+v", ri.Desc.Replicas)
}
}
}
开发者ID:JKhawaja,项目名称:cockroach,代码行数:28,代码来源:status_test.go
示例2: TestNodeStatusResponse
// TestNodeStatusResponse verifies that node status returns the expected
// results.
func TestNodeStatusResponse(t *testing.T) {
defer leaktest.AfterTest(t)()
ts := startServer(t)
defer ts.Stop()
// First fetch all the node statuses.
wrapper := NodesResponse{}
if err := getRequestProto(t, ts, statusNodesPrefix, &wrapper); err != nil {
t.Fatal(err)
}
nodeStatuses := wrapper.Nodes
if len(nodeStatuses) != 1 {
t.Errorf("too many node statuses returned - expected:1 actual:%d", len(nodeStatuses))
}
if !reflect.DeepEqual(ts.node.Descriptor, nodeStatuses[0].Desc) {
t.Errorf("node status descriptors are not equal\nexpected:%+v\nactual:%+v\n", ts.node.Descriptor, nodeStatuses[0].Desc)
}
// Now fetch each one individually. Loop through the nodeStatuses to use the
// ids only.
for _, oldNodeStatus := range nodeStatuses {
nodeStatus := status.NodeStatus{}
if err := getRequestProto(t, ts, PathForNodeStatus(oldNodeStatus.Desc.NodeID.String()), &nodeStatus); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(ts.node.Descriptor, nodeStatus.Desc) {
t.Errorf("node status descriptors are not equal\nexpected:%+v\nactual:%+v\n", ts.node.Descriptor, nodeStatus.Desc)
}
}
}
开发者ID:JKhawaja,项目名称:cockroach,代码行数:33,代码来源:status_test.go
示例3: TestNodeStatusResponse
// TestNodeStatusResponse verifies that node status returns the expected
// results.
func TestNodeStatusResponse(t *testing.T) {
defer leaktest.AfterTest(t)
ts, body := startServerAndGetStatus(t, statusNodeKeyPrefix)
defer ts.Stop()
// First fetch all the node statuses.
type nsWrapper struct {
Data []status.NodeStatus `json:"d"`
}
wrapper := nsWrapper{}
if err := json.Unmarshal(body, &wrapper); err != nil {
t.Fatal(err)
}
nodeStatuses := wrapper.Data
if len(nodeStatuses) != 1 {
t.Errorf("too many node statuses returned - expected:1 actual:%d", len(nodeStatuses))
}
if !reflect.DeepEqual(ts.node.Descriptor, nodeStatuses[0].Desc) {
t.Errorf("node status descriptors are not equal\nexpected:%+v\nactual:%+v\n", ts.node.Descriptor, nodeStatuses[0].Desc)
}
// Now fetch each one individually. Loop through the nodeStatuses to use the
// ids only.
for _, oldNodeStatus := range nodeStatuses {
nodeStatus := &status.NodeStatus{}
requestBody := getRequest(t, ts, fmt.Sprintf("%s%s", statusNodeKeyPrefix, oldNodeStatus.Desc.NodeID))
if err := json.Unmarshal(requestBody, &nodeStatus); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(ts.node.Descriptor, nodeStatus.Desc) {
t.Errorf("node status descriptors are not equal\nexpected:%+v\nactual:%+v\n", ts.node.Descriptor, nodeStatus.Desc)
}
}
}
开发者ID:Gardenya,项目名称:cockroach,代码行数:37,代码来源:status_test.go
示例4: TestStoreStatusResponse
// TestStoreStatusResponse verifies that node status returns the expected
// results.
func TestStoreStatusResponse(t *testing.T) {
defer leaktest.AfterTest(t)
t.Skip("TODO(bram): disabled until #2440 is fixed")
ts := startServer(t)
defer ts.Stop()
body := getRequest(t, ts, statusStoresPrefix)
type ssWrapper struct {
Data []storage.StoreStatus `json:"d"`
}
wrapper := ssWrapper{}
if err := json.Unmarshal(body, &wrapper); err != nil {
t.Fatal(err)
}
storeStatuses := wrapper.Data
if len(storeStatuses) != ts.node.lSender.GetStoreCount() {
t.Errorf("expected %d node statuses, got %d", ts.node.lSender.GetStoreCount(), len(storeStatuses))
}
for _, storeStatus := range storeStatuses {
storeID := storeStatus.Desc.StoreID
store, err := ts.node.lSender.GetStore(storeID)
if err != nil {
t.Fatal(err)
}
desc, err := store.Descriptor()
if err != nil {
t.Fatal(err)
}
// The capacities fluctuate a lot, so drop them for the deep equal.
desc.Capacity = proto.StoreCapacity{}
storeStatus.Desc.Capacity = proto.StoreCapacity{}
if !reflect.DeepEqual(*desc, storeStatus.Desc) {
t.Errorf("store status descriptors are not equal\nexpected:%+v\nactual:%+v\n", *desc, storeStatus.Desc)
}
// Also fetch the each status individually.
fetchedStoreStatus := storage.StoreStatus{}
requestBody := getRequest(t, ts, fmt.Sprintf("%s%s", statusStoresPrefix, storeStatus.Desc.StoreID))
if err := json.Unmarshal(requestBody, &fetchedStoreStatus); err != nil {
t.Fatal(err)
}
fetchedStoreStatus.Desc.Capacity = proto.StoreCapacity{}
if !reflect.DeepEqual(*desc, fetchedStoreStatus.Desc) {
t.Errorf("store status descriptors are not equal\nexpected:%+v\nactual:%+v\n", *desc, fetchedStoreStatus.Desc)
}
}
}
开发者ID:WentaoXu,项目名称:cockroach,代码行数:51,代码来源:status_test.go
示例5: TestStatusLocalLogs
// TestStatusLocalLogs checks to ensure that local/logfiles,
// local/logfiles/{filename}, local/log and local/log/{level} function
// correctly.
func TestStatusLocalLogs(t *testing.T) {
defer leaktest.AfterTest(t)
dir, err := ioutil.TempDir("", "local_log_test")
if err != nil {
t.Fatal(err)
}
log.EnableLogFileOutput(dir)
defer func() {
log.DisableLogFileOutput()
if err := os.RemoveAll(dir); err != nil {
t.Fatal(err)
}
}()
ts := startServer(t, statusLocalLogFileKeyPrefix)
defer ts.Stop()
// Log an error which we expect to show up on every log file.
timestamp := time.Now().UnixNano()
log.Errorf("TestStatusLocalLogFile test message-Error")
timestampE := time.Now().UnixNano()
log.Warningf("TestStatusLocalLogFile test message-Warning")
timestampEW := time.Now().UnixNano()
log.Infof("TestStatusLocalLogFile test message-Info")
timestampEWI := time.Now().UnixNano()
body := getRequest(t, ts, statusLocalLogFileKeyPrefix)
type logsWrapper struct {
Data []log.FileInfo `json:"d"`
}
logs := logsWrapper{}
if err := json.Unmarshal(body, &logs); err != nil {
t.Fatal(err)
}
if a, e := len(logs.Data), 3; a != e {
t.Fatalf("expected %d log files; got %d", e, a)
}
for i, name := range []string{"log.ERROR", "log.INFO", "log.WARNING"} {
if !strings.Contains(logs.Data[i].Name, name) {
t.Errorf("expected log file name %s to contain %q", logs.Data[i].Name, name)
}
}
// Fetch a each listed log directly.
type logWrapper struct {
Data []log.LogEntry `json:"d"`
}
// Check each individual log can be fetched and is non-empty.
for _, log := range logs.Data {
body = getRequest(t, ts, fmt.Sprintf("%s%s", statusLocalLogFileKeyPrefix, log.Name))
logW := logWrapper{}
if err := json.Unmarshal(body, &logW); err != nil {
t.Fatal(err)
}
var found bool
for _, data := range logW.Data {
if data.Format == "TestStatusLocalLogFile test message-Error" {
found = true
break
}
}
if !found {
t.Errorf("expected to find test message in %v", logW.Data)
}
}
// Fetch the full list of log entries.
type entryWrapper struct {
Data []log.LogEntry `json:"d"`
}
testCases := []struct {
Level log.Severity
MaxEntities int
StartTimestamp int64
EndTimestamp int64
Pattern string
ExpectedError bool
ExpectedWarning bool
ExpectedInfo bool
}{
// Test filtering by log severity.
{log.InfoLog, 0, 0, 0, "", true, true, true},
{log.WarningLog, 0, 0, 0, "", true, true, false},
{log.ErrorLog, 0, 0, 0, "", true, false, false},
// Test filtering in different timestamp windows.
{log.InfoLog, 1, timestamp, timestampEWI, "", true, false, false},
{log.InfoLog, 2, timestamp, timestampEWI, "", true, true, false},
{log.InfoLog, 3, timestamp, timestampEWI, "", true, true, true},
{log.InfoLog, 0, timestamp, timestamp, "", false, false, false},
{log.InfoLog, 0, timestamp, timestampE, "", true, false, false},
{log.InfoLog, 0, timestampE, timestampEW, "", false, true, false},
{log.InfoLog, 0, timestampEW, timestampEWI, "", false, false, true},
{log.InfoLog, 0, timestamp, timestampEW, "", true, true, false},
{log.InfoLog, 0, timestampE, timestampEWI, "", false, true, true},
{log.InfoLog, 0, timestamp, timestampEWI, "", true, true, true},
//.........这里部分代码省略.........
开发者ID:zhaoyta,项目名称:cockroach,代码行数:101,代码来源:status_test.go
示例6: TestStatusLocalLogs
// TestStatusLocalLogs checks to ensure that local/logfiles,
// local/logfiles/{filename}, local/log and local/log/{level} function
// correctly.
func TestStatusLocalLogs(t *testing.T) {
defer leaktest.AfterTest(t)
dir, err := ioutil.TempDir("", "local_log_test")
if err != nil {
t.Fatal(err)
}
log.EnableLogFileOutput(dir)
defer func() {
log.DisableLogFileOutput()
if err := os.RemoveAll(dir); err != nil {
t.Fatal(err)
}
}()
ts := startServer(t)
defer ts.Stop()
// Log an error which we expect to show up on every log file.
timestamp := time.Now().UnixNano()
log.Errorf("TestStatusLocalLogFile test message-Error")
timestampE := time.Now().UnixNano()
log.Warningf("TestStatusLocalLogFile test message-Warning")
timestampEW := time.Now().UnixNano()
log.Infof("TestStatusLocalLogFile test message-Info")
timestampEWI := time.Now().UnixNano()
type logsWrapper struct {
Data []log.FileInfo `json:"d"`
}
var logs logsWrapper
if err := json.Unmarshal(getRequest(t, ts, "/_status/logfiles/local"), &logs); err != nil {
t.Fatal(err)
}
if a, e := len(logs.Data), 3; a != e {
t.Fatalf("expected %d log files; got %d", e, a)
}
for i, name := range []string{"log.ERROR", "log.INFO", "log.WARNING"} {
if !strings.Contains(logs.Data[i].Name, name) {
t.Errorf("expected log file name %s to contain %q", logs.Data[i].Name, name)
}
}
// Fetch the full list of log entries.
type logWrapper struct {
Data []log.LogEntry `json:"d"`
}
// Check each individual log can be fetched and is non-empty.
var foundInfo, foundWarning, foundError bool
for _, file := range logs.Data {
var log logWrapper
if err := json.Unmarshal(getRequest(t, ts, fmt.Sprintf("/_status/logfiles/local/%s", file.Name)), &log); err != nil {
t.Fatal(err)
}
for _, entry := range log.Data {
switch entry.Format {
case "TestStatusLocalLogFile test message-Error":
foundError = true
case "TestStatusLocalLogFile test message-Warning":
foundWarning = true
case "TestStatusLocalLogFile test message-Info":
foundInfo = true
}
}
}
if !(foundInfo && foundWarning && foundError) {
t.Errorf("expected to find test messages in %v", logs.Data)
}
testCases := []struct {
Level log.Severity
MaxEntities int
StartTimestamp int64
EndTimestamp int64
Pattern string
ExpectedError bool
ExpectedWarning bool
ExpectedInfo bool
}{
// Test filtering by log severity.
{log.InfoLog, 0, 0, 0, "", true, true, true},
{log.WarningLog, 0, 0, 0, "", true, true, false},
{log.ErrorLog, 0, 0, 0, "", true, false, false},
// Test entry limit. Ignore Info/Warning/Error filters.
{log.InfoLog, 1, timestamp, timestampEWI, "", false, false, false},
{log.InfoLog, 2, timestamp, timestampEWI, "", false, false, false},
{log.InfoLog, 3, timestamp, timestampEWI, "", false, false, false},
// Test filtering in different timestamp windows.
{log.InfoLog, 0, timestamp, timestamp, "", false, false, false},
{log.InfoLog, 0, timestamp, timestampE, "", true, false, false},
{log.InfoLog, 0, timestampE, timestampEW, "", false, true, false},
{log.InfoLog, 0, timestampEW, timestampEWI, "", false, false, true},
{log.InfoLog, 0, timestamp, timestampEW, "", true, true, false},
{log.InfoLog, 0, timestampE, timestampEWI, "", false, true, true},
{log.InfoLog, 0, timestamp, timestampEWI, "", true, true, true},
// Test filtering by regexp pattern.
//.........这里部分代码省略.........
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:101,代码来源:status_test.go
示例7: TestStatusLocalLogs
// TestStatusLocalLogs checks to ensure that local/logfiles,
// local/logfiles/{filename}, local/log and local/log/{level} function
// correctly.
func TestStatusLocalLogs(t *testing.T) {
defer leaktest.AfterTest(t)
dir, err := ioutil.TempDir("", "local_log_test")
if err != nil {
t.Fatal(err)
}
log.EnableLogFileOutput(dir)
defer func() {
log.DisableLogFileOutput()
if err := os.RemoveAll(dir); err != nil {
t.Fatal(err)
}
}()
ts, body := startServerAndGetStatus(t, statusLocalLogFileKeyPrefix)
defer ts.Stop()
type logsWrapper struct {
Data []log.FileInfo `json:"d"`
}
logs := logsWrapper{}
if err := json.Unmarshal(body, &logs); err != nil {
t.Fatal(err)
}
if l := len(logs.Data); l != 3 {
t.Fatalf("expected 3 log files; got %d", l)
}
for i, pat := range []string{`.*log.ERROR.*`, `.*log.INFO.*`, `.*log.WARNING.*`} {
if ok, err := regexp.MatchString(pat, logs.Data[i].Name); !ok || err != nil {
t.Errorf("expected log file %s to match %q: %s", logs.Data[i].Name, pat, err)
}
}
// Log an error which we expect to show up on every log file.
timestamp := time.Now().UnixNano()
log.Errorf("TestStatusLocalLogFile test message-Error")
timestampE := time.Now().UnixNano()
log.Warningf("TestStatusLocalLogFile test message-Warning")
timestampEW := time.Now().UnixNano()
log.Infof("TestStatusLocalLogFile test message-Info")
timestampEWI := time.Now().UnixNano()
// Fetch a each listed log directly.
type logWrapper struct {
Data []log.LogEntry `json:"d"`
}
// Check each individual log can be fetched and is non-empty.
for _, log := range logs.Data {
body = getRequest(t, ts, fmt.Sprintf("%s%s", statusLocalLogFileKeyPrefix, log.Name))
logW := logWrapper{}
if err := json.Unmarshal(body, &logW); err != nil {
t.Fatal(err)
}
var found bool
for i := len(logW.Data) - 1; i >= 0; i-- {
if logW.Data[i].Format == "TestStatusLocalLogFile test message-Error" {
found = true
break
}
}
if !found {
t.Errorf("expected to find test message in %v", logW.Data)
}
}
// Fetch the full list of log entries.
type entryWrapper struct {
Data []log.LogEntry `json:"d"`
}
testCases := []struct {
Level log.Severity
MaxEntities int
StartTimestamp int64
EndTimestamp int64
ExpectedError bool
ExpectedWarning bool
ExpectedInfo bool
}{
{log.InfoLog, 0, 0, 0, true, true, true},
{log.WarningLog, 0, 0, 0, true, true, false},
{log.ErrorLog, 0, 0, 0, true, false, false},
{log.InfoLog, 1, timestamp, timestampEWI, true, false, false},
{log.InfoLog, 2, timestamp, timestampEWI, true, true, false},
{log.InfoLog, 3, timestamp, timestampEWI, true, true, true},
{log.InfoLog, 0, timestamp, timestamp, false, false, false},
{log.InfoLog, 0, timestamp, timestampE, true, false, false},
{log.InfoLog, 0, timestampE, timestampEW, false, true, false},
{log.InfoLog, 0, timestampEW, timestampEWI, false, false, true},
{log.InfoLog, 0, timestamp, timestampEW, true, true, false},
{log.InfoLog, 0, timestampE, timestampEWI, false, true, true},
{log.InfoLog, 0, timestamp, timestampEWI, true, true, true},
}
for i, testCase := range testCases {
var url bytes.Buffer
fmt.Fprintf(&url, "%s%s?", statusLocalLogKeyPrefix, testCase.Level.Name())
if testCase.MaxEntities > 0 {
//.........这里部分代码省略.........
开发者ID:Gardenya,项目名称:cockroach,代码行数:101,代码来源:status_test.go
注:本文中的github.com/cockroachdb/cockroach/ts.Stop函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论