Skip to content

Commit 6645b29

Browse files
committed
chore: use project references instead of package references
Use project references where possible for now to simplify development.
1 parent 1cb3641 commit 6645b29

File tree

10 files changed

+143
-14
lines changed

10 files changed

+143
-14
lines changed

drivers/spanner-ado-net/spanner-ado-net-specification-tests/spanner-ado-net-specification-tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="AdoNet.Specification.Tests" Version="2.0.0-beta.2" />
17-
<PackageReference Include="Alpha.Google.Cloud.SpannerLib.MockServer" Version="1.0.0-alpha.20251009102337" />
1817
<PackageReference Include="coverlet.collector" Version="6.0.4">
1918
<PrivateAssets>all</PrivateAssets>
2019
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -28,6 +27,7 @@
2827
</ItemGroup>
2928

3029
<ItemGroup>
30+
<ProjectReference Include="..\..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-mockserver\spannerlib-dotnet-mockserver.csproj" />
3131
<ProjectReference Include="..\spanner-ado-net\spanner-ado-net.csproj" />
3232
</ItemGroup>
3333

drivers/spanner-ado-net/spanner-ado-net-tests/AbstractMockServerTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ protected SpannerDataSource CreateDataSource()
6565
{
6666
return CreateDataSource(_ => { });
6767
}
68+
69+
protected SpannerDataSource CreateDataSource(string connectionString)
70+
{
71+
return CreateDataSource(csb => { csb.ConnectionString = connectionString; });
72+
}
6873

6974
protected SpannerDataSource CreateDataSource(Action<SpannerConnectionStringBuilder> connectionStringBuilderAction)
7075
{

drivers/spanner-ado-net/spanner-ado-net-tests/CommandTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
using Google.Cloud.Spanner.V1;
2323
using Google.Cloud.SpannerLib.MockServer;
2424
using Google.Protobuf.WellKnownTypes;
25+
using Google.Rpc;
26+
using Grpc.Core;
2527

2628
namespace Google.Cloud.Spanner.DataProvider.Tests;
2729

@@ -269,6 +271,70 @@ public async Task Timeout()
269271
Assert.That(conn!.State, Is.EqualTo(ConnectionState.Open));
270272
}
271273

274+
[Test]
275+
[Ignore("Requires support for statement_timeout in the shared library")]
276+
public async Task TimeoutAsync()
277+
{
278+
Fixture.SpannerMock.AddOrUpdateExecutionTime(nameof(Fixture.SpannerMock.ExecuteStreamingSql), ExecutionTime.FromMillis(10, 0));
279+
280+
await using var dataSource = CreateDataSource(csb => csb.CommandTimeout = 1);
281+
await using var conn = await dataSource.OpenConnectionAsync() as SpannerConnection;
282+
await using var cmd = new SpannerCommand("SELECT 1", conn!);
283+
Assert.That(async () => await cmd.ExecuteScalarAsync(),
284+
Throws.Exception
285+
.TypeOf<SpannerDbException>()
286+
.With.InnerException.TypeOf<TimeoutException>());
287+
Assert.That(conn!.State, Is.EqualTo(ConnectionState.Open));
288+
}
289+
290+
[Test]
291+
public async Task TimeoutSwitchConnection()
292+
{
293+
var csb = new SpannerConnectionStringBuilder(ConnectionString);
294+
Assert.That(csb.CommandTimeout, Is.EqualTo(0));
295+
296+
await using var dataSource1 = CreateDataSource(ConnectionString + ";CommandTimeout=100");
297+
await using var c1 = dataSource1.CreateConnection();
298+
await using var cmd = c1.CreateCommand();
299+
Assert.That(cmd.CommandTimeout, Is.EqualTo(100));
300+
await using var dataSource2 = CreateDataSource(ConnectionString + ";CommandTimeout=101");
301+
await using (var c2 = dataSource2.CreateConnection())
302+
{
303+
cmd.Connection = c2;
304+
Assert.That(cmd.CommandTimeout, Is.EqualTo(101));
305+
}
306+
cmd.CommandTimeout = 102;
307+
await using (var c2 = dataSource2.CreateConnection())
308+
{
309+
cmd.Connection = c2;
310+
Assert.That(cmd.CommandTimeout, Is.EqualTo(102));
311+
}
312+
}
313+
314+
[Test]
315+
[Ignore("Requires support for cancel in the shared library")]
316+
public async Task Cancel()
317+
{
318+
var sql = "insert into my_table (id, value) values (1, 'one')";
319+
Fixture.SpannerMock.AddOrUpdateStatementResult(sql, StatementResult.CreateUpdateCount(1L));
320+
Fixture.SpannerMock.AddOrUpdateExecutionTime(nameof(Fixture.SpannerMock.ExecuteStreamingSql), ExecutionTime.FromMillis(50, 0));
321+
322+
await using var conn = await OpenConnectionAsync();
323+
await using var cmd = conn.CreateCommand();
324+
cmd.CommandText = sql;
325+
326+
// ReSharper disable once AccessToDisposedClosure
327+
var queryTask = Task.Run(() => cmd.ExecuteNonQuery());
328+
// Wait until the request is on the mock server.
329+
Fixture.SpannerMock.WaitForRequestsToContain(message => message is ExecuteSqlRequest request && request.Sql == sql);
330+
cmd.Cancel();
331+
Assert.That(async () => await queryTask, Throws
332+
.TypeOf<OperationCanceledException>()
333+
.With.InnerException.TypeOf<SpannerDbException>()
334+
.With.InnerException.Property(nameof(SpannerDbException.ErrorCode)).EqualTo(StatusCode.Cancelled)
335+
);
336+
}
337+
272338
private void AddParameter(DbCommand command, string name, object? value)
273339
{
274340
var parameter = command.CreateParameter();

drivers/spanner-ado-net/spanner-ado-net-tests/ConnectionTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using System.Data;
1616
using System.Diagnostics.CodeAnalysis;
17-
using System.Transactions;
1817
using Google.Cloud.Spanner.V1;
1918
using Google.Cloud.SpannerLib;
2019
using Google.Cloud.SpannerLib.MockServer;
@@ -302,14 +301,16 @@ public void FailedConnectThenSucceed()
302301
[Ignore("Needs connect_timeout property")]
303302
public void OpenTimeout()
304303
{
305-
// TODO: Add connect_timeout property.
304+
// Close all current pools to ensure that we get a fresh pool.
305+
SpannerPool.CloseSpannerLib();
306+
Fixture.SpannerMock.AddOrUpdateExecutionTime(nameof(Fixture.SpannerMock.CreateSession), ExecutionTime.FromMillis(20, 0));
306307
var builder = new SpannerConnectionStringBuilder
307308
{
308309
Host = Fixture.Host,
309310
Port = (uint) Fixture.Port,
310311
UsePlainText = true,
311312
DataSource = "projects/project1/instances/instance1/databases/database1",
312-
//ConnectTimeout = TimeSpan.FromMicroseconds(1),
313+
ConnectionTimeout = 1,
313314
};
314315
using var connection = new SpannerConnection();
315316
connection.ConnectionString = builder.ConnectionString;
@@ -489,6 +490,7 @@ public async Task ConcurrentReadersAllowed()
489490
Assert.That(await conn.ExecuteScalarAsync("SELECT 1"), Is.EqualTo(1));
490491
}
491492
}
493+
492494
[Test]
493495
public async Task ManyOpenClose()
494496
{
@@ -541,8 +543,6 @@ public async Task RollbackOnClose()
541543
}
542544

543545
[Test]
544-
// TODO: Enable once https://github.com/googleapis/go-sql-spanner/pull/571 has been merged
545-
[Ignore("https://github.com/googleapis/go-sql-spanner/pull/571")]
546546
public async Task ReadLargeString()
547547
{
548548
const string sql = "select large_value from my_table";

drivers/spanner-ado-net/spanner-ado-net-tests/spanner-ado-net-tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Alpha.Google.Cloud.SpannerLib.MockServer" Version="1.0.0-alpha.20251009100446" />
1716
<PackageReference Include="coverlet.collector" Version="6.0.4">
1817
<PrivateAssets>all</PrivateAssets>
1918
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -29,6 +28,7 @@
2928
</ItemGroup>
3029

3130
<ItemGroup>
31+
<ProjectReference Include="..\..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-mockserver\spannerlib-dotnet-mockserver.csproj" />
3232
<ProjectReference Include="..\spanner-ado-net\spanner-ado-net.csproj" />
3333
</ItemGroup>
3434

drivers/spanner-ado-net/spanner-ado-net.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spanner-ado-net-samples", "
1010
EndProject
1111
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spanner-ado-net-benchmarks", "spanner-ado-net-benchmarks\spanner-ado-net-benchmarks.csproj", "{2C70D969-A8AA-440B-81D8-532C327F237E}"
1212
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spannerlib-dotnet-mockserver", "..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-mockserver\spannerlib-dotnet-mockserver.csproj", "{E690FD52-65CD-4F11-A56E-A7D3B8D7A190}"
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spannerlib-dotnet", "..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet\spannerlib-dotnet.csproj", "{90663BC7-07FD-4089-9594-94D61D9F63A2}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spannerlib-dotnet-grpc-impl", "..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-grpc-impl\spannerlib-dotnet-grpc-impl.csproj", "{8759AB44-DEC6-4E78-B64D-2EE4A403DFE1}"
18+
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spannerlib-dotnet-native-impl", "..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-native-impl\spannerlib-dotnet-native-impl.csproj", "{85711FA3-547A-4B8E-AA23-95A6108F0DF8}"
20+
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spannerlib-dotnet-grpc-v1", "..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-grpc-v1\spannerlib-dotnet-grpc-v1.csproj", "{DF3C6D80-EB58-4189-A15A-9D3FEA233AF0}"
22+
EndProject
1323
Global
1424
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1525
Debug|Any CPU = Debug|Any CPU
@@ -36,5 +46,25 @@ Global
3646
{2C70D969-A8AA-440B-81D8-532C327F237E}.Debug|Any CPU.Build.0 = Debug|Any CPU
3747
{2C70D969-A8AA-440B-81D8-532C327F237E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3848
{2C70D969-A8AA-440B-81D8-532C327F237E}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{E690FD52-65CD-4F11-A56E-A7D3B8D7A190}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{E690FD52-65CD-4F11-A56E-A7D3B8D7A190}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{E690FD52-65CD-4F11-A56E-A7D3B8D7A190}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{E690FD52-65CD-4F11-A56E-A7D3B8D7A190}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{90663BC7-07FD-4089-9594-94D61D9F63A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{90663BC7-07FD-4089-9594-94D61D9F63A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{90663BC7-07FD-4089-9594-94D61D9F63A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{90663BC7-07FD-4089-9594-94D61D9F63A2}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{8759AB44-DEC6-4E78-B64D-2EE4A403DFE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{8759AB44-DEC6-4E78-B64D-2EE4A403DFE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{8759AB44-DEC6-4E78-B64D-2EE4A403DFE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{8759AB44-DEC6-4E78-B64D-2EE4A403DFE1}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{85711FA3-547A-4B8E-AA23-95A6108F0DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{85711FA3-547A-4B8E-AA23-95A6108F0DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{85711FA3-547A-4B8E-AA23-95A6108F0DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{85711FA3-547A-4B8E-AA23-95A6108F0DF8}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{DF3C6D80-EB58-4189-A15A-9D3FEA233AF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{DF3C6D80-EB58-4189-A15A-9D3FEA233AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{DF3C6D80-EB58-4189-A15A-9D3FEA233AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{DF3C6D80-EB58-4189-A15A-9D3FEA233AF0}.Release|Any CPU.Build.0 = Release|Any CPU
3969
EndGlobalSection
4070
EndGlobal

drivers/spanner-ado-net/spanner-ado-net/SpannerCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ public class SpannerCommand : DbCommand
3232

3333
private string _commandText = "";
3434
[AllowNull] public override string CommandText { get => _commandText; set => _commandText = value ?? ""; }
35-
36-
public override int CommandTimeout { get; set; }
35+
36+
private int? _timeout;
37+
38+
public override int CommandTimeout
39+
{
40+
get => _timeout ?? (int) SpannerConnection.DefaultCommandTimeout;
41+
set => _timeout = value;
42+
}
43+
3744
public override CommandType CommandType { get; set; } = CommandType.Text;
3845
public override UpdateRowSource UpdatedRowSource { get; set; }
3946
protected override DbConnection? DbConnection { get; set; }

drivers/spanner-ado-net/spanner-ado-net/SpannerConnection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ internal Connection? LibConnection
119119
return _libConnection;
120120
}
121121
}
122+
123+
internal uint DefaultCommandTimeout => _connectionStringBuilder?.CommandTimeout ?? 0;
122124

123125
private SpannerTransaction? _transaction;
124126

@@ -297,7 +299,8 @@ private void AssertClosed()
297299

298300
protected override DbCommand CreateDbCommand()
299301
{
300-
return new SpannerCommand(this);
302+
var cmd = new SpannerCommand(this);
303+
return cmd;
301304
}
302305

303306
protected override DbBatch CreateDbBatch()

drivers/spanner-ado-net/spanner-ado-net/spanner-ado-net.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ Alpha version: Not for production use</Description>
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Alpha.Google.Cloud.SpannerLib" Version="1.0.0-alpha.20251009140944" />
23-
<PackageReference Include="Alpha.Google.Cloud.SpannerLib.GrpcImpl" Version="1.0.0-alpha.20251009140944" />
24-
<PackageReference Include="Alpha.Google.Cloud.SpannerLib.GrpcServer" Version="1.0.0-alpha.20251009140944" />
25-
<PackageReference Include="Alpha.Google.Cloud.SpannerLib.NativeImpl" Version="1.0.0-alpha.20251009140944" />
22+
<ProjectReference Include="..\..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-grpc-impl\spannerlib-dotnet-grpc-impl.csproj" />
23+
<ProjectReference Include="..\..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet-native-impl\spannerlib-dotnet-native-impl.csproj" />
24+
<ProjectReference Include="..\..\..\spannerlib\wrappers\spannerlib-dotnet\spannerlib-dotnet\spannerlib-dotnet.csproj" />
2625
</ItemGroup>
2726

2827
</Project>

spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-mockserver/MockSpannerServer.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System.Collections;
1616
using System.Collections.Concurrent;
17+
using System.Diagnostics;
1718
using Google.Cloud.Spanner.Admin.Database.V1;
1819
using Google.Cloud.Spanner.Common.V1;
1920
using Google.Cloud.Spanner.V1;
@@ -385,6 +386,24 @@ internal void AbortNextStatement()
385386

386387
public IEnumerable<IMessage> Requests => new List<IMessage>(_requests).AsReadOnly();
387388

389+
public bool WaitForRequestsToContain(Func<IMessage, bool> predicate)
390+
{
391+
return WaitForRequestsToContain(predicate, new TimeSpan(5 * TimeSpan.TicksPerSecond));
392+
}
393+
394+
public bool WaitForRequestsToContain(Func<IMessage, bool> predicate, TimeSpan timeout)
395+
{
396+
var stopwatch = new Stopwatch();
397+
while (stopwatch.Elapsed < timeout)
398+
{
399+
if (Requests.Any(predicate))
400+
{
401+
return true;
402+
}
403+
}
404+
return false;
405+
}
406+
388407
public IEnumerable<ServerCallContext> Contexts => new List<ServerCallContext>(_contexts).AsReadOnly();
389408

390409
public IEnumerable<Metadata> Headers => new List<Metadata>(_headers).AsReadOnly();

0 commit comments

Comments
 (0)