diff --git a/issues/Issue11653b/Issue11653b.csproj b/issues/Issue11653b/Issue11653b.csproj new file mode 100644 index 000000000000..3f313d8413b4 --- /dev/null +++ b/issues/Issue11653b/Issue11653b.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/issues/Issue11653b/Issue11653b.sln b/issues/Issue11653b/Issue11653b.sln new file mode 100644 index 000000000000..0a7d1eff60e9 --- /dev/null +++ b/issues/Issue11653b/Issue11653b.sln @@ -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 diff --git a/issues/Issue11653b/Program.cs b/issues/Issue11653b/Program.cs new file mode 100644 index 000000000000..fe412d93e55f --- /dev/null +++ b/issues/Issue11653b/Program.cs @@ -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: "); + 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 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}"); + } +}