-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Olivier Poitrey
committed
Aug 27, 2015
1 parent
3e62f95
commit 09d7c61
Showing
2 changed files
with
71 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package oplog_test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/dailymotion/oplog" | ||
) | ||
|
||
func ExampleOpLog_Append() { | ||
ol, err := oplog.New("mongodb://localhost/oplog", 1048576) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
op := oplog.NewOperation("insert", time.Now(), "123", "user", nil) | ||
ol.Append(op) | ||
} | ||
|
||
func ExampleOpLog_Ingest() { | ||
ol, err := oplog.New("mongodb://localhost/oplog", 1048576) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
ops := make(chan *oplog.Operation) | ||
done := make(chan bool, 1) | ||
go ol.Ingest(ops, nil) | ||
// Insert a large number of operations | ||
for i := 0; i < 1000; i++ { | ||
ops <- oplog.NewOperation("insert", time.Now(), strconv.FormatInt(int64(i), 10), "user", nil) | ||
} | ||
done <- true | ||
} | ||
|
||
func ExampleOpLog_Tail() { | ||
ol, err := oplog.New("mongodb://localhost/oplog", 1048576) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
ops := make(chan oplog.GenericEvent) | ||
stop := make(chan bool) | ||
// Tail all future events with no filters | ||
go ol.Tail(nil, oplog.Filter{}, ops, stop) | ||
// Read 100 events | ||
for i := 0; i < 100; i++ { | ||
op := <-ops | ||
op.WriteTo(os.Stdout) | ||
} | ||
// Stop the tail | ||
stop <- true | ||
} |