forked from gammazero/nexus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test code to exercise dropped events
- Loading branch information
Neil Edgar
committed
Sep 30, 2019
1 parent
2b9db9a
commit 5ddd0ec
Showing
3 changed files
with
113 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"sync" | ||
"sync/atomic" | ||
|
||
"github.com/gammazero/nexus/examples/newclient" | ||
"github.com/gammazero/nexus/wamp" | ||
) | ||
|
||
const exampleTopic = "example.hello" | ||
const exampleCountTopic = "example.eventCount" | ||
|
||
func main() { | ||
logger := log.New(os.Stdout, "PUBLISHER> ", 0) | ||
// Connect publisher client with requested socket type and serialization. | ||
publisher, err := newclient.NewClient(logger) | ||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
defer publisher.Close() | ||
|
||
// Publish to topic. | ||
args := wamp.List{"hello world"} | ||
err = publisher.Publish(exampleTopic, nil, args, nil) | ||
if err != nil { | ||
logger.Fatalf("publish error: %s", err) | ||
} | ||
newclient.ParseArgs() | ||
|
||
// Publish more events to topic. | ||
args = wamp.List{"how are you today"} | ||
err = publisher.Publish(exampleTopic, nil, args, nil) | ||
if err != nil { | ||
logger.Fatalf("publish error: %s", err) | ||
} | ||
max := 20 | ||
msgCount := 20 | ||
fmt.Printf("PUBLISHER %d clients\n", max) | ||
|
||
// Publish events only to sessions 42, 1138, 1701. | ||
args = wamp.List{"for your eyes only"} | ||
opts := wamp.Dict{wamp.WhitelistKey: wamp.List{42, 1138, 1701}} | ||
err = publisher.Publish(exampleTopic, opts, args, nil) | ||
if err != nil { | ||
logger.Fatalf("publish error: %s", err) | ||
} | ||
wg := sync.WaitGroup{} | ||
wg.Add(max) | ||
|
||
args = wamp.List{"testing 1"} | ||
err = publisher.Publish(exampleTopic, nil, args, nil) | ||
if err != nil { | ||
logger.Fatalf("publish error: %s", err) | ||
} | ||
var success uint64 | ||
var failure uint64 | ||
|
||
args = wamp.List{"testing 2"} | ||
err = publisher.Publish(exampleTopic, nil, args, nil) | ||
if err != nil { | ||
logger.Fatalf("publish error: %s", err) | ||
} | ||
for ii := 1; ii <= max; ii++ { | ||
go func(loop int) { | ||
|
||
logger := log.New(os.Stdout, fmt.Sprintf("PUBLISHER %d > ", loop), 0) | ||
// Connect publisher client with requested socket type and serialization. | ||
publisher, err := newclient.MyNewClient(logger) | ||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
defer publisher.Close() | ||
|
||
// Publish to topic. | ||
for jj := 1; jj <= msgCount; jj++ { | ||
args := wamp.List{ fmt.Sprintf("%d:%d", loop, jj, ) } | ||
err = publisher.Publish(exampleCountTopic, nil, args, nil) | ||
if err != nil { | ||
logger.Printf("message %d error: %s\n", jj, err) | ||
atomic.AddUint64(&failure, 1) | ||
} else { | ||
//logger.Printf("message %d: success\n", jj) | ||
atomic.AddUint64(&success, 1) | ||
} | ||
} | ||
|
||
args = wamp.List{"testing 3"} | ||
err = publisher.Publish(exampleTopic, nil, args, nil) | ||
if err != nil { | ||
logger.Fatalf("publish error: %s", err) | ||
logger.Printf("Sent %d messages to %s\n", msgCount, exampleCountTopic) | ||
wg.Done() | ||
|
||
}(ii) | ||
} | ||
|
||
logger.Println("Published messages to", exampleTopic) | ||
publisher.Close() | ||
fmt.Printf("Waiting PUBLISHER %d clients\n", max) | ||
wg.Wait() | ||
fmt.Printf("Done PUBLISHER %d clients %d success %d failure\n", max, success, failure) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters