Exemple #1
0
// Test client to send a sample payload of data endlessly
// By default it points locally, but it can point to any network address
// TODO Make that externally configurable to make automating the test easier
func main() {
	cfg := buffstreams.BuffManagerConfig{
		MaxMessageSize: 2048,
		EnableLogging:  true,
	}
	name := "Stabby"
	date := time.Now().UnixNano()
	data := "This is an intenntionally long and rambling sentence to pad out the size of the message."
	msg := &message.Note{Name: &name, Date: &date, Comment: &data}
	msgBytes, err := proto.Marshal(msg)
	if err != nil {
		log.Print(err)
	}
	count := 0
	bm := buffstreams.New(cfg)
	currentTime := time.Now()
	lastTime := currentTime
	address := buffstreams.FormatAddress("127.0.0.1", strconv.Itoa(5031))
	for {
		_, err := bm.WriteTo(address, msgBytes, true)
		if err != nil {
			log.Print("EEEEEERRRRROOOOOOOORRRRRRRRRRR")
			log.Print(err)
		}
		count = count + 1
		if lastTime.Second() != currentTime.Second() {
			lastTime = currentTime
			log.Printf(", %d", count)
			count = 0
		}
		currentTime = time.Now()
	}
}
Exemple #2
0
// This is not a proper test, but it lets me benchmark how it
// performs on a raw level. Run this with the time command
func main() {
	cfg := buffstreams.BuffManagerConfig{
		MaxMessageSize: 256,
	}
	// 100 byte message
	msg := []byte("HeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyHeyheyheyH!")
	startingPort := 5031
	for i := 0; i < 10; i++ {
		go func(n int, port string) {
			bm := buffstreams.New(cfg)
			bm.StartListening(strconv.Itoa(startingPort), TestCallback)
			address := buffstreams.FormatAddress("127.0.0.1", strconv.Itoa(startingPort))
			count := 0
			for {
				_, err := bm.WriteTo(address, msg, true)
				if err != nil {
					log.Print("EEEEEERRRRROOOOOOOORRRRRRRRRRR")
					log.Print(err)
				}
				count = count + 1
				log.Printf("%d - %d", n, count)
			}
		}(i, strconv.Itoa(startingPort))
		startingPort = startingPort + 1
	}
	time.Sleep(time.Minute * 10)
}
// Test client to send a sample payload of data endlessly
// By default it points locally, but it can point to any network address
// TODO Make that externally configurable to make automating the test easier
func main() {
	cfg := &buffstreams.TCPConnConfig{
		MaxMessageSize: 2048,
		Address:        buffstreams.FormatAddress("127.0.0.1", strconv.Itoa(5031)),
	}
	name := "Stabby"
	date := time.Now().UnixNano()
	data := "This is an intenntionally long and rambling sentence to pad out the size of the message."
	msg := &message.Note{Name: &name, Date: &date, Comment: &data}
	msgBytes, err := proto.Marshal(msg)
	if err != nil {
		log.Print(err)
	}
	count := 0
	btw, err := buffstreams.DialTCP(cfg)
	if err != nil {
		log.Fatal(err)
	}
	currentTime := time.Now()
	lastTime := currentTime
	for {
		_, err := btw.Write(msgBytes)
		if err != nil {
			log.Print("There was an error")
			log.Print(err)
		}
		count = count + 1
		if lastTime.Second() != currentTime.Second() {
			lastTime = currentTime
			log.Printf(", %d", count)
			count = 0
		}
		currentTime = time.Now()
	}
}
func main() {
	cfg := buffstreams.BuffTCPListenerConfig{
		MaxMessageSize: 2048,
		EnableLogging:  true,
		Address:        buffstreams.FormatAddress("", strconv.Itoa(5031)),
		Callback:       TestCallback,
	}

	btl, err := buffstreams.ListenBuffTCP(cfg)
	if err != nil {
		log.Print(err)
	}
	if err := btl.StartListening(); err != nil {
		log.Print(err)
	} else {
		// Need to block until ctrl+c, but having trouble getting signal trapping to work on OSX...
		time.Sleep(time.Minute * 10)
	}
}
Exemple #5
0
// This is not a proper test, but it lets me benchmark how it
// performs on a raw level. Run this with the time command
func main() {
	cfg := buffstreams.BuffManagerConfig{
		MaxMessageSize: 256,
		EnableLogging:  true,
	}
	// 100 byte message
	name := "Stabby"
	date := time.Now().UnixNano()
	data := "This is an intenntionally long and rambling sentence to pad out the size of the message."
	msg := &message.Note{Name: &name, Date: &date, Comment: &data}
	msgBytes, err := proto.Marshal(msg)
	if err != nil {
		log.Print(err)
	}
	startingPort := 5031
	bm := buffstreams.New(cfg)
	bm.StartListening(strconv.Itoa(startingPort), TestCallback)

	for i := 0; i < 10; i++ {
		go func(n int, port string, bm *buffstreams.BuffManager) {
			address := buffstreams.FormatAddress("127.0.0.1", port)
			count := 0
			for {
				_, err := bm.WriteTo(address, msgBytes, true)
				//log.Printf("Wrote %d Bytes of %d + 2, error was: %s", written, len(msgBytes), err)
				if err != nil {
					log.Printf("Error %s", err)
				}
				count = count + 1
				log.Printf("%d - %d", n, count)
			}
		}(i, strconv.Itoa(startingPort), bm)
		//startingPort = startingPort + 1
	}
	time.Sleep(time.Minute * 10)
}