예제 #1
0
 public virtual void Cleanup()
 {
     if (Environment != null)
     {
         Environment = null;
         GrpcEnvironment.ReleaseAsync().Wait();
     }
 }
        public void CreateSyncAndDestroy()
        {
            GrpcEnvironment.AddRef();
            var cq = CompletionQueueSafeHandle.CreateSync();

            cq.Dispose();
            GrpcEnvironment.ReleaseAsync().Wait();
        }
예제 #3
0
        public void SubsequentInvocations()
        {
            var env1 = GrpcEnvironment.AddRef();
            var env2 = GrpcEnvironment.AddRef();

            Assert.AreSame(env1, env2);
            GrpcEnvironment.ReleaseAsync().Wait();
            GrpcEnvironment.ReleaseAsync().Wait();
        }
예제 #4
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();
        }
        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);
        }
예제 #6
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);
        }
예제 #7
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();
        }
예제 #8
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);
        }
예제 #9
0
        public virtual void Cleanup()
        {
            for (int i = 0; i < ThreadCount; i++)
            {
                dispatchQueues[i].Add(null);  // null action request termination of the worker thread.
                workers[i].Join();
            }

            if (Environment != null)
            {
                Environment = null;
                GrpcEnvironment.ReleaseAsync().Wait();
            }
        }
예제 #10
0
        public void InitializeAfterShutdown()
        {
            Assert.AreEqual(0, GrpcEnvironment.GetRefCount());

            var env1 = GrpcEnvironment.AddRef();

            GrpcEnvironment.ReleaseAsync().Wait();

            var env2 = GrpcEnvironment.AddRef();

            GrpcEnvironment.ReleaseAsync().Wait();

            Assert.AreNotSame(env1, env2);
        }
예제 #11
0
 public void Cleanup()
 {
     GrpcEnvironment.ReleaseAsync().Wait();
     // TODO(jtattermusch): track GC stats
 }
예제 #12
0
 public void ReleaseWithoutAddRef()
 {
     Assert.AreEqual(0, GrpcEnvironment.GetRefCount());
     Assert.ThrowsAsync(typeof(InvalidOperationException), async() => await GrpcEnvironment.ReleaseAsync());
 }
 public void Cleanup()
 {
     GrpcEnvironment.ReleaseAsync().Wait();
 }