-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of PostgreSQL samples and tests
- Loading branch information
Showing
34 changed files
with
1,868 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
spanner/api/Spanner.Samples.Tests/AddColumnAsyncPostgreTest.cs
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,43 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class AddColumnAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly AddColumnAsyncPostgreSample _sample; | ||
|
||
public AddColumnAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new AddColumnAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddColumnAsyncPostgre() | ||
{ | ||
// Arrange. | ||
// Create a new database to avoid flakiness. | ||
var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; | ||
await _spannerFixture.CreatePostgreSqlDatabaseAsync(databaseId); | ||
|
||
//Act. | ||
await _sample.AddColumnAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
spanner/api/Spanner.Samples.Tests/AddStoringIndexAsyncPostgreTest.cs
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,37 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class AddStoringIndexAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly AddStoringIndexAsyncPostgreSample _sample; | ||
|
||
public AddStoringIndexAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new AddStoringIndexAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddStoringIndexAsyncPostgre() | ||
{ | ||
//Act. | ||
await _sample.AddStoringIndexAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.PostgreSqlDatabaseId); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
spanner/api/Spanner.Samples.Tests/CastDataTypesAsyncPostgreTest.cs
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,47 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class CastDataTypesAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly CastDataTypesAsyncPostgreSample _sample; | ||
|
||
public CastDataTypesAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new CastDataTypesAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCastDataTypesAsyncPostgre() | ||
{ | ||
// Act. | ||
var result = await _sample.CastDataTypesAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.PostgreSqlDatabaseId); | ||
|
||
//Assert. | ||
Assert.Equal("1", result.String); | ||
Assert.Equal(2, result.Integer); | ||
Assert.Equal(3, result.Decimal); | ||
Assert.Equal("34", BitConverter.ToString(result.Bytes)); | ||
Assert.Equal(5.00, result.Float); | ||
Assert.True(result.Bool); | ||
Assert.Equal("2021-11-03 09:35:01Z", result.Timestamp.ToString("u")); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
spanner/api/Spanner.Samples.Tests/ConnectToDatabaseAsyncPostgreTest.cs
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,40 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class ConnectToDatabaseAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly ConnectToDatabaseAsyncPostgreSample _sample; | ||
|
||
public ConnectToDatabaseAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new ConnectToDatabaseAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestConnectToDatabaseAsyncPostgre() | ||
{ | ||
// Act. | ||
var result = await _sample.ConnectToDatabaseAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.PostgreSqlDatabaseId); | ||
|
||
//Assert. | ||
Assert.Equal($"Hello from Spanner PostgreSQL!", result); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
spanner/api/Spanner.Samples.Tests/CreateDatabaseAsyncPostgreTest.cs
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,47 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Cloud.Spanner.Admin.Database.V1; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class CreateDatabaseAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly CreateDatabaseAsyncPostgreSample _sample; | ||
|
||
public CreateDatabaseAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new CreateDatabaseAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCreateDatabaseAsyncPostgre() | ||
{ | ||
// Arrange. | ||
var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; | ||
|
||
// Act. | ||
await _sample.CreateDatabaseAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
|
||
// Assert. | ||
var databases = _spannerFixture.GetDatabases(); | ||
Assert.Contains(databases, d => d.DatabaseName.DatabaseId == databaseId && d.DatabaseDialect == DatabaseDialect.Postgresql); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
spanner/api/Spanner.Samples.Tests/CreateInterleavedTablesAsyncPostgreTest.cs
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,46 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class CreateInterleavedTablesAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly CreateInterleavedTablesAsyncPostgreSample _sample; | ||
|
||
public CreateInterleavedTablesAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new CreateInterleavedTablesAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCreateInterleavedTablesAsyncPostgre() | ||
{ | ||
// Act. | ||
await _sample.CreateInterleavedTablesAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.PostgreSqlDatabaseId); | ||
|
||
//Assert. | ||
var tables = await _spannerFixture.ListTableNamesAsync(_spannerFixture.PostgreSqlDatabaseId); | ||
Assert.Collection(tables.OrderBy(j => j), | ||
item1 => Assert.Equal("albums", item1), | ||
item2 => Assert.Equal("authors", item2), | ||
item3 => Assert.Equal("books", item3), | ||
item4 => Assert.Equal("singers", item4)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
spanner/api/Spanner.Samples.Tests/ExecutePartitionedDmlAsyncPostgreTest.cs
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,50 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class ExecutePartitionedDmlAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly ExecutePartitionedDmlAsyncPostgreSample _sample; | ||
|
||
public ExecutePartitionedDmlAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new ExecutePartitionedDmlAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestExecutePartitionedDmlAsyncPostgre() | ||
{ | ||
// Arrange. | ||
var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; | ||
|
||
// Create Database. | ||
var createDatabaseAsyncPostgreSample = new CreateDatabaseAsyncPostgreSample(); | ||
await createDatabaseAsyncPostgreSample.CreateDatabaseAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
|
||
// Insert data. | ||
var insertDataSample = new InsertUsingDmlWithParametersAsyncPostgreSample(); | ||
await insertDataSample.InsertUsingDmlWithParametersAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
|
||
// Act. | ||
var result = await _sample.ExecutePartitionedDmlAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
Assert.Equal(2, result); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
spanner/api/Spanner.Samples.Tests/GetInformationSchemaAsyncPostgreTest.cs
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,59 @@ | ||
// Copyright 2022 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class GetInformationSchemaAsyncPostgreTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
private readonly GetInformationSchemaAsyncPostgreSample _sample; | ||
|
||
public GetInformationSchemaAsyncPostgreTest(SpannerFixture spannerFixture) | ||
{ | ||
_spannerFixture = spannerFixture; | ||
_sample = new GetInformationSchemaAsyncPostgreSample(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestGetInformationSchemaAsyncPostgre() | ||
{ | ||
// Arrange. Lets create a brand new database, so that tests are not flaky. | ||
var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; | ||
var createDatabaseSample = new CreateDatabaseAsyncPostgreSample(); | ||
await createDatabaseSample.CreateDatabaseAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
|
||
// Act. | ||
var result = await _sample.GetInformationSchemaAsyncPostgre(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); | ||
|
||
//Assert. | ||
Assert.Collection(result.OrderBy(j => j.Name), | ||
item1 => | ||
{ | ||
Assert.Equal("public", item1.Schema); | ||
Assert.Equal("albums", item1.Name); | ||
Assert.Equal("null", item1.UserDefinedType); | ||
}, | ||
item2 => | ||
{ | ||
Assert.Equal("public", item2.Schema); | ||
Assert.Equal("singers", item2.Name); | ||
Assert.Equal("null", item2.UserDefinedType); | ||
}); | ||
} | ||
} |
Oops, something went wrong.