-
Notifications
You must be signed in to change notification settings - Fork 891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GODRIVER-2617 Remove deprecated code #1398
Changes from 16 commits
1b99cfd
2265cff
b07ff6e
0a66171
be47df2
5202542
f35a93a
cfd0ffc
fe99af6
d1cc8c2
53a3fbe
f7daae8
3ce688d
d7c9ff7
23df976
26f0a2f
29b292e
eb224b5
19243b7
cb7a81b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1763,7 +1763,7 @@ func UpdateEmployeeInfo(ctx context.Context, client *mongo.Client) error { | |
return client.UseSession(ctx, func(sctx mongo.SessionContext) error { | ||
err := sctx.StartTransaction(options.Transaction(). | ||
SetReadConcern(readconcern.Snapshot()). | ||
SetWriteConcern(writeconcern.New(writeconcern.WMajority())), | ||
SetWriteConcern(writeconcern.Majority()), | ||
) | ||
if err != nil { | ||
return err | ||
|
@@ -1921,7 +1921,7 @@ func TransactionsExamples(ctx context.Context, client *mongo.Client) error { | |
|
||
err := sctx.StartTransaction(options.Transaction(). | ||
SetReadConcern(readconcern.Snapshot()). | ||
SetWriteConcern(writeconcern.New(writeconcern.WMajority())), | ||
SetWriteConcern(writeconcern.Majority()), | ||
) | ||
if err != nil { | ||
return err | ||
|
@@ -1971,7 +1971,10 @@ func WithTransactionExample(ctx context.Context) error { | |
defer func() { _ = client.Disconnect(ctx) }() | ||
|
||
// Prereq: Create collections. | ||
wcMajority := writeconcern.New(writeconcern.WMajority(), writeconcern.WTimeout(1*time.Second)) | ||
wcMajority := &writeconcern.WriteConcern{ | ||
W: "majority", | ||
WTimeout: 1 * time.Second, | ||
} | ||
wcMajorityCollectionOpts := options.Collection().SetWriteConcern(wcMajority) | ||
fooColl := client.Database("mydb1").Collection("foo", wcMajorityCollectionOpts) | ||
barColl := client.Database("mydb1").Collection("bar", wcMajorityCollectionOpts) | ||
|
@@ -2552,7 +2555,11 @@ func CausalConsistencyExamples(client *mongo.Client) error { | |
|
||
// Use a causally-consistent session to run some operations | ||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority()).SetDefaultWriteConcern( | ||
writeconcern.New(writeconcern.WMajority(), writeconcern.WTimeout(1000))) | ||
&writeconcern.WriteConcern{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the convenience function in the example, instead of using the "majority" magic string? wcMajority := writeconcern.Majority()
wcMajority.WTimeout = 1000 |
||
W: "majority", | ||
WTimeout: 1000, | ||
}, | ||
) | ||
session1, err := client.StartSession(opts) | ||
if err != nil { | ||
return err | ||
|
@@ -2585,8 +2592,12 @@ func CausalConsistencyExamples(client *mongo.Client) error { | |
|
||
// Make a new session that is causally consistent with session1 so session2 reads what session1 writes | ||
opts = options.Session().SetDefaultReadPreference(readpref.Secondary()).SetDefaultReadConcern( | ||
readconcern.Majority()).SetDefaultWriteConcern(writeconcern.New(writeconcern.WMajority(), | ||
writeconcern.WTimeout(1000))) | ||
readconcern.Majority()).SetDefaultWriteConcern( | ||
&writeconcern.WriteConcern{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the convenience function in the example, instead of using the "majority" magic string? wcMajority := writeconcern.Majority()
wcMajority.WTimeout = 1000 |
||
W: "majority", | ||
WTimeout: 1000, | ||
}, | ||
) | ||
session2, err := client.StartSession(opts) | ||
if err != nil { | ||
return err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"testing" | ||
|
||
"go.mongodb.org/mongo-driver/internal/assert" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func TestChangeStream(t *testing.T) { | ||
|
@@ -27,3 +28,60 @@ func TestChangeStream(t *testing.T) { | |
assert.Nil(t, err, "Close error: %v", err) | ||
}) | ||
} | ||
|
||
func TestMergeChangeStreamOptions(t *testing.T) { | ||
t.Parallel() | ||
|
||
fullDocumentP := func(x options.FullDocument) *options.FullDocument { return &x } | ||
int32P := func(x int32) *int32 { return &x } | ||
|
||
testCases := []struct { | ||
description string | ||
input []*options.ChangeStreamOptions | ||
want *options.ChangeStreamOptions | ||
}{ | ||
{ | ||
description: "empty", | ||
input: []*options.ChangeStreamOptions{}, | ||
want: &options.ChangeStreamOptions{}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we include a |
||
{ | ||
description: "many ChangeStreamOptions with one configuration each", | ||
input: []*options.ChangeStreamOptions{ | ||
options.ChangeStream().SetFullDocumentBeforeChange(options.Required), | ||
options.ChangeStream().SetFullDocument(options.Required), | ||
options.ChangeStream().SetBatchSize(10), | ||
}, | ||
want: &options.ChangeStreamOptions{ | ||
FullDocument: fullDocumentP(options.Required), | ||
FullDocumentBeforeChange: fullDocumentP(options.Required), | ||
BatchSize: int32P(10), | ||
}, | ||
}, | ||
{ | ||
description: "single ChangeStreamOptions with many configurations", | ||
input: []*options.ChangeStreamOptions{ | ||
options.ChangeStream(). | ||
SetFullDocumentBeforeChange(options.Required). | ||
SetFullDocument(options.Required). | ||
SetBatchSize(10), | ||
}, | ||
want: &options.ChangeStreamOptions{ | ||
FullDocument: fullDocumentP(options.Required), | ||
FullDocumentBeforeChange: fullDocumentP(options.Required), | ||
BatchSize: int32P(10), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc // Capture range variable. | ||
|
||
t.Run(tc.description, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got := mergeChangeStreamOptions(tc.input...) | ||
assert.Equal(t, tc.want, got, "expected and actual ChangeStreamOptions are different") | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the convenience function in the example, instead of using the "majority" magic string?