Adding test_case for volunteers. (#31) * Adding docs/test_case.md and gofmt * Update: docs/test_case.md
diff --git a/core/api.go b/core/api.go index 8a6fdd3..694383a 100644 --- a/core/api.go +++ b/core/api.go
@@ -18,8 +18,10 @@ import "fmt" +const GoClientVersion = "Go Client V1.2.0, Support CPP Core:V1.2.X" + func Version() (version string) { - return GetVersion() + return GoClientVersion } type ClientConfig struct {
diff --git a/core/api_test.go b/core/api_test.go index 01f360b..603ce7a 100644 --- a/core/api_test.go +++ b/core/api_test.go
@@ -75,3 +75,14 @@ " MessageBatchMaxSize: 32, MessageModel: Clustering, ]" assert.Equal(t, expect, pcConfig.String()) } + +func TestMessageModel_String(t *testing.T) { + m := BroadCasting + assert.Equal(t, "BroadCasting", m.String()) + + m = Clustering + assert.Equal(t, "Clustering", m.String()) + + m = 3 + assert.Equal(t, "Unknown", m.String()) +}
diff --git a/core/producer.go b/core/producer.go index fe2d978..7df57e6 100644 --- a/core/producer.go +++ b/core/producer.go
@@ -235,12 +235,12 @@ unsafe.Pointer(&key), C.int(autoRetryTimes), &sr)) - + if err != NIL { log.Warnf("send message orderly error, error is: %s", err.Error()) return nil, err } - + return &SendResult{ Status: SendStatus(sr.sendStatus), MsgId: C.GoString(&sr.msgId[0]), @@ -257,7 +257,7 @@ log.Warnf("send message with oneway error, error is: %s", err.Error()) return err } - + log.Debugf("Send Message: %s with oneway success.", msg.String()) return nil }
diff --git a/core/producer_test.go b/core/producer_test.go index 04c007b..b70cee7 100644 --- a/core/producer_test.go +++ b/core/producer_test.go
@@ -16,28 +16,3 @@ */ package rocketmq -//func TestCreateMessage(test *testing.T){ -// fmt.Println("-----TestCreateMessage Start----") -// rocketmq.CreateMessage("testTopic") -// fmt.Println("-----TestCreateMessage Finish----") -//} -// -//func TestDestroyMessage(test *testing.T){ -// fmt.Println("-----TestCreateMessage Start----") -// msg := rocketmq.CreateMessage("testTopic") -// rocketmq.DestroyMessage(msg) -// fmt.Println("-----TestCreateMessage Finish----") -//} -//func TestSetMessageKeys(test *testing.T){ -// fmt.Println("-----TestSetMessageKeys Start----") -// msg := rocketmq.CreateMessage("testTopic") -// len := rocketmq.SetMessageKeys(msg,"testKey") -// fmt.Println("Len:",len) -// rocketmq.DestroyMessage(msg) -// fmt.Println("-----TestCreateMessage Finish----") -//} -//func TestCreateProducer(test *testing.T){ -// fmt.Println("-----TestCreateProducer Start----") -// rocketmq.CreateProducer("testGroupId") -// fmt.Println("-----TestCreateProducer Finish----") -//}
diff --git a/core/push_consumer.go b/core/push_consumer.go index 90e1454..c222587 100644 --- a/core/push_consumer.go +++ b/core/push_consumer.go
@@ -32,11 +32,11 @@ import "C" import ( + "errors" "fmt" log "github.com/sirupsen/logrus" "sync" "unsafe" - "errors" ) type ConsumeStatus int
diff --git a/core/push_consumer_test.go b/core/push_consumer_test.go index 22c1444..4c806b8 100644 --- a/core/push_consumer_test.go +++ b/core/push_consumer_test.go
@@ -14,15 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package rocketmq - -//import "fmt" -//import "testing" -//import "../client" -// -//func TestCreatePushConsumer(test *testing.T){ -// fmt.Println("-----TestCreateProducer Start----") -// consumer := rocketmq.CreatePushConsumer("testGroupId") -// rocketmq.DestroyPushConsumer(consumer) -// fmt.Println("-----TestCreateProducer Finish----") -//} +package rocketmq \ No newline at end of file
diff --git a/core/queue.go b/core/queue.go deleted file mode 100644 index 47f10ef..0000000 --- a/core/queue.go +++ /dev/null
@@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package rocketmq - -import "fmt" - -// MessageQueue the queue of the message -type MessageQueue struct { - Topic string - Broker string - ID int -} - -func (q *MessageQueue) String() string { - return fmt.Sprintf("broker:%s, topic:%s, id:%d", q.Broker, q.Topic, q.ID) -}
diff --git a/core/queue_selector.go b/core/queue_selector.go index 7bf1927..45631b3 100644 --- a/core/queue_selector.go +++ b/core/queue_selector.go
@@ -18,11 +18,23 @@ import "C" import ( + "fmt" "strconv" "sync" "unsafe" ) +// MessageQueue the queue of the message +type MessageQueue struct { + Topic string + Broker string + ID int +} + +func (q *MessageQueue) String() string { + return fmt.Sprintf("broker:%s, topic:%s, id:%d", q.Broker, q.Topic, q.ID) +} + var selectors = selectorHolder{selectors: map[int]*messageQueueSelectorWrapper{}} //export queueSelectorCallback
diff --git a/core/version.go b/core/version.go deleted file mode 100644 index 95ff0f3..0000000 --- a/core/version.go +++ /dev/null
@@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rocketmq - -const GoClientVersion = "Go Client V1.2.0, Support CPP Core:V1.2.X" - -func GetVersion() (version string) { - return GoClientVersion -}
diff --git a/core/version_test.go b/core/version_test.go deleted file mode 100644 index 85f43c1..0000000 --- a/core/version_test.go +++ /dev/null
@@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rocketmq - -//import ( -// "fmt" -// "testing" -// "../client" -//) -// -//func TestGetVersion(test *testing.T){ -// fmt.Println("-----TestGetVersion Start----") -// version := rocketmq.GetVersion(); -// fmt.Println(version) -// fmt.Println("-----TestGetVersion Finish----") -//}
diff --git a/doc/Introduction.md b/docs/Introduction.md similarity index 100% rename from doc/Introduction.md rename to docs/Introduction.md
diff --git a/docs/test_case.md b/docs/test_case.md new file mode 100644 index 0000000..5c176c1 --- /dev/null +++ b/docs/test_case.md
@@ -0,0 +1,77 @@ +# Apache RocketMQ Golang Client Test Case List + +## Unit Test +**TODO: How to mock cgo API** + +### core package +#### api.go +- [ ] `func (config *ClientConfig) String() string` +- [x] `func (config *ProducerConfig) String() string` +- [x] `func (mode MessageModel) String() string` +- [x] `func (config *PushConsumerConfig) String() string` +- [ ] `func (config *PullConsumerConfig) String() string` +- [ ] `func (session *SessionCredentials) String() string` +- [ ] `func (result *SendResult) String() string` + +#### cfuns.go +- [ ] `func consumeMessageCallback(cconsumer *C.CPushConsumer, msg *C.CMessageExt) C.int ` + +#### error.go +- [ ] `func (e rmqError) Error() string` + +#### log.go +- [x] `func (l LogLevel) String() string ` +- [x] `func (lc *LogConfig) String() string ` + +#### message.go +- [ ] `func (msg *Message) String() string` +- [ ] `func goMsgToC(gomsg *Message) *C.struct_CMessage ` +- [ ] `func (msgExt *MessageExt) String() string` +- [ ] `func (msgExt *MessageExt) GetProperty(key string) string ` +- [ ] `func cmsgExtToGo(cmsg *C.struct_CMessageExt) *MessageExt ` + +#### producer.go +- [ ] `func (status SendStatus) String() string ` +- [ ] `func newDefaultProducer(config *ProducerConfig) (*defaultProducer, error)` +- [ ] `func (p *defaultProducer) String() string ` +- [ ] `func (p *defaultProducer) Start() error ` +- [ ] `func (p *defaultProducer) Shutdown() error ` +- [ ] `func (p *defaultProducer) SendMessageSync(msg *Message) (*SendResult, error)` +- [ ] `func (p *defaultProducer) SendMessageOrderly(msg *Message, selector MessageQueueSelector, arg interface{}, autoRetryTimes int) (*SendResult, error) ` +- [ ] `func (p *defaultProducer) SendMessageOneway(msg *Message) error ` + +#### pull_consumer.go +- [ ] `func (ps PullStatus) String() string ` +- [ ] `func (c *defaultPullConsumer) String() string ` +- [ ] `func NewPullConsumer(config *PullConsumerConfig) (PullConsumer, error) ` +- [ ] `func (c *defaultPullConsumer) Start() error ` +- [ ] `func (c *defaultPullConsumer) Shutdown() error ` +- [ ] `func (c *defaultPullConsumer) FetchSubscriptionMessageQueues(topic string) []MessageQueue ` +- [ ] `func (pr *PullResult) String() string ` +- [ ] `func (c *defaultPullConsumer) Pull(mq MessageQueue, subExpression string, offset int64, maxNums int) PullResult ` + +#### push_consumer.go +- [ ] `func (status ConsumeStatus) String() string ` +- [ ] `func (c *defaultPushConsumer) String() string ` +- [ ] `func newPushConsumer(config *PushConsumerConfig) (PushConsumer, error) ` +- [ ] `func (c *defaultPushConsumer) Start() error ` +- [ ] `func (c *defaultPushConsumer) Shutdown() error ` +- [ ] `func (c *defaultPushConsumer) Subscribe(topic, expression string, consumeFunc func(msg *MessageExt) ConsumeStatus) error ` + +#### queue_selector.go +- [ ] `func (q *MessageQueue) String() string ` +- [ ] `func queueSelectorCallback(size int, selectorKey unsafe.Pointer) int ` +- [x] `func (w *messageQueueSelectorWrapper) Select(size int) int` +- [x] `func (s *selectorHolder) put(selector *messageQueueSelectorWrapper) (key int) ` +- [x] `func (s *selectorHolder) getAndDelete(key int) (*messageQueueSelectorWrapper, bool) ` + +## Integration Test +### Producer +- send message with `DelayTimeLevel` +- send message with `tag` +- send message orderly with `tag` + +### Consumer +- consume message delayed through push/pull +- subscribe topic with expression +- pull message with expression \ No newline at end of file