本文整理匯總了Golang中github.com/nsqio/nsq/internal/test.NewTestLogger函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTestLogger函數的具體用法?Golang NewTestLogger怎麽用?Golang NewTestLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTestLogger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestHTTPconfig
func TestHTTPconfig(t *testing.T) {
lopts := nsqlookupd.NewOptions()
lopts.Logger = test.NewTestLogger(t)
_, _, lookupd1 := mustStartNSQLookupd(lopts)
defer lookupd1.Exit()
_, _, lookupd2 := mustStartNSQLookupd(lopts)
defer lookupd2.Exit()
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, httpAddr, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
url := fmt.Sprintf("http://%s/config/nsqlookupd_tcp_addresses", httpAddr)
resp, err := http.Get(url)
test.Nil(t, err)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
test.Equal(t, 200, resp.StatusCode)
test.Equal(t, "[]", string(body))
client := http.Client{}
addrs := fmt.Sprintf(`["%s","%s"]`, lookupd1.RealTCPAddr().String(), lookupd2.RealTCPAddr().String())
url = fmt.Sprintf("http://%s/config/nsqlookupd_tcp_addresses", httpAddr)
req, err := http.NewRequest("PUT", url, bytes.NewBuffer([]byte(addrs)))
test.Nil(t, err)
resp, err = client.Do(req)
test.Nil(t, err)
defer resp.Body.Close()
body, _ = ioutil.ReadAll(resp.Body)
test.Equal(t, 200, resp.StatusCode)
test.Equal(t, addrs, string(body))
}
示例2: TestPauseMetadata
func TestPauseMetadata(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, _, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
// avoid concurrency issue of async PersistMetadata() calls
atomic.StoreInt32(&nsqd.isLoading, 1)
topicName := "pause_metadata" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
channel := topic.GetChannel("ch")
atomic.StoreInt32(&nsqd.isLoading, 0)
nsqd.PersistMetadata()
var isPaused = func(n *NSQD, topicIndex int, channelIndex int) bool {
m, _ := getMetadata(n)
return m.Topics[topicIndex].Channels[channelIndex].Paused
}
test.Equal(t, false, isPaused(nsqd, 0, 0))
channel.Pause()
test.Equal(t, false, isPaused(nsqd, 0, 0))
nsqd.PersistMetadata()
test.Equal(t, true, isPaused(nsqd, 0, 0))
channel.UnPause()
test.Equal(t, true, isPaused(nsqd, 0, 0))
nsqd.PersistMetadata()
test.Equal(t, false, isPaused(nsqd, 0, 0))
}
示例3: TestInactiveNodes
func TestInactiveNodes(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
opts.InactiveProducerTimeout = 200 * time.Millisecond
tcpAddr, httpAddr, nsqlookupd := mustStartLookupd(opts)
defer nsqlookupd.Exit()
lookupdHTTPAddrs := []string{fmt.Sprintf("%s", httpAddr)}
topicName := "inactive_nodes"
conn := mustConnectLookupd(t, tcpAddr)
defer conn.Close()
identify(t, conn)
nsq.Register(topicName, "channel1").WriteTo(conn)
_, err := nsq.ReadResponse(conn)
test.Nil(t, err)
ci := clusterinfo.New(nil, http_api.NewClient(nil, ConnectTimeout, RequestTimeout))
producers, _ := ci.GetLookupdProducers(lookupdHTTPAddrs)
test.Equal(t, 1, len(producers))
test.Equal(t, 1, len(producers[0].Topics))
test.Equal(t, topicName, producers[0].Topics[0].Topic)
test.Equal(t, false, producers[0].Topics[0].Tombstoned)
time.Sleep(250 * time.Millisecond)
producers, _ = ci.GetLookupdProducers(lookupdHTTPAddrs)
test.Equal(t, 0, len(producers))
}
示例4: TestChannelEmpty
func TestChannelEmpty(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, _, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_channel_empty" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
channel := topic.GetChannel("channel")
msgs := make([]*Message, 0, 25)
for i := 0; i < 25; i++ {
msg := NewMessage(<-nsqd.idChan, []byte("test"))
channel.StartInFlightTimeout(msg, 0, opts.MsgTimeout)
msgs = append(msgs, msg)
}
channel.RequeueMessage(0, msgs[len(msgs)-1].ID, 100*time.Millisecond)
test.Equal(t, 24, len(channel.inFlightMessages))
test.Equal(t, 24, len(channel.inFlightPQ))
test.Equal(t, 1, len(channel.deferredMessages))
test.Equal(t, 1, len(channel.deferredPQ))
channel.Empty()
test.Equal(t, 0, len(channel.inFlightMessages))
test.Equal(t, 0, len(channel.inFlightPQ))
test.Equal(t, 0, len(channel.deferredMessages))
test.Equal(t, 0, len(channel.deferredPQ))
test.Equal(t, int64(0), channel.Depth())
}
示例5: TestHTTPpubDefer
func TestHTTPpubDefer(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, httpAddr, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_http_pub_defer" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
ch := topic.GetChannel("ch")
buf := bytes.NewBuffer([]byte("test message"))
url := fmt.Sprintf("http://%s/pub?topic=%s&defer=%d", httpAddr, topicName, 1000)
resp, err := http.Post(url, "application/octet-stream", buf)
test.Nil(t, err)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
test.Equal(t, "OK", string(body))
time.Sleep(5 * time.Millisecond)
ch.deferredMutex.Lock()
numDef := len(ch.deferredMessages)
ch.deferredMutex.Unlock()
test.Equal(t, 1, numDef)
}
示例6: TestHTTPmput
func TestHTTPmput(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, httpAddr, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_http_mput" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
msg := []byte("test message")
msgs := make([][]byte, 4)
for i := range msgs {
msgs[i] = msg
}
buf := bytes.NewBuffer(bytes.Join(msgs, []byte("\n")))
url := fmt.Sprintf("http://%s/mput?topic=%s", httpAddr, topicName)
resp, err := http.Post(url, "application/octet-stream", buf)
test.Nil(t, err)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
test.Equal(t, "OK", string(body))
time.Sleep(5 * time.Millisecond)
test.Equal(t, int64(4), topic.Depth())
}
示例7: bootstrapNSQCluster
func bootstrapNSQCluster(t *testing.T) (string, []*nsqd.NSQD, *NSQLookupd) {
lgr := test.NewTestLogger(t)
nsqlookupdOpts := NewOptions()
nsqlookupdOpts.TCPAddress = "127.0.0.1:0"
nsqlookupdOpts.HTTPAddress = "127.0.0.1:0"
nsqlookupdOpts.BroadcastAddress = "127.0.0.1"
nsqlookupdOpts.Logger = lgr
nsqlookupd1 := New(nsqlookupdOpts)
go nsqlookupd1.Main()
time.Sleep(100 * time.Millisecond)
nsqdOpts := nsqd.NewOptions()
nsqdOpts.TCPAddress = "127.0.0.1:0"
nsqdOpts.HTTPAddress = "127.0.0.1:0"
nsqdOpts.BroadcastAddress = "127.0.0.1"
nsqdOpts.NSQLookupdTCPAddresses = []string{nsqlookupd1.RealTCPAddr().String()}
nsqdOpts.Logger = lgr
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano()))
if err != nil {
panic(err)
}
nsqdOpts.DataPath = tmpDir
nsqd1 := nsqd.New(nsqdOpts)
go nsqd1.Main()
time.Sleep(100 * time.Millisecond)
return tmpDir, []*nsqd.NSQD{nsqd1}, nsqlookupd1
}
示例8: TestTLSRequireVerifyExceptHTTP
func TestTLSRequireVerifyExceptHTTP(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
opts.Verbose = true
opts.TLSCert = "./test/certs/server.pem"
opts.TLSKey = "./test/certs/server.key"
opts.TLSRootCAFile = "./test/certs/ca.pem"
opts.TLSClientAuthPolicy = "require-verify"
opts.TLSRequired = TLSRequiredExceptHTTP
_, httpAddr, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_http_req_verf_except_http" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
// no cert
buf := bytes.NewBuffer([]byte("test message"))
url := fmt.Sprintf("http://%s/put?topic=%s", httpAddr, topicName)
resp, err := http.Post(url, "application/octet-stream", buf)
test.Nil(t, err)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
test.Equal(t, "OK", string(body))
time.Sleep(5 * time.Millisecond)
test.Equal(t, int64(1), topic.Depth())
}
示例9: testIOLoopReturnsClientErr
func testIOLoopReturnsClientErr(t *testing.T, fakeConn test.FakeNetConn) {
fakeConn.ReadFunc = func(b []byte) (int, error) {
return copy(b, []byte("INVALID_COMMAND\n")), nil
}
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
opts.Verbose = true
prot := &LookupProtocolV1{ctx: &Context{nsqlookupd: New(opts)}}
errChan := make(chan error)
testIOLoop := func() {
errChan <- prot.IOLoop(fakeConn)
defer prot.ctx.nsqlookupd.Exit()
}
go testIOLoop()
var err error
var timeout bool
select {
case err = <-errChan:
case <-time.After(2 * time.Second):
timeout = true
}
test.Equal(t, false, timeout)
test.NotNil(t, err)
test.Equal(t, "E_INVALID invalid command INVALID_COMMAND", err.Error())
test.NotNil(t, err.(*protocol.FatalClientErr))
}
示例10: TestChannelEmptyConsumer
func TestChannelEmptyConsumer(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
tcpAddr, _, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
conn, _ := mustConnectNSQD(tcpAddr)
defer conn.Close()
topicName := "test_channel_empty" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
channel := topic.GetChannel("channel")
client := newClientV2(0, conn, &context{nsqd})
client.SetReadyCount(25)
channel.AddClient(client.ID, client)
for i := 0; i < 25; i++ {
msg := NewMessage(<-nsqd.idChan, []byte("test"))
channel.StartInFlightTimeout(msg, 0, opts.MsgTimeout)
client.SendingMessage()
}
for _, cl := range channel.clients {
stats := cl.Stats()
test.Equal(t, int64(25), stats.InFlightCount)
}
channel.Empty()
for _, cl := range channel.clients {
stats := cl.Stats()
test.Equal(t, int64(0), stats.InFlightCount)
}
}
示例11: TestHTTPmputBinary
func TestHTTPmputBinary(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, httpAddr, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_http_mput_bin" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
mpub := make([][]byte, 5)
for i := range mpub {
mpub[i] = make([]byte, 100)
}
cmd, _ := nsq.MultiPublish(topicName, mpub)
buf := bytes.NewBuffer(cmd.Body)
url := fmt.Sprintf("http://%s/mput?topic=%s&binary=true", httpAddr, topicName)
resp, err := http.Post(url, "application/octet-stream", buf)
test.Nil(t, err)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
test.Equal(t, "OK", string(body))
time.Sleep(5 * time.Millisecond)
test.Equal(t, int64(5), topic.Depth())
}
示例12: TestStats
func TestStats(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
tcpAddr, _, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_stats" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
msg := NewMessage(<-nsqd.idChan, []byte("test body"))
topic.PutMessage(msg)
conn, err := mustConnectNSQD(tcpAddr)
test.Nil(t, err)
defer conn.Close()
identify(t, conn, nil, frameTypeResponse)
sub(t, conn, topicName, "ch")
stats := nsqd.GetStats()
t.Logf("stats: %+v", stats)
test.Equal(t, 1, len(stats))
test.Equal(t, 1, len(stats[0].Channels))
test.Equal(t, 1, len(stats[0].Channels[0].Clients))
}
示例13: TestBasicV2
// exercise the basic operations of the V2 protocol
func TestBasicV2(t *testing.T) {
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
opts.ClientTimeout = 60 * time.Second
tcpAddr, _, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
topicName := "test_v2" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)
msg := NewMessage(<-nsqd.idChan, []byte("test body"))
topic.PutMessage(msg)
conn, err := mustConnectNSQD(tcpAddr)
test.Nil(t, err)
defer conn.Close()
identify(t, conn, nil, frameTypeResponse)
sub(t, conn, topicName, "ch")
_, err = nsq.Ready(1).WriteTo(conn)
test.Nil(t, err)
resp, err := nsq.ReadResponse(conn)
test.Nil(t, err)
frameType, data, err := nsq.UnpackResponse(resp)
msgOut, _ := decodeMessage(data)
test.Equal(t, frameTypeMessage, frameType)
test.Equal(t, msg.ID, msgOut.ID)
test.Equal(t, msg.Body, msgOut.Body)
test.Equal(t, uint16(1), msgOut.Attempts)
}
示例14: TestReconfigure
func TestReconfigure(t *testing.T) {
lopts := nsqlookupd.NewOptions()
lopts.Logger = test.NewTestLogger(t)
_, _, lookupd1 := mustStartNSQLookupd(lopts)
defer lookupd1.Exit()
_, _, lookupd2 := mustStartNSQLookupd(lopts)
defer lookupd2.Exit()
_, _, lookupd3 := mustStartNSQLookupd(lopts)
defer lookupd3.Exit()
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
_, _, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
time.Sleep(50 * time.Millisecond)
newOpts := *opts
newOpts.NSQLookupdTCPAddresses = []string{lookupd1.RealTCPAddr().String()}
nsqd.swapOpts(&newOpts)
nsqd.triggerOptsNotification()
test.Equal(t, 1, len(nsqd.getOpts().NSQLookupdTCPAddresses))
time.Sleep(50 * time.Millisecond)
numLookupPeers := len(nsqd.lookupPeers.Load().([]*lookupPeer))
test.Equal(t, 1, numLookupPeers)
newOpts = *opts
newOpts.NSQLookupdTCPAddresses = []string{lookupd2.RealTCPAddr().String(), lookupd3.RealTCPAddr().String()}
nsqd.swapOpts(&newOpts)
nsqd.triggerOptsNotification()
test.Equal(t, 2, len(nsqd.getOpts().NSQLookupdTCPAddresses))
time.Sleep(50 * time.Millisecond)
var lookupPeers []string
for _, lp := range nsqd.lookupPeers.Load().([]*lookupPeer) {
lookupPeers = append(lookupPeers, lp.addr)
}
test.Equal(t, 2, len(lookupPeers))
test.Equal(t, newOpts.NSQLookupdTCPAddresses, lookupPeers)
}
示例15: TestClientAttributes
func TestClientAttributes(t *testing.T) {
userAgent := "Test User Agent"
opts := NewOptions()
opts.Logger = test.NewTestLogger(t)
opts.Verbose = true
opts.SnappyEnabled = true
tcpAddr, httpAddr, nsqd := mustStartNSQD(opts)
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()
conn, err := mustConnectNSQD(tcpAddr)
test.Nil(t, err)
defer conn.Close()
data := identify(t, conn, map[string]interface{}{
"snappy": true,
"user_agent": userAgent,
}, frameTypeResponse)
resp := struct {
Snappy bool `json:"snappy"`
UserAgent string `json:"user_agent"`
}{}
err = json.Unmarshal(data, &resp)
test.Nil(t, err)
test.Equal(t, true, resp.Snappy)
r := snappystream.NewReader(conn, snappystream.SkipVerifyChecksum)
w := snappystream.NewWriter(conn)
readValidate(t, r, frameTypeResponse, "OK")
topicName := "test_client_attributes" + strconv.Itoa(int(time.Now().Unix()))
sub(t, readWriter{r, w}, topicName, "ch")
var d struct {
Topics []struct {
Channels []struct {
Clients []struct {
UserAgent string `json:"user_agent"`
Snappy bool `json:"snappy"`
} `json:"clients"`
} `json:"channels"`
} `json:"topics"`
}
endpoint := fmt.Sprintf("http://127.0.0.1:%d/stats?format=json", httpAddr.Port)
err = http_api.NewClient(nil, ConnectTimeout, RequestTimeout).GETV1(endpoint, &d)
test.Nil(t, err)
test.Equal(t, userAgent, d.Topics[0].Channels[0].Clients[0].UserAgent)
test.Equal(t, true, d.Topics[0].Channels[0].Clients[0].Snappy)
}