File: client_test.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (63 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package mq

import "testing"

// 您在控制台创建的Topic
var Topic = ""

// 公测集群URL
var ENDPOINT = ""

// 阿里云官网身份验证访问码
var Ak = ""

// 阿里云身份验证密钥
var Sk = ""

// MQ控制台创建的Producer ID
var ProducerID = ""

// MQ控制台创建的Consumer ID
var ConsumerID = ""

func TestNewClient(t *testing.T) {
	client := NewClient(Ak, Sk, ENDPOINT, Topic, ProducerID, ConsumerID, "http", "http")
	msgId, err := client.Send(GetCurrentUnixMicro(), []byte("hello world"))
	if err != nil {
		t.Error(err)
	} else {
		t.Logf("The message id successfully send is %v", msgId)
	}
}

func TestReceiveClient(t *testing.T) {

	// time.Sleep(100 * time.Second)
	client := NewClient(Ak, Sk, ENDPOINT, Topic, ProducerID, ConsumerID, "http", "http")
	respChan := make(chan string)
	errChan := make(chan error)
	end := make(chan int)
	message := ""
	go func() {
		select {
		case resp := <-respChan:
			{
				t.Logf("message: %s", resp)
				message = resp
				end <- 1
			}
		case err := <-errChan:
			{
				t.Logf("err: %v", err)
				end <- 1
			}
		}
	}()

	client.ReceiveMessage(respChan, errChan)
	<-end

	if message != "hello world" {
		t.Errorf("message: %s", message)
	}
}