Example #1
0
 public override void Run()
 {
     try
     {
         DomainSocket client             = DomainSocket.Connect(TestPath);
         OutputStream clientOutputStream = client.GetOutputStream();
         InputStream  clientInputStream  = client.GetInputStream();
         clientOutputStream.Write(clientMsg1);
         DomainSocket      domainConn = (DomainSocket)client;
         byte[]            in1        = new byte[serverMsg1.Length];
         FileInputStream[] recvFis    = new FileInputStream[passedFds.Length];
         int r = domainConn.RecvFileInputStreams(recvFis, in1, 0, in1.Length - 1);
         Assert.True(r > 0);
         IOUtils.ReadFully(clientInputStream, in1, r, in1.Length - r);
         Assert.True(Arrays.Equals(serverMsg1, in1));
         for (int i = 0; i < passedFds.Length; i++)
         {
             NUnit.Framework.Assert.IsNotNull(recvFis[i]);
             passedFiles[i].CheckInputStream(recvFis[i]);
         }
         foreach (FileInputStream fis in recvFis)
         {
             fis.Close();
         }
         client.Close();
     }
     catch (System.Exception e)
     {
         threadResults.AddItem(e);
     }
     threadResults.AddItem(new TestDomainSocket.Success());
 }
Example #2
0
        /// <summary>
        /// Test that we get an AsynchronousCloseException when the DomainSocket
        /// we're using is closed during a read or write operation.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        private void TestAsyncCloseDuringIO(bool closeDuringWrite)
        {
            string TestPath = new FilePath(sockDir.GetDir(), "testAsyncCloseDuringIO(" + closeDuringWrite
                                           + ")").GetAbsolutePath();
            DomainSocket    serv           = DomainSocket.BindAndListen(TestPath);
            ExecutorService exeServ        = Executors.NewFixedThreadPool(2);
            Callable <Void> serverCallable = new _Callable_180(serv, closeDuringWrite);
            // The server just continues either writing or reading until someone
            // asynchronously closes the client's socket.  At that point, all our
            // reads return EOF, and writes get a socket error.
            Future <Void>   serverFuture   = exeServ.Submit(serverCallable);
            DomainSocket    clientConn     = DomainSocket.Connect(serv.GetPath());
            Callable <Void> clientCallable = new _Callable_213(closeDuringWrite, clientConn);
            // The client writes or reads until another thread
            // asynchronously closes the socket.  At that point, we should
            // get ClosedChannelException, or possibly its subclass
            // AsynchronousCloseException.
            Future <Void> clientFuture = exeServ.Submit(clientCallable);

            Thread.Sleep(500);
            clientConn.Close();
            serv.Close();
            clientFuture.Get(2, TimeUnit.Minutes);
            serverFuture.Get(2, TimeUnit.Minutes);
        }
Example #3
0
 /// <summary>Test that attempting to connect to an invalid path doesn't work.</summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual void TestInvalidOperations()
 {
     try
     {
         DomainSocket.Connect(new FilePath(sockDir.GetDir(), "test_sock_invalid_operation"
                                           ).GetAbsolutePath());
     }
     catch (IOException e)
     {
         GenericTestUtils.AssertExceptionContains("connect(2) error: ", e);
     }
 }
Example #4
0
        /// <summary>Test that we get a read result of -1 on EOF.</summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestSocketReadEof()
        {
            string TestPath = new FilePath(sockDir.GetDir(), "testSocketReadEof").GetAbsolutePath
                                  ();
            DomainSocket    serv     = DomainSocket.BindAndListen(TestPath);
            ExecutorService exeServ  = Executors.NewSingleThreadExecutor();
            Callable <Void> callable = new _Callable_109(serv);
            Future <Void>   future   = exeServ.Submit(callable);
            DomainSocket    conn     = DomainSocket.Connect(serv.GetPath());

            Thread.Sleep(50);
            conn.Close();
            serv.Close();
            future.Get(2, TimeUnit.Minutes);
        }
Example #5
0
 public override void Run()
 {
     try
     {
         DomainSocket client = preConnectedSockets != null ? preConnectedSockets[1] : DomainSocket
                               .Connect(TestPath);
         TestDomainSocket.WriteStrategy writer = System.Activator.CreateInstance(writeStrategyClass
                                                                                 );
         writer.Init(client);
         writer.Write(clientMsg1);
         TestDomainSocket.ReadStrategy reader = System.Activator.CreateInstance(readStrategyClass
                                                                                );
         reader.Init(client);
         byte[] in1 = new byte[serverMsg1.Length];
         reader.ReadFully(in1, 0, in1.Length);
         Assert.True(Arrays.Equals(serverMsg1, in1));
         OutputStream clientOutputStream = client.GetOutputStream();
         clientOutputStream.Write(clientMsg2);
         client.Close();
     }
     catch (Exception e)
     {
         threadResults.AddItem(e);
     }
     threadResults.AddItem(new TestDomainSocket.Success());
 }