コード例 #1
0
 public void TestReturnTransport_PoolWasNotSet_Fail()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
             {
                 target.ReturnTransport(transport);
             }
 }
コード例 #2
0
		private static void TestCore( Action<ServerRequestContext, ServerTransport> test )
		{
			using ( var server = new RpcServer() )
			using ( var manager = new NullServerTransportManager( server ) )
			using ( var transport = new NullServerTransport( manager ) )
			using ( var target = new ServerRequestContext() )
			{
				test( target, transport );
			}
		}
コード例 #3
0
 private static void TestCore(Action <ServerRequestContext, ServerTransport> test)
 {
     using (var server = new RpcServer())
         using (var manager = new NullServerTransportManager(server))
             using (var transport = new NullServerTransport(manager))
                 using (var target = new ServerRequestContext())
                 {
                     test(target, transport);
                 }
 }
コード例 #4
0
 public void TestReturnTransport_Null_Fail()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
                 using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                 {
                     target.InvokeSetTransportPool(transportPool);
                     target.ReturnTransport(null);
                 }
 }
コード例 #5
0
 public void TestGetTransport_PoolWasNotSet_Fail()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
                 using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                     using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                     {
                         target.InvokeGetTransport(socket);
                     }
 }
コード例 #6
0
        public void TestBeginShutdown_ShutdownCompletedOccurredAndSocketShutdowned()
        {
            using (var server = new RpcServer())
                using (var target = new Target(server))
                    using (var transport = new NullServerTransport(target))
                        using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                            {
                                var listener = new TcpListener(IPAddress.Loopback, 19860);
                                try
                                {
                                    listener.Start();
                                    var ar = listener.BeginAcceptSocket(null, null);

                                    target.InvokeSetTransportPool(transportPool);
                                    // activate
                                    var activeTransport = target.InvokeGetTransport(socket);
                                    // maually set transport
                                    activeTransport.BoundSocket = socket;

                                    using (var waitHandle = new ManualResetEventSlim())
                                    {
                                        target.ShutdownCompleted += (sender, e) => waitHandle.Set();

                                        activeTransport.BoundSocket.Connect(IPAddress.Loopback, 19860);

                                        using (var acceptted = listener.EndAcceptSocket(ar))
                                        {
                                            target.BeginShutdown();

                                            if (Debugger.IsAttached)
                                            {
                                                waitHandle.Wait();
                                            }
                                            else
                                            {
                                                bool signaled = waitHandle.Wait(TimeSpan.FromSeconds(3));
                                                Assert.That(signaled);
                                            }
                                        }
                                    }
                                }
                                finally
                                {
                                    try
                                    {
                                        listener.Stop();
                                    }
                                    catch (SocketException) { }
                                }
                            }
        }
コード例 #7
0
		public void TestDispatch_MethodExists_Success()
		{
			var svcFile = ".\\Services.svc";
			File.WriteAllText(
				svcFile,
				String.Format( CultureInfo.InvariantCulture, "<% @ ServiceHost Service=\"{0}\" %>", typeof( TestService ).FullName )
			);
			try
			{
				var configuration = new RpcServerConfiguration();
				configuration.ServiceTypeLocatorProvider = conf => new FileBasedServiceTypeLocator();

				using ( var server = new RpcServer( configuration ) )
				using ( var transportManager = new NullServerTransportManager( server ) )
				using ( var transport = new NullServerTransport( transportManager ) )
				using ( var requestContext = DispatchTestHelper.CreateRequestContext() )
				using ( var argumentsBuffer = new MemoryStream() )
				using ( var waitHandle = new ManualResetEventSlim() )
				{
					var message = Guid.NewGuid().ToString();
					using ( var argumentsPacker = Packer.Create( argumentsBuffer, false ) )
					{
						argumentsPacker.PackArrayHeader( 1 );
						argumentsPacker.Pack( message );
					}

					argumentsBuffer.Position = 0;

					var target = new LocatorBasedDispatcher( server );
					MessagePackObject response = MessagePackObject.Nil;
					requestContext.MethodName = "Echo:TestService:1";
					requestContext.MessageId = 1;
					requestContext.SetTransport( transport );
					requestContext.ArgumentsUnpacker = Unpacker.Create( argumentsBuffer );
					transport.Sent +=
						( sender, e ) =>
						{
							response = Unpacking.UnpackString( e.Context.GetReturnValueData() ).Value;
							waitHandle.Set();
						};
					target.Dispatch( transport, requestContext );

					Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );

					Assert.That( message == response, "{0} != {1}", message, response );
				}
			}
			finally
			{
				File.Delete( svcFile );
			}
		}
コード例 #8
0
 public void TestGetRequestContext_NotNull_ReturnsWithTransportBound()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
                 using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                     using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                     {
                         target.InvokeSetTransportPool(transportPool);
                         var result = target.InvokeGetRequestContext(target.InvokeGetTransport(socket));
                         Assert.That(result.BoundTransport, Is.SameAs(transport));
                     }
 }
コード例 #9
0
 public void TestGetTransport_Null_Harmless()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
                 using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                 {
                     target.InvokeSetTransportPool(transportPool);
                     var result = target.InvokeGetTransport(null);
                     // Default implementation does not treat bindingSocket
                     Assert.That(result.BoundSocket, Is.Null);
                 }
 }
コード例 #10
0
 public void TestGetTransport_NotNull_ReturnsTransportWithSpecifiedSocket()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
                 using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                     using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                     {
                         target.InvokeSetTransportPool(transportPool);
                         var result = target.InvokeGetTransport(socket);
                         // Default implementation does not treat bindingSocket
                         Assert.That(result.BoundSocket, Is.Null);
                     }
 }
コード例 #11
0
 public void TestReturnTransport_NotNull_ReturnsToPool()
 {
     using (var server = new RpcServer())
         using (var target = new Target(server))
             using (var transport = new NullServerTransport(target))
                 using (var transportPool = new SingletonObjectPool <NullServerTransport>(transport))
                     using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                     {
                         target.InvokeSetTransportPool(transportPool);
                         NullServerTransport returned = null;
                         transportPool.ObjectReturned += (sender, e) => returned = e.ReturnedObject;
                         target.ReturnTransport(target.InvokeGetTransport(socket));
                         Assert.That(returned, Is.Not.Null.And.SameAs(transport));
                     }
 }
コード例 #12
0
		public void TestDispatch_MethodNotExists_NoMethodError()
		{
			using ( var server = new RpcServer() )
			using ( var transportManager = new NullServerTransportManager( server ) )
			using ( var transport = new NullServerTransport( transportManager ) )
			using ( var requestContext = DispatchTestHelper.CreateRequestContext() )
			using ( var argumentsBuffer = new MemoryStream() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				var message = Guid.NewGuid().ToString();
				using ( var argumentsPacker = Packer.Create( argumentsBuffer, false ) )
				{
					argumentsPacker.PackArrayHeader( 1 );
					argumentsPacker.Pack( message );
				}

				argumentsBuffer.Position = 0;

				var target = new LocatorBasedDispatcher( server );
				MessagePackObject response = MessagePackObject.Nil;
				requestContext.MethodName = "Echo:TestServices:1";
				requestContext.MessageId = 1;
				requestContext.SetTransport( transport );
				requestContext.ArgumentsUnpacker = Unpacker.Create( argumentsBuffer );
				transport.Sent +=
					( sender, e ) =>
					{
						response = Unpacking.UnpackString( e.Context.GetErrorData() ).Value;
						waitHandle.Set();
					};
				target.Dispatch( transport, requestContext );

				Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ) );

				Assert.That( RpcError.NoMethodError.Identifier == response, "{0} != {1}", message, response );
			}
		}