Skip to content

Commit 2e90dce

Browse files
committed
Remove legacy network library code
GODRIVER-994 Change-Id: I2fff2161d4d8958ad2dc6d1228c4e3db96d635a1
1 parent f45a522 commit 2e90dce

File tree

164 files changed

+872
-16392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+872
-16392
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ doc:
2626

2727
.PHONY: build-examples
2828
build-examples:
29-
go build $(BUILD_TAGS) ./examples/... ./x/network/examples/...
29+
go build $(BUILD_TAGS) ./examples/... ./x/mongo/driver/examples/...
3030

3131
.PHONY: build
3232
build:
@@ -113,7 +113,7 @@ evg-test:
113113

114114
.PHONY: evg-test-auth
115115
evg-test-auth:
116-
go run -tags gssapi ./x/network/examples/count/main.go -uri $(MONGODB_URI)
116+
go run -tags gssapi ./x/mongo/driver/examples/count/main.go -uri $(MONGODB_URI)
117117

118118
# benchmark specific targets and support
119119
perf:driver-test-data.tar.gz

etc/check_env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ if [ ! -z $AUTH ] && [[ ! $AUTH =~ ^(noauth|auth)$ ]]; then
1010
exit 1
1111
fi
1212

13-
if [ ! -z $SSL ] && [[ ! $SLL =~ ^(nossl|ssl)$ ]]; then
13+
if [ ! -z $SSL ] && [[ ! $SSL =~ ^(nossl|ssl)$ ]]; then
1414
>&2 echo "Invalid value of SSL. SSL can optionally be set to one of: nossl, ssl"
1515
exit 1
1616
fi
1717

1818
if [ ! -z $MONGO_GO_DRIVER_COMPRESSOR ] && [[ ! $MONGO_GO_DRIVER_COMPRESSOR =~ ^(snappy|zlib)$ ]]; then
1919
>&2 echo "Invalid value of MONGO_GO_DRIVER_COMPRESSOR. MONGO_GO_DRIVER_COMPRESSOR can optionally be set to one of: snappy, zlib"
2020
exit 1
21-
fi
21+
fi

internal/channel_connection.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

internal/testutil/config.go

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919

2020
"github.com/stretchr/testify/require"
2121
"go.mongodb.org/mongo-driver/event"
22-
"go.mongodb.org/mongo-driver/x/bsonx"
22+
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
2323
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
2424
"go.mongodb.org/mongo-driver/x/mongo/driver/description"
25+
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
2526
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
26-
"go.mongodb.org/mongo-driver/x/network/command"
2727
)
2828

2929
var connectionString connstring.ConnString
@@ -102,16 +102,9 @@ func MonitoredTopology(t *testing.T, dbName string, monitor *event.CommandMonito
102102
t.Fatal(err)
103103
} else {
104104
monitoredTopology.Connect()
105-
s, err := monitoredTopology.SelectServerLegacy(context.Background(), description.WriteSelector())
106-
require.NoError(t, err)
107-
108-
c, err := s.ConnectionLegacy(context.Background())
109-
require.NoError(t, err)
110105

111-
_, err = (&command.Write{
112-
DB: dbName,
113-
Command: bsonx.Doc{{"dropDatabase", bsonx.Int32(1)}},
114-
}).RoundTrip(context.Background(), s.SelectedDescription(), c)
106+
err = operation.NewCommand(bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "dropDatabase", 1))).
107+
Database(dbName).ServerSelector(description.WriteSelector()).Deployment(monitoredTopology).Execute(context.Background())
115108

116109
require.NoError(t, err)
117110
}
@@ -146,16 +139,9 @@ func GlobalMonitoredTopology(t *testing.T, monitor *event.CommandMonitor) *topol
146139
monitoredTopologyErr = err
147140
} else {
148141
monitoredTopology.Connect()
149-
s, err := monitoredTopology.SelectServerLegacy(context.Background(), description.WriteSelector())
150-
require.NoError(t, err)
151142

152-
c, err := s.ConnectionLegacy(context.Background())
153-
require.NoError(t, err)
154-
155-
_, err = (&command.Write{
156-
DB: DBName(t),
157-
Command: bsonx.Doc{{"dropDatabase", bsonx.Int32(1)}},
158-
}).RoundTrip(context.Background(), s.SelectedDescription(), c)
143+
err = operation.NewCommand(bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "dropDatabase", 1))).
144+
Database(DBName(t)).ServerSelector(description.WriteSelector()).Deployment(monitoredTopology).Execute(context.Background())
159145

160146
require.NoError(t, err)
161147
}
@@ -178,16 +164,9 @@ func Topology(t *testing.T) *topology.Topology {
178164
liveTopologyErr = err
179165
} else {
180166
liveTopology.Connect()
181-
s, err := liveTopology.SelectServerLegacy(context.Background(), description.WriteSelector())
182-
require.NoError(t, err)
183-
184-
c, err := s.ConnectionLegacy(context.Background())
185-
require.NoError(t, err)
186167

187-
_, err = (&command.Write{
188-
DB: DBName(t),
189-
Command: bsonx.Doc{{"dropDatabase", bsonx.Int32(1)}},
190-
}).RoundTrip(context.Background(), s.SelectedDescription(), c)
168+
err = operation.NewCommand(bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "dropDatabase", 1))).
169+
Database(DBName(t)).ServerSelector(description.WriteSelector()).Deployment(liveTopology).Execute(context.Background())
191170
require.NoError(t, err)
192171
}
193172
})

internal/testutil/ops.go

Lines changed: 42 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,28 @@ import (
1212
"testing"
1313

1414
"github.com/stretchr/testify/require"
15-
"go.mongodb.org/mongo-driver/bson"
16-
"go.mongodb.org/mongo-driver/internal/testutil/helpers"
1715
"go.mongodb.org/mongo-driver/mongo/writeconcern"
18-
"go.mongodb.org/mongo-driver/x/bsonx"
16+
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
17+
"go.mongodb.org/mongo-driver/x/mongo/driver"
1918
"go.mongodb.org/mongo-driver/x/mongo/driver/description"
20-
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
19+
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
2120
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
22-
"go.mongodb.org/mongo-driver/x/mongo/driver/uuid"
23-
"go.mongodb.org/mongo-driver/x/mongo/driverlegacy"
24-
"go.mongodb.org/mongo-driver/x/network/command"
2521
)
2622

2723
// AutoCreateIndexes creates an index in the test cluster.
2824
func AutoCreateIndexes(t *testing.T, keys []string) {
29-
indexes := bsonx.Doc{}
25+
var elems [][]byte
3026
for _, k := range keys {
31-
indexes = append(indexes, bsonx.Elem{k, bsonx.Int32(1)})
27+
elems = append(elems, bsoncore.AppendInt32Element(nil, k, 1))
3228
}
3329
name := strings.Join(keys, "_")
34-
indexes = bsonx.Doc{
35-
{"key", bsonx.Document(indexes)},
36-
{"name", bsonx.String(name)},
37-
}
38-
cmd := command.CreateIndexes{
39-
NS: command.NewNamespace(DBName(t), ColName(t)),
40-
Indexes: bsonx.Arr{bsonx.Document(indexes)},
41-
}
42-
id, _ := uuid.New()
43-
_, err := driverlegacy.CreateIndexes(
44-
context.Background(),
45-
cmd,
46-
Topology(t),
47-
description.WriteSelector(),
48-
id,
49-
&session.Pool{},
30+
indexes := bsoncore.BuildDocumentFromElements(nil,
31+
bsoncore.AppendDocumentElement(nil, "key", bsoncore.BuildDocumentFromElements(nil,
32+
elems...)),
33+
bsoncore.AppendStringElement(nil, "name", name),
5034
)
35+
err := operation.NewCreateIndexes(indexes).Collection(ColName(t)).Database(DBName(t)).
36+
Deployment(Topology(t)).ServerSelector(description.WriteSelector()).Execute(context.Background())
5137
require.NoError(t, err)
5238
}
5339

@@ -58,100 +44,60 @@ func AutoDropCollection(t *testing.T) {
5844

5945
// DropCollection drops the collection in the test cluster.
6046
func DropCollection(t *testing.T, dbname, colname string) {
61-
cmd := command.Write{DB: dbname, Command: bsonx.Doc{{"drop", bsonx.String(colname)}}}
62-
id, _ := uuid.New()
63-
_, err := driverlegacy.Write(
64-
context.Background(),
65-
cmd,
66-
Topology(t),
67-
description.WriteSelector(),
68-
id,
69-
&session.Pool{},
70-
)
71-
if err != nil && !command.IsNotFound(err) {
47+
err := operation.NewCommand(bsoncore.BuildDocument(nil, bsoncore.AppendStringElement(nil, "drop", colname))).
48+
Database(dbname).ServerSelector(description.WriteSelector()).Deployment(Topology(t)).
49+
Execute(context.Background())
50+
if de, ok := err.(driver.Error); err != nil && !(ok && de.NamespaceNotFound()) {
7251
require.NoError(t, err)
7352
}
7453
}
7554

7655
func autoDropDB(t *testing.T, topo *topology.Topology) {
77-
cmd := command.Write{DB: DBName(t), Command: bsonx.Doc{{"dropDatabase", bsonx.Int32(1)}}}
78-
id, _ := uuid.New()
79-
_, err := driverlegacy.Write(
80-
context.Background(),
81-
cmd,
82-
topo,
83-
description.WriteSelector(),
84-
id,
85-
&session.Pool{},
86-
)
56+
err := operation.NewCommand(bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "dropDatabase", 1))).
57+
Database(DBName(t)).ServerSelector(description.WriteSelector()).Deployment(topo).
58+
Execute(context.Background())
8759
require.NoError(t, err)
8860
}
8961

9062
// AutoInsertDocs inserts the docs into the test cluster.
91-
func AutoInsertDocs(t *testing.T, writeConcern *writeconcern.WriteConcern, docs ...bsonx.Doc) {
63+
func AutoInsertDocs(t *testing.T, writeConcern *writeconcern.WriteConcern, docs ...bsoncore.Document) {
9264
InsertDocs(t, DBName(t), ColName(t), writeConcern, docs...)
9365
}
9466

9567
// InsertDocs inserts the docs into the test cluster.
96-
func InsertDocs(t *testing.T, dbname, colname string, writeConcern *writeconcern.WriteConcern, docs ...bsonx.Doc) {
97-
cmd := command.Insert{NS: command.NewNamespace(dbname, colname), Docs: docs}
98-
99-
topo := Topology(t)
100-
id, _ := uuid.New()
101-
_, err := driverlegacy.Insert(
102-
context.Background(),
103-
cmd,
104-
topo,
105-
description.WriteSelector(),
106-
id,
107-
&session.Pool{},
108-
false,
109-
)
68+
func InsertDocs(t *testing.T, dbname, colname string, writeConcern *writeconcern.WriteConcern, docs ...bsoncore.Document) {
69+
err := operation.NewInsert(docs...).Collection(colname).Database(dbname).
70+
Deployment(Topology(t)).ServerSelector(description.WriteSelector()).Execute(context.Background())
11071
require.NoError(t, err)
11172
}
11273

11374
// EnableMaxTimeFailPoint turns on the max time fail point in the test cluster.
11475
func EnableMaxTimeFailPoint(t *testing.T, s *topology.Server) error {
115-
cmd := command.Write{
116-
DB: "admin",
117-
Command: bsonx.Doc{
118-
{"configureFailPoint", bsonx.String("maxTimeAlwaysTimeOut")},
119-
{"mode", bsonx.String("alwaysOn")},
120-
},
121-
}
122-
conn, err := s.ConnectionLegacy(context.Background())
123-
require.NoError(t, err)
124-
defer testhelpers.RequireNoErrorOnClose(t, conn)
125-
_, err = cmd.RoundTrip(context.Background(), s.SelectedDescription(), conn)
126-
return err
76+
cmd := bsoncore.BuildDocumentFromElements(nil,
77+
bsoncore.AppendStringElement(nil, "configureFailPoint", "maxTimeAlwaysTimeOut"),
78+
bsoncore.AppendStringElement(nil, "mode", "alwaysOn"),
79+
)
80+
return operation.NewCommand(cmd).
81+
Database("admin").Deployment(driver.SingleServerDeployment{Server: s}).
82+
Execute(context.Background())
12783
}
12884

12985
// DisableMaxTimeFailPoint turns off the max time fail point in the test cluster.
13086
func DisableMaxTimeFailPoint(t *testing.T, s *topology.Server) {
131-
cmd := command.Write{
132-
DB: "admin",
133-
Command: bsonx.Doc{
134-
{"configureFailPoint", bsonx.String("maxTimeAlwaysTimeOut")},
135-
{"mode", bsonx.String("off")},
136-
},
137-
}
138-
conn, err := s.ConnectionLegacy(context.Background())
139-
require.NoError(t, err)
140-
defer testhelpers.RequireNoErrorOnClose(t, conn)
141-
_, err = cmd.RoundTrip(context.Background(), s.SelectedDescription(), conn)
142-
require.NoError(t, err)
87+
cmd := bsoncore.BuildDocumentFromElements(nil,
88+
bsoncore.AppendStringElement(nil, "configureFailPoint", "maxTimeAlwaysTimeOut"),
89+
bsoncore.AppendStringElement(nil, "mode", "off"),
90+
)
91+
_ = operation.NewCommand(cmd).
92+
Database("admin").Deployment(driver.SingleServerDeployment{Server: s}).
93+
Execute(context.Background())
14394
}
14495

14596
// RunCommand runs an arbitrary command on a given database of target server
146-
func RunCommand(t *testing.T, s *topology.Server, db string, b bsonx.Doc) (bson.Raw, error) {
147-
conn, err := s.ConnectionLegacy(context.Background())
148-
if err != nil {
149-
return nil, err
150-
}
151-
defer testhelpers.RequireNoErrorOnClose(t, conn)
152-
cmd := command.Read{
153-
DB: db,
154-
Command: b,
155-
}
156-
return cmd.RoundTrip(context.Background(), s.SelectedDescription(), conn)
97+
func RunCommand(t *testing.T, s *topology.Server, db string, cmd bsoncore.Document) (bsoncore.Document, error) {
98+
op := operation.NewCommand(cmd).
99+
Database(db).Deployment(driver.SingleServerDeployment{Server: s})
100+
err := op.Execute(context.Background())
101+
res := op.Result()
102+
return res, err
157103
}

mongo/change_stream_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ import (
1717
"go.mongodb.org/mongo-driver/bson"
1818
"go.mongodb.org/mongo-driver/bson/bsontype"
1919
"go.mongodb.org/mongo-driver/bson/primitive"
20-
"go.mongodb.org/mongo-driver/internal/testutil/helpers"
20+
testhelpers "go.mongodb.org/mongo-driver/internal/testutil/helpers"
2121
"go.mongodb.org/mongo-driver/mongo/options"
2222
"go.mongodb.org/mongo-driver/mongo/writeconcern"
2323
"go.mongodb.org/mongo-driver/x/bsonx"
2424
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
2525
"go.mongodb.org/mongo-driver/x/mongo/driver"
26-
"go.mongodb.org/mongo-driver/x/network/command"
2726
)
2827

2928
var collectionStartingDoc = bsonx.Doc{
@@ -57,7 +56,7 @@ func (ebc *errorBatchCursor) Server() driver.Server {
5756
}
5857

5958
func (ebc *errorBatchCursor) Err() error {
60-
return command.Error{
59+
return driver.Error{
6160
Code: ebc.errCode,
6261
}
6362
}

0 commit comments

Comments
 (0)