//fc should be set appropriately by the deriving test.
        /// <exception cref="System.Exception"/>
        public virtual void TestStatisticsOperations()
        {
            FileSystem.Statistics stats = new FileSystem.Statistics("file");
            Assert.Equal(0L, stats.GetBytesRead());
            Assert.Equal(0L, stats.GetBytesWritten());
            Assert.Equal(0, stats.GetWriteOps());
            stats.IncrementBytesWritten(1000);
            Assert.Equal(1000L, stats.GetBytesWritten());
            Assert.Equal(0, stats.GetWriteOps());
            stats.IncrementWriteOps(123);
            Assert.Equal(123, stats.GetWriteOps());
            Thread thread = new _Thread_61(stats);

            thread.Start();
            Uninterruptibles.JoinUninterruptibly(thread);
            Assert.Equal(124, stats.GetWriteOps());
            // Test copy constructor and reset function
            FileSystem.Statistics stats2 = new FileSystem.Statistics(stats);
            stats.Reset();
            Assert.Equal(0, stats.GetWriteOps());
            Assert.Equal(0L, stats.GetBytesWritten());
            Assert.Equal(0L, stats.GetBytesRead());
            Assert.Equal(124, stats2.GetWriteOps());
            Assert.Equal(1000L, stats2.GetBytesWritten());
            Assert.Equal(0L, stats2.GetBytesRead());
        }
 /// <summary>Close the DomainSocketWatcher and wait for its thread to terminate.</summary>
 /// <remarks>
 /// Close the DomainSocketWatcher and wait for its thread to terminate.
 /// If there is more than one close, all but the first will be ignored.
 /// </remarks>
 /// <exception cref="System.IO.IOException"/>
 public void Close()
 {
     Lock.Lock();
     try
     {
         if (closed)
         {
             return;
         }
         if (Log.IsDebugEnabled())
         {
             Log.Debug(this + ": closing");
         }
         closed = true;
     }
     finally
     {
         Lock.Unlock();
     }
     // Close notificationSockets[0], so that notificationSockets[1] gets an EOF
     // event.  This will wake up the thread immediately if it is blocked inside
     // the select() system call.
     notificationSockets[0].Close();
     // Wait for the select thread to terminate.
     Uninterruptibles.JoinUninterruptibly(watcherThread);
 }
        /// <summary>
        /// Test that transitioning a service to the state that it is already
        /// in is a nop, specifically, an exception is not thrown.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestTransitionToCurrentStateIsANop()
        {
            Configuration conf = new Configuration();

            conf.SetLong(DFSConfigKeys.DfsNamenodePathBasedCacheRefreshIntervalMs, 1L);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(1).Build();
            List <Sharpen.Thread> crmThreads = new List <Sharpen.Thread>();

            try
            {
                cluster.WaitActive();
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToActive(0);
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToActive(0);
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToStandby(0);
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToStandby(0);
                AddCrmThreads(cluster, crmThreads);
            }
            finally
            {
                cluster.Shutdown();
            }
            // Verify that all cacheReplicationMonitor threads shut down
            foreach (Sharpen.Thread thread in crmThreads)
            {
                Uninterruptibles.JoinUninterruptibly(thread);
            }
        }
        public virtual void TestConcurrentRead()
        {
            StartUpCluster(true, 2);
            string MethodName = GenericTestUtils.GetMethodName();
            Path   path1      = new Path("/" + MethodName + ".dat");
            int    Seed       = unchecked ((int)(0xFADED));
            int    NumTasks   = 5;

            MakeRandomTestFile(path1, BlockSize, true, Seed);
            EnsureFileReplicasOnStorageType(path1, StorageType.RamDisk);
            //Read from multiple clients
            CountDownLatch latch          = new CountDownLatch(NumTasks);
            AtomicBoolean  testFailed     = new AtomicBoolean(false);
            Runnable       readerRunnable = new _Runnable_564(this, path1, Seed, testFailed, latch);

            Sharpen.Thread[] threads = new Sharpen.Thread[NumTasks];
            for (int i = 0; i < NumTasks; i++)
            {
                threads[i] = new Sharpen.Thread(readerRunnable);
                threads[i].Start();
            }
            Sharpen.Thread.Sleep(500);
            for (int i_1 = 0; i_1 < NumTasks; i_1++)
            {
                Uninterruptibles.JoinUninterruptibly(threads[i_1]);
            }
            NUnit.Framework.Assert.IsFalse(testFailed.Get());
        }
Beispiel #5
0
        /// <summary>Test that a java interruption can stop the watcher thread</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestInterruption()
        {
            DomainSocketWatcher watcher = NewDomainSocketWatcher(10);

            watcher.watcherThread.Interrupt();
            Uninterruptibles.JoinUninterruptibly(watcher.watcherThread);
            watcher.Close();
        }
Beispiel #6
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());
        }
        /// <summary>
        /// Test the case where we have a failure to complete a short circuit read
        /// that occurs, and then later on, we have a success.
        /// </summary>
        /// <remarks>
        /// Test the case where we have a failure to complete a short circuit read
        /// that occurs, and then later on, we have a success.
        /// Any thread waiting on a cache load should receive the failure (if it
        /// occurs);  however, the failure result should not be cached.  We want
        /// to be able to retry later and succeed.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestShortCircuitCacheTemporaryFailure()
        {
            BlockReaderTestUtil.EnableBlockReaderFactoryTracing();
            AtomicBoolean replicaCreationShouldFail = new AtomicBoolean(true);
            AtomicBoolean testFailed = new AtomicBoolean(false);

            DFSInputStream.tcpReadsDisabledForTesting = true;
            BlockReaderFactory.createShortCircuitReplicaInfoCallback = new _ShortCircuitReplicaCreator_215
                                                                           (replicaCreationShouldFail);
            // Insert a short delay to increase the chance that one client
            // thread waits for the other client thread's failure via
            // a condition variable.
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            Configuration            conf    = CreateShortCircuitConf("testShortCircuitCacheTemporaryFailure"
                                                                      , sockDir);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            DistributedFileSystem dfs       = cluster.GetFileSystem();
            string         TestFile         = "/test_file";
            int            TestFileLen      = 4000;
            int            NumThreads       = 2;
            int            Seed             = unchecked ((int)(0xFADED));
            CountDownLatch gotFailureLatch  = new CountDownLatch(NumThreads);
            CountDownLatch shouldRetryLatch = new CountDownLatch(1);

            DFSTestUtil.CreateFile(dfs, new Path(TestFile), TestFileLen, (short)1, Seed);
            Runnable readerRunnable = new _Runnable_243(cluster, TestFile, TestFileLen, gotFailureLatch
                                                        , shouldRetryLatch, testFailed);

            // First time should fail.
            // first block
            // keep findbugs happy
            // Second time should succeed.
            Sharpen.Thread[] threads = new Sharpen.Thread[NumThreads];
            for (int i = 0; i < NumThreads; i++)
            {
                threads[i] = new Sharpen.Thread(readerRunnable);
                threads[i].Start();
            }
            gotFailureLatch.Await();
            replicaCreationShouldFail.Set(false);
            shouldRetryLatch.CountDown();
            for (int i_1 = 0; i_1 < NumThreads; i_1++)
            {
                Uninterruptibles.JoinUninterruptibly(threads[i_1]);
            }
            cluster.Shutdown();
            sockDir.Close();
            NUnit.Framework.Assert.IsFalse(testFailed.Get());
        }
Beispiel #8
0
 /// <summary>
 /// Stops and removes all volume scanners.<p/>
 /// This function will block until all the volume scanners have stopped.
 /// </summary>
 public virtual void RemoveAllVolumeScanners()
 {
     lock (this)
     {
         foreach (KeyValuePair <string, VolumeScanner> entry in scanners)
         {
             entry.Value.Shutdown();
         }
         foreach (KeyValuePair <string, VolumeScanner> entry_1 in scanners)
         {
             Uninterruptibles.JoinUninterruptibly(entry_1.Value, 5, TimeUnit.Minutes);
         }
         scanners.Clear();
     }
 }
Beispiel #9
0
        /// <exception cref="System.Exception"/>
        public virtual void TestStress()
        {
            int                    SocketNum   = 250;
            ReentrantLock          Lock        = new ReentrantLock();
            DomainSocketWatcher    watcher     = NewDomainSocketWatcher(10000000);
            AList <DomainSocket[]> pairs       = new AList <DomainSocket[]>();
            AtomicInteger          handled     = new AtomicInteger(0);
            Thread                 adderThread = new Thread(new _Runnable_122(SocketNum, watcher
                                                                              , Lock, pairs, handled));
            Thread removerThread = new Thread(new _Runnable_149(handled, SocketNum
                                                                , Lock, pairs, watcher));

            adderThread.Start();
            removerThread.Start();
            Uninterruptibles.JoinUninterruptibly(adderThread);
            Uninterruptibles.JoinUninterruptibly(removerThread);
            watcher.Close();
        }
        /// <summary>
        /// Test the case where we have multiple threads waiting on the
        /// ShortCircuitCache delivering a certain ShortCircuitReplica.
        /// </summary>
        /// <remarks>
        /// Test the case where we have multiple threads waiting on the
        /// ShortCircuitCache delivering a certain ShortCircuitReplica.
        /// In this case, there should only be one call to
        /// createShortCircuitReplicaInfo.  This one replica should be shared
        /// by all threads.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestMultipleWaitersOnShortCircuitCache()
        {
            CountDownLatch latch             = new CountDownLatch(1);
            AtomicBoolean  creationIsBlocked = new AtomicBoolean(true);
            AtomicBoolean  testFailed        = new AtomicBoolean(false);

            DFSInputStream.tcpReadsDisabledForTesting = true;
            BlockReaderFactory.createShortCircuitReplicaInfoCallback = new _ShortCircuitReplicaCreator_146
                                                                           (latch, creationIsBlocked);
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            Configuration            conf    = CreateShortCircuitConf("testMultipleWaitersOnShortCircuitCache"
                                                                      , sockDir);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            DistributedFileSystem dfs = cluster.GetFileSystem();
            string TestFile           = "/test_file";
            int    TestFileLen        = 4000;
            int    Seed       = unchecked ((int)(0xFADED));
            int    NumThreads = 10;

            DFSTestUtil.CreateFile(dfs, new Path(TestFile), TestFileLen, (short)1, Seed);
            Runnable readerRunnable = new _Runnable_170(dfs, TestFile, creationIsBlocked, Seed
                                                        , TestFileLen, testFailed);

            Sharpen.Thread[] threads = new Sharpen.Thread[NumThreads];
            for (int i = 0; i < NumThreads; i++)
            {
                threads[i] = new Sharpen.Thread(readerRunnable);
                threads[i].Start();
            }
            Sharpen.Thread.Sleep(500);
            latch.CountDown();
            for (int i_1 = 0; i_1 < NumThreads; i_1++)
            {
                Uninterruptibles.JoinUninterruptibly(threads[i_1]);
            }
            cluster.Shutdown();
            sockDir.Close();
            NUnit.Framework.Assert.IsFalse(testFailed.Get());
        }
Beispiel #11
0
 /// <summary>
 /// Stops and removes a volume scanner.<p/>
 /// This function will block until the volume scanner has stopped.
 /// </summary>
 /// <param name="volume">The volume to remove.</param>
 public virtual void RemoveVolumeScanner(FsVolumeSpi volume)
 {
     lock (this)
     {
         if (!IsEnabled())
         {
             Log.Debug("Not removing volume scanner for {}, because the block " + "scanner is disabled."
                       , volume.GetStorageID());
             return;
         }
         VolumeScanner scanner = scanners[volume.GetStorageID()];
         if (scanner == null)
         {
             Log.Warn("No scanner found to remove for volumeId {}", volume.GetStorageID());
             return;
         }
         Log.Info("Removing scanner for volume {} (StorageID {})", volume.GetBasePath(), volume
                  .GetStorageID());
         scanner.Shutdown();
         Sharpen.Collections.Remove(scanners, volume.GetStorageID());
         Uninterruptibles.JoinUninterruptibly(scanner, 5, TimeUnit.Minutes);
     }
 }