Example #1
0
 public void Run()
 {
     try
     {
         for (int i = 0; i < SocketNum; i++)
         {
             DomainSocket[] pair = DomainSocket.Socketpair();
             watcher.Add(pair[1], new _Handler_128(handled));
             Lock.Lock();
             try
             {
                 pairs.AddItem(pair);
             }
             finally
             {
                 Lock.Unlock();
             }
         }
     }
     catch (Exception e)
     {
         TestDomainSocketWatcher.Log.Error(e);
         throw new RuntimeException(e);
     }
 }
Example #2
0
        /// <summary>Test that domain sockets are closed when the watcher is closed.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestCloseSocketOnWatcherClose()
        {
            DomainSocketWatcher watcher = NewDomainSocketWatcher(10000000);

            DomainSocket[] pair = DomainSocket.Socketpair();
            watcher.Add(pair[1], new _Handler_103());
            watcher.Close();
            Uninterruptibles.JoinUninterruptibly(watcher.watcherThread);
            NUnit.Framework.Assert.IsFalse(pair[1].IsOpen());
        }
Example #3
0
        /// <summary>Test that we can get notifications out a DomainSocketWatcher.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestDeliverNotifications()
        {
            DomainSocketWatcher watcher = NewDomainSocketWatcher(10000000);

            DomainSocket[] pair  = DomainSocket.Socketpair();
            CountDownLatch latch = new CountDownLatch(1);

            watcher.Add(pair[1], new _Handler_73(latch));
            pair[0].Close();
            latch.Await();
            watcher.Close();
        }
 /// <exception cref="System.IO.IOException"/>
 public DomainSocketWatcher(int interruptCheckPeriodMs, string src)
 {
     watcherThread = new Thread(new _Runnable_451(this));
     if (loadingFailureReason != null)
     {
         throw new NotSupportedException(loadingFailureReason);
     }
     Preconditions.CheckArgument(interruptCheckPeriodMs > 0);
     this.interruptCheckPeriodMs = interruptCheckPeriodMs;
     notificationSockets         = DomainSocket.Socketpair();
     watcherThread.SetDaemon(true);
     watcherThread.SetName(src + " DomainSocketWatcher");
     watcherThread.SetUncaughtExceptionHandler(new _UncaughtExceptionHandler_252());
     watcherThread.Start();
 }
Example #5
0
        /// <exception cref="System.Exception"/>
        public virtual void TestShutdown()
        {
            AtomicInteger bytesRead = new AtomicInteger(0);
            AtomicBoolean failed    = new AtomicBoolean(false);

            DomainSocket[] socks        = DomainSocket.Socketpair();
            Runnable       reader       = new _Runnable_737(socks, bytesRead, failed);
            Thread         readerThread = new Thread(reader);

            readerThread.Start();
            socks[0].GetOutputStream().Write(1);
            socks[0].GetOutputStream().Write(2);
            socks[0].GetOutputStream().Write(3);
            Assert.True(readerThread.IsAlive());
            socks[0].Shutdown();
            readerThread.Join();
            NUnit.Framework.Assert.IsFalse(failed.Get());
            Assert.Equal(3, bytesRead.Get());
            IOUtils.Cleanup(null, socks);
        }
Example #6
0
 /// <exception cref="System.Exception"/>
 public virtual void TestClientServerOutStreamInAbbWithSocketpair()
 {
     TestClientServer1(typeof(TestDomainSocket.OutputStreamWriteStrategy), typeof(TestDomainSocket.ArrayBackedByteBufferReadStrategy
                                                                                  ), DomainSocket.Socketpair());
 }
Example #7
0
 /// <exception cref="System.Exception"/>
 public virtual void TestClientServerOutStreamInStreamWithSocketpair()
 {
     TestClientServer1(typeof(TestDomainSocket.OutputStreamWriteStrategy), typeof(TestDomainSocket.InputStreamReadStrategy
                                                                                  ), DomainSocket.Socketpair());
 }