Skip to content

Commit 688d335

Browse files
CSHARP-3162: Testing Data Lake with Drivers
1 parent 42c1c17 commit 688d335

22 files changed

+817
-2
lines changed

build.cake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ Task("TestAtlasConnectivity")
237237
);
238238
});
239239

240+
Task("TestAtlasDataLake")
241+
.IsDependentOn("Build")
242+
.DoesForEach(
243+
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
244+
testProject =>
245+
{
246+
DotNetCoreTest(
247+
testProject.FullPath,
248+
new DotNetCoreTestSettings {
249+
NoBuild = true,
250+
NoRestore = true,
251+
Configuration = configuration,
252+
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
253+
Filter = "Category=\"AtlasDataLake\""
254+
}
255+
);
256+
});
257+
240258
Task("TestOcsp")
241259
.IsDependentOn("Build")
242260
.DoesForEach(

evergreen/evergreen.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ functions:
229229
params:
230230
file: mo-expansion.yml
231231

232+
bootstrap-mongohoused:
233+
- command: shell.exec
234+
params:
235+
script: |
236+
DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
237+
sh ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/build-mongohouse-local.sh
238+
- command: shell.exec
239+
params:
240+
background: true
241+
script: |
242+
DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
243+
sh ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/run-mongohouse-local.sh
244+
232245
run-tests:
233246
- command: shell.exec
234247
type: test
@@ -421,6 +434,15 @@ functions:
421434
${PREPARE_SHELL}
422435
evergreen/run-mongodb-aws-test.sh
423436
437+
run-atlas-data-lake-test:
438+
- command: shell.exec
439+
type: test
440+
params:
441+
working_dir: mongo-csharp-driver
442+
script: |
443+
${PREPARE_SHELL}
444+
evergreen/run-atlas-data-lake-test.sh
445+
424446
run-ocsp-test:
425447
- command: shell.exec
426448
type: test
@@ -657,6 +679,11 @@ tasks:
657679
- func: run-aws-auth-test-with-aws-EC2-credentials
658680
# ECS test is skipped untill testing on Linux becomes possible
659681

682+
- name: atlas-data-lake-test
683+
commands:
684+
- func: bootstrap-mongohoused
685+
- func: run-atlas-data-lake-test
686+
660687
- name: publish-snapshot
661688
depends_on:
662689
- variant: ".tests-variant"
@@ -1172,6 +1199,13 @@ buildvariants:
11721199
tasks:
11731200
- name: atlas-connectivity-tests
11741201

1202+
- name: atlas-data-lake-test
1203+
display_name: "Atlas Data Lake Tests"
1204+
run_on:
1205+
- windows-64-vs2017-test
1206+
tasks:
1207+
- name: atlas-data-lake-test
1208+
11751209
# - name: plain-auth-tests
11761210
# display_name: "PLAIN (LDAP) Auth tests"
11771211
# run_on:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -o xtrace
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
############################################
7+
# Main Program #
8+
############################################
9+
10+
echo "Running Atlas Data Lake driver tests"
11+
12+
export MONGODB_URI="mongodb://mhuser:pencil@localhost"
13+
export ATLAS_DATA_LAKE_TESTS_ENABLED=true
14+
15+
powershell.exe .\\build.ps1 -target TestAtlasDataLake

tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenFindTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ protected override void SetArgument(string name, BsonValue value)
101101
_options.Limit = value.ToInt32();
102102
return;
103103

104+
case "projection":
105+
_options.Projection = (ProjectionDefinition<BsonDocument, BsonDocument>)value;
106+
return;
107+
104108
case "result":
105109
ParseExpectedResult(value.IsBsonArray ? value.AsBsonArray : new BsonArray(new[] { value }));
106110
return;

tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ protected virtual void ExecuteOperations(IMongoClient client, Dictionary<string,
246246
}
247247
}
248248

249+
protected virtual string GetCollectionName(BsonDocument definition)
250+
{
251+
return definition[CollectionNameKey].AsString;
252+
}
253+
254+
protected virtual string GetDatabaseName(BsonDocument definition)
255+
{
256+
return definition[DatabaseNameKey].AsString;
257+
}
258+
249259
protected virtual void InsertData(IMongoClient client, string databaseName, string collectionName, BsonDocument shared)
250260
{
251261
if (shared.Contains(DataKey))
@@ -469,8 +479,8 @@ private void SetupAndRunTest(BsonDocument shared, BsonDocument test)
469479

470480
CustomDataValidation(shared, test);
471481

472-
DatabaseName = shared[DatabaseNameKey].AsString;
473-
CollectionName = shared[CollectionNameKey].AsString;
482+
DatabaseName = GetDatabaseName(shared);
483+
CollectionName = GetCollectionName(shared);
474484

475485
var client = CreateClientForTestSetup();
476486
TestInitialize(client, test, shared);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using MongoDB.Bson;
18+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
19+
using MongoDB.Bson.TestHelpers.XunitExtensions;
20+
using MongoDB.Driver.Tests.Specifications.Runner;
21+
using Xunit;
22+
23+
namespace MongoDB.Driver.Tests.Specifications.atlas_data_lake
24+
{
25+
[Trait("Category", "AtlasDataLake")]
26+
public class AtlasDataLakeTestRunner : MongoClientJsonDrivenTestRunnerBase
27+
{
28+
protected override string[] ExpectedSharedColumns => new[] { "_path", "database_name", "collection_name", "tests" };
29+
protected override string[] ExpectedTestColumns => new[] { "description", "operations", "expectations", "async" };
30+
31+
[SkippableTheory]
32+
[ClassData(typeof(TestCaseFactory))]
33+
public void Run(JsonDrivenTestCase testCase)
34+
{
35+
RequireEnvironment.Check().EnvironmentVariable("ATLAS_DATA_LAKE_TESTS_ENABLED");
36+
37+
SetupAndRunTest(testCase);
38+
}
39+
40+
protected override void CreateCollection(IMongoClient client, string databaseName, string collectionName, BsonDocument test, BsonDocument shared)
41+
{
42+
// do nothing
43+
}
44+
45+
protected override void DropCollection(MongoClient client, string databaseName, string collectionName, BsonDocument test, BsonDocument shared)
46+
{
47+
// do nothing
48+
}
49+
50+
protected override string GetCollectionName(BsonDocument definition)
51+
{
52+
if (definition.TryGetValue(CollectionNameKey, out var collectionName))
53+
{
54+
return collectionName.AsString;
55+
}
56+
else
57+
{
58+
return DriverTestConfiguration.CollectionNamespace.CollectionName;
59+
}
60+
}
61+
62+
protected override string GetDatabaseName(BsonDocument definition)
63+
{
64+
if (definition.TryGetValue(DatabaseNameKey, out var databaseName))
65+
{
66+
return databaseName.AsString;
67+
}
68+
else
69+
{
70+
return DriverTestConfiguration.DatabaseNamespace.DatabaseName;
71+
}
72+
}
73+
74+
// nested types
75+
private class TestCaseFactory : JsonDrivenTestCaseFactory
76+
{
77+
// protected properties
78+
protected override string PathPrefix => "MongoDB.Driver.Tests.Specifications.atlas_data_lake.tests.";
79+
80+
// protected methods
81+
protected override IEnumerable<JsonDrivenTestCase> CreateTestCases(BsonDocument document)
82+
{
83+
foreach (var testCase in base.CreateTestCases(document))
84+
{
85+
foreach (var async in new[] { false, true })
86+
{
87+
var name = $"{testCase.Name}:async={async}";
88+
var test = testCase.Test.DeepClone().AsBsonDocument.Add("async", async);
89+
yield return new JsonDrivenTestCase(name, testCase.Shared, test);
90+
}
91+
}
92+
}
93+
}
94+
}
95+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Linq;
17+
using FluentAssertions;
18+
using MongoDB.Bson;
19+
using MongoDB.Bson.TestHelpers.XunitExtensions;
20+
using MongoDB.Driver.Core;
21+
using MongoDB.Driver.Core.Events;
22+
using MongoDB.Driver.Core.Misc;
23+
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
24+
using Xunit;
25+
26+
namespace MongoDB.Driver.Tests.Specifications.atlas_data_lake.prose_tests
27+
{
28+
[Trait("Category", "AtlasDataLake")]
29+
public class AtlasDataLakeProseTests
30+
{
31+
[SkippableFact]
32+
public void Driver_should_connect_to_AtlasDataLake_without_authentication()
33+
{
34+
RequireEnvironment.Check().EnvironmentVariable("ATLAS_DATA_LAKE_TESTS_ENABLED");
35+
36+
using (var client = DriverTestConfiguration.CreateDisposableClient())
37+
{
38+
client.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
39+
}
40+
}
41+
42+
[SkippableFact]
43+
public void Driver_should_connect_to_AtlasDataLake_with_SCRAM_SHA_1()
44+
{
45+
RequireEnvironment.Check().EnvironmentVariable("ATLAS_DATA_LAKE_TESTS_ENABLED");
46+
RequireServer.Check().Supports(Feature.ScramSha1Authentication);
47+
48+
var connectionString = CoreTestConfiguration.ConnectionString;
49+
var username = connectionString.Username;
50+
var password = connectionString.Password;
51+
var source = connectionString.AuthSource;
52+
53+
var settings = DriverTestConfiguration.Client.Settings.Clone();
54+
settings.Credential = MongoCredential.FromComponents(mechanism: "SCRAM-SHA-1", source, username, password);
55+
56+
using (var client = DriverTestConfiguration.CreateDisposableClient(settings))
57+
{
58+
client.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
59+
}
60+
}
61+
62+
[SkippableFact]
63+
public void Driver_should_connect_to_AtlasDataLake_with_SCRAM_SHA_256()
64+
{
65+
RequireEnvironment.Check().EnvironmentVariable("ATLAS_DATA_LAKE_TESTS_ENABLED");
66+
RequireServer.Check().Supports(Feature.ScramSha256Authentication);
67+
68+
var connectionString = CoreTestConfiguration.ConnectionString;
69+
var username = connectionString.Username;
70+
var password = connectionString.Password;
71+
var source = connectionString.AuthSource;
72+
73+
var settings = DriverTestConfiguration.Client.Settings.Clone();
74+
settings.Credential = MongoCredential.FromComponents(mechanism: "SCRAM-SHA-256", source, username, password);
75+
76+
using (var client = DriverTestConfiguration.CreateDisposableClient(settings))
77+
{
78+
client.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
79+
}
80+
}
81+
82+
[SkippableFact]
83+
public void KillCursors_should_return_expected_result()
84+
{
85+
RequireEnvironment.Check().EnvironmentVariable("ATLAS_DATA_LAKE_TESTS_ENABLED");
86+
RequireServer.Check().Supports(Feature.KillCursorsCommand);
87+
88+
var databaseName = "test";
89+
var collectionName = "driverdata";
90+
91+
var eventCapturer = new EventCapturer()
92+
.Capture<CommandStartedEvent>(x => "killCursors" == x.CommandName)
93+
.Capture<CommandSucceededEvent>(x => new[] { "killCursors", "find" }.Contains(x.CommandName));
94+
95+
using (var client = DriverTestConfiguration.CreateDisposableClient(eventCapturer))
96+
{
97+
var cursor = client
98+
.GetDatabase(databaseName)
99+
.GetCollection<BsonDocument>(collectionName)
100+
.Find(new BsonDocument(), new FindOptions { BatchSize = 2 })
101+
.ToCursor();
102+
103+
var findCommandSucceededEvent = eventCapturer.Events.OfType<CommandSucceededEvent>().First(x => x.CommandName == "find");
104+
var findCommandResult = findCommandSucceededEvent.Reply;
105+
var cursorId = findCommandResult["cursor"]["id"].AsInt64;
106+
var cursorNamespace = CollectionNamespace.FromFullName(findCommandResult["cursor"]["ns"].AsString);
107+
108+
cursor.Dispose();
109+
110+
var killCursorsCommandStartedEvent = eventCapturer.Events.OfType<CommandStartedEvent>().First(x => x.CommandName == "killCursors");
111+
var killCursorsCommandSucceededEvent = eventCapturer.Events.OfType<CommandSucceededEvent>().First(x => x.CommandName == "killCursors");
112+
var killCursorsStartedCommand = killCursorsCommandStartedEvent.Command;
113+
114+
cursorNamespace.DatabaseNamespace.DatabaseName.Should().Be(killCursorsCommandStartedEvent.DatabaseNamespace.DatabaseName);
115+
cursorNamespace.CollectionName.Should().Be(killCursorsStartedCommand["killCursors"].AsString);
116+
cursorId.Should().Be(killCursorsStartedCommand["cursors"][0].AsInt64);
117+
cursorId.Should().Be(killCursorsCommandSucceededEvent.Reply["cursorsKilled"][0].AsInt64);
118+
}
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)