-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add test for issue 11653, but with Datastore
It looks like the Datastore emulator is not impacted in the way that the Firestore emulator is.
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Google.Cloud.Datastore.V1" Version="4.7.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34408.163 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Issue11653b", "Issue11653b.csproj", "{1B9AE535-B811-43D9-A56E-8B236B9E76B9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1B9AE535-B811-43D9-A56E-8B236B9E76B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1B9AE535-B811-43D9-A56E-8B236B9E76B9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1B9AE535-B811-43D9-A56E-8B236B9E76B9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1B9AE535-B811-43D9-A56E-8B236B9E76B9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4AB11F66-05AB-4096-B85A-35AA34842012} | ||
EndGlobalSection | ||
EndGlobal |
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,55 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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.Api.Gax; | ||
using Google.Cloud.Datastore.V1; | ||
using Grpc.Core; | ||
|
||
if (args.Length != 2) | ||
{ | ||
Console.WriteLine("Arguments: <emulator-host> <project-id>"); | ||
Console.WriteLine("(The DATASTORE_EMULATOR_HOST environment variable is ignored.)"); | ||
return; | ||
} | ||
|
||
Environment.SetEnvironmentVariable("DATASTORE_EMULATOR_HOST", args[0]); | ||
|
||
var db = new DatastoreDbBuilder | ||
{ | ||
ProjectId = args[1], | ||
EmulatorDetection = EmulatorDetection.EmulatorOnly | ||
}.Build(); | ||
|
||
var keyFactory = db.CreateKeyFactory("test"); | ||
var entityKey = keyFactory.CreateKey("testid"); | ||
await Try("Allocate ID", () => db.AllocateIdAsync(keyFactory.CreateIncompleteKey())); | ||
await Try("Insert entity", () => db.InsertAsync(new Entity { Key = entityKey, Properties = { { "key", "value" } } })); | ||
await Try("Get entity", () => db.LookupAsync(entityKey)); | ||
|
||
async Task Try(string description, Func<Task> taskProvider) | ||
{ | ||
try | ||
{ | ||
await taskProvider(); | ||
Console.WriteLine($"'{description}' RPC succeeded"); | ||
} | ||
catch (RpcException e) | ||
{ | ||
Console.WriteLine($"'{description}' RPC failed: {e.Message}"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"'{description}' failed more dramatically: {e.GetType()}: {e.Message}"); | ||
} | ||
} |