Exemplo n.º 1
0
        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();
        }
Exemplo n.º 3
0
        public void SubsequentInvocations()
        {
            var env1 = GrpcEnvironment.AddRef();
            var env2 = GrpcEnvironment.AddRef();

            Assert.AreSame(env1, env2);
            GrpcEnvironment.Release();
            GrpcEnvironment.Release();
        }
Exemplo n.º 4
0
        public void SubsequentInvocations()
        {
            var env1 = GrpcEnvironment.AddRef();
            var env2 = GrpcEnvironment.AddRef();

            Assert.IsTrue(object.ReferenceEquals(env1, env2));
            GrpcEnvironment.Release();
            GrpcEnvironment.Release();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        public void InitializeAfterShutdown()
        {
            var env1 = GrpcEnvironment.AddRef();

            GrpcEnvironment.Release();

            var env2 = GrpcEnvironment.AddRef();

            GrpcEnvironment.Release();

            Assert.IsFalse(object.ReferenceEquals(env1, env2));
        }
Exemplo n.º 7
0
 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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public void InitializeAfterShutdown()
        {
            Assert.AreEqual(0, GrpcEnvironment.GetRefCount());

            var env1 = GrpcEnvironment.AddRef();

            GrpcEnvironment.Release();

            var env2 = GrpcEnvironment.AddRef();

            GrpcEnvironment.Release();

            Assert.AreNotSame(env1, env2);
        }
Exemplo n.º 12
0
        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();
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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();
            }
        }
Exemplo n.º 15
0
        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();
 }
Exemplo n.º 17
0
 public void Init()
 {
     Native.grpcsharp_test_override_method("grpcsharp_call_start_batch", "nop");
     environment = GrpcEnvironment.AddRef();
 }