public void InitializeAndShutdownGrpcEnvironment() { var env = GrpcEnvironment.AddRef(); Assert.IsNotNull(env.CompletionQueue); GrpcEnvironment.Release(); }
public void CreateSyncAndDestroy() { GrpcEnvironment.AddRef(); var cq = CompletionQueueSafeHandle.CreateSync(); cq.Dispose(); GrpcEnvironment.ReleaseAsync().Wait(); }
public void SubsequentInvocations() { var env1 = GrpcEnvironment.AddRef(); var env2 = GrpcEnvironment.AddRef(); Assert.AreSame(env1, env2); GrpcEnvironment.Release(); GrpcEnvironment.Release(); }
public void SubsequentInvocations() { var env1 = GrpcEnvironment.AddRef(); var env2 = GrpcEnvironment.AddRef(); Assert.IsTrue(object.ReferenceEquals(env1, env2)); GrpcEnvironment.Release(); GrpcEnvironment.Release(); }
public void InitializeAndShutdownGrpcEnvironment() { var env = GrpcEnvironment.AddRef(); Assert.IsTrue(env.CompletionQueues.Count > 0); for (int i = 0; i < env.CompletionQueues.Count; i++) { Assert.IsNotNull(env.CompletionQueues.ElementAt(i)); } GrpcEnvironment.ReleaseAsync().Wait(); }
public void InitializeAfterShutdown() { var env1 = GrpcEnvironment.AddRef(); GrpcEnvironment.Release(); var env2 = GrpcEnvironment.AddRef(); GrpcEnvironment.Release(); Assert.IsFalse(object.ReferenceEquals(env1, env2)); }
public virtual void Setup() { ThreadPool.GetMinThreads(out var workers, out var iocp); if (workers <= ThreadCount) { ThreadPool.SetMinThreads(ThreadCount + 1, iocp); } if (NeedsEnvironment) { Environment = GrpcEnvironment.AddRef(); } }
public void CreateAsyncAndShutdown() { var env = GrpcEnvironment.AddRef(); var cq = CompletionQueueSafeHandle.CreateAsync(new CompletionRegistry(env, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create())); cq.Shutdown(); var ev = cq.Next(); cq.Dispose(); GrpcEnvironment.ReleaseAsync().Wait(); Assert.AreEqual(CompletionQueueEvent.CompletionType.Shutdown, ev.type); Assert.AreNotEqual(IntPtr.Zero, ev.success); }
public void ShuttingDownEventIsFired() { var cts = new CancellationTokenSource(); var handler = new EventHandler((sender, args) => { cts.Cancel(); }); GrpcEnvironment.ShuttingDown += handler; var env = GrpcEnvironment.AddRef(); GrpcEnvironment.ReleaseAsync().Wait(); GrpcEnvironment.ShuttingDown -= handler; Assert.IsTrue(cts.Token.IsCancellationRequested); }
public void CreateAndShutdown() { GrpcEnvironment.AddRef(); var cq = CompletionQueueSafeHandle.Create(); cq.Shutdown(); var ev = cq.Next(); cq.Dispose(); GrpcEnvironment.ReleaseAsync().Wait(); Assert.AreEqual(CompletionQueueEvent.CompletionType.Shutdown, ev.type); Assert.AreNotEqual(IntPtr.Zero, ev.success); Assert.AreEqual(IntPtr.Zero, ev.tag); }
public void InitializeAfterShutdown() { Assert.AreEqual(0, GrpcEnvironment.GetRefCount()); var env1 = GrpcEnvironment.AddRef(); GrpcEnvironment.Release(); var env2 = GrpcEnvironment.AddRef(); GrpcEnvironment.Release(); Assert.AreNotSame(env1, env2); }
public void CompletionQueueCreateDestroyBenchmark() { GrpcEnvironment.AddRef(); // completion queue requires gRPC environment being initialized. BenchmarkUtil.RunBenchmark( 10, 10, () => { CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create(); cq.Dispose(); }); GrpcEnvironment.ReleaseAsync().Wait(); }
public void Setup() { var native = NativeMethods.Get(); // nop the native-call via reflection NativeMethods.Delegates.grpcsharp_call_send_status_from_server_delegate nop = (CallSafeHandle call, BatchContextSafeHandle ctx, StatusCode statusCode, byte[] statusMessage, UIntPtr statusMessageLen, MetadataArraySafeHandle metadataArray, int sendEmptyInitialMetadata, byte[] optionalSendBuffer, UIntPtr optionalSendBufferLen, WriteFlags writeFlags) => { completionRegistry.Extract(ctx.Handle).OnComplete(true); // drain the dictionary as we go return(CallError.OK); }; native.GetType().GetField(nameof(native.grpcsharp_call_send_status_from_server)).SetValue(native, nop); environment = GrpcEnvironment.AddRef(); metadata = MetadataArraySafeHandle.Create(Metadata.Empty); completionRegistry = new CompletionRegistry(environment, () => environment.BatchContextPool.Lease(), () => throw new NotImplementedException()); var cq = CompletionQueueSafeHandle.CreateAsync(completionRegistry); call = CreateFakeCall(cq); }
public virtual void Setup() { dispatchQueues = new List <BlockingCollection <Action> >(); workers = new List <Thread>(); for (int i = 0; i < ThreadCount; i++) { var dispatchQueue = new BlockingCollection <Action>(); var thread = new Thread(new ThreadStart(() => WorkerThreadBody(dispatchQueue))); thread.Name = string.Format("threaded benchmark worker {0}", i); thread.Start(); workers.Add(thread); dispatchQueues.Add(dispatchQueue); } if (NeedsEnvironment) { Environment = GrpcEnvironment.AddRef(); } }
public void Init() { var environment = GrpcEnvironment.AddRef(); // Create a fake server just so we have an instance to refer to. // The server won't actually be used at all. server = new Server() { Ports = { { "localhost", 0, ServerCredentials.Insecure } } }; server.Start(); fakeCall = new FakeNativeCall(); asyncCallServer = new AsyncCallServer <string, string>( Marshallers.StringMarshaller.Serializer, Marshallers.StringMarshaller.Deserializer, environment, server); asyncCallServer.InitializeForTesting(fakeCall); }
public void Init() { environment = GrpcEnvironment.AddRef(); }
public void Init() { Native.grpcsharp_test_override_method("grpcsharp_call_start_batch", "nop"); environment = GrpcEnvironment.AddRef(); }