Skip to content

Commit

Permalink
Stable test (apache#20)
Browse files Browse the repository at this point in the history
Add a stable test;
Add license in the benchmark file.
  • Loading branch information
zjykzk authored and ShannonDing committed Dec 28, 2018
1 parent 8789b8c commit 67d8bf9
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 15 deletions.
17 changes: 17 additions & 0 deletions benchmark/consumer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 main

import (
Expand Down
27 changes: 18 additions & 9 deletions benchmark/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
/*
* 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 main

import (
"fmt"
"os"
"strings"
)

type command interface {
Expand All @@ -12,16 +28,9 @@ type command interface {
}

var (
cmds = map[string]command{}
longText = ""
longTextLen = 0
cmds = map[string]command{}
)

func init() {
longText = strings.Repeat("0123456789", 100)
longTextLen = len(longText)
}

func registerCommand(name string, cmd command) {
if cmd == nil {
panic("empty command")
Expand Down
34 changes: 34 additions & 0 deletions benchmark/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 main

import "strings"

var (
longText = ""
longTextLen = 0
)

func init() {
longText = strings.Repeat("0123456789", 100)
longTextLen = len(longText)
}

func buildMsg(size int) string {
return longText[:size]
}
30 changes: 24 additions & 6 deletions benchmark/producer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 main

import (
Expand Down Expand Up @@ -126,10 +143,15 @@ AGAIN:
}

now := time.Now()
r := p.SendMessageSync(&rocketmq.Message{
Topic: bp.topic, Body: longText[:bp.bodySize],
r, err := p.SendMessageSync(&rocketmq.Message{
Topic: bp.topic, Body: buildMsg(bp.bodySize),
})

if err != nil {
fmt.Printf("send message sync error:%s", err)
goto AGAIN
}

if r.Status == rocketmq.SendOK {
atomic.AddInt64(&stati.receiveResponseSuccessCount, 1)
atomic.AddInt64(&stati.sendRequestSuccessCount, 1)
Expand Down Expand Up @@ -249,7 +271,3 @@ func (bp *producer) run(args []string) {
func (bp *producer) usage() {
bp.flags.Usage()
}

func (bp *producer) buildMsg() string {
return longText[:bp.bodySize]
}
Loading

0 comments on commit 67d8bf9

Please sign in to comment.