Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Sharpen.URISyntaxException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Sharpen.ExecutionException"/>
        public virtual void TestDownloadPublicWithStatCache()
        {
            Configuration conf    = new Configuration();
            FileContext   files   = FileContext.GetLocalFSFileContext(conf);
            Path          basedir = files.MakeQualified(new Path("target", typeof(TestFSDownload).Name
                                                                 ));
            // if test directory doesn't have ancestor permission, skip this test
            FileSystem f = basedir.GetFileSystem(conf);

            Assume.AssumeTrue(FSDownload.AncestorsHaveExecutePermissions(f, basedir, null));
            files.Mkdir(basedir, null, true);
            conf.SetStrings(typeof(TestFSDownload).FullName, basedir.ToString());
            int size = 512;
            ConcurrentMap <Path, AtomicInteger> counts = new ConcurrentHashMap <Path, AtomicInteger
                                                                                >();
            CacheLoader <Path, Future <FileStatus> > loader = FSDownload.CreateStatusCacheLoader
                                                                  (conf);
            LoadingCache <Path, Future <FileStatus> > statCache = CacheBuilder.NewBuilder().Build
                                                                      (new _CacheLoader_328(counts, loader));
            // increment the count
            // use the default loader
            // test FSDownload.isPublic() concurrently
            int fileCount = 3;
            IList <Callable <bool> > tasks = new AList <Callable <bool> >();

            for (int i = 0; i < fileCount; i++)
            {
                Random rand       = new Random();
                long   sharedSeed = rand.NextLong();
                rand.SetSeed(sharedSeed);
                System.Console.Out.WriteLine("SEED: " + sharedSeed);
                Path path = new Path(basedir, "test-file-" + i);
                CreateFile(files, path, size, rand);
                FileSystem fs    = path.GetFileSystem(conf);
                FileStatus sStat = fs.GetFileStatus(path);
                tasks.AddItem(new _Callable_358(fs, path, sStat, statCache));
            }
            ExecutorService exec = Executors.NewFixedThreadPool(fileCount);

            try
            {
                IList <Future <bool> > futures = exec.InvokeAll(tasks);
                // files should be public
                foreach (Future <bool> future in futures)
                {
                    NUnit.Framework.Assert.IsTrue(future.Get());
                }
                // for each path exactly one file status call should be made
                foreach (AtomicInteger count in counts.Values)
                {
                    NUnit.Framework.Assert.AreSame(count.Get(), 1);
                }
            }
            finally
            {
                exec.Shutdown();
            }
        }
Beispiel #2
0
        /// <summary>Execute the callables by a number of threads</summary>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Sharpen.ExecutionException"/>
        public static void Execute <T, E>(int nThreads, IList <E> callables)
            where E : Callable <T>
        {
            ExecutorService     executor = Executors.NewFixedThreadPool(nThreads);
            IList <Future <T> > futures  = executor.InvokeAll(callables);

            foreach (Future <T> f in futures)
            {
                f.Get();
            }
        }
Beispiel #3
0
        public virtual void TestConcurrentFormat()
        {
            URI           uri = BKJMUtil.CreateJournalURI("/hdfsjournal-concurrentformat");
            NamespaceInfo nsi = NewNSInfo();
            // populate with data first
            BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri, nsi);

            bkjm.Format(nsi);
            for (int i = 1; i < 100 * 2; i += 2)
            {
                bkjm.StartLogSegment(i, NameNodeLayoutVersion.CurrentLayoutVersion);
                bkjm.FinalizeLogSegment(i, i + 1);
            }
            bkjm.Close();
            int numThreads = 40;
            IList <Callable <TestBookKeeperJournalManager.ThreadStatus> > threads = new AList <Callable
                                                                                               <TestBookKeeperJournalManager.ThreadStatus> >();
            CyclicBarrier barrier = new CyclicBarrier(numThreads);

            for (int i_1 = 0; i_1 < numThreads; i_1++)
            {
                threads.AddItem(new _Callable_784(uri, nsi, barrier));
            }
            ExecutorService service = Executors.NewFixedThreadPool(numThreads);
            IList <Future <TestBookKeeperJournalManager.ThreadStatus> > statuses = service.InvokeAll
                                                                                       (threads, 60, TimeUnit.Seconds);
            int numCompleted = 0;

            foreach (Future <TestBookKeeperJournalManager.ThreadStatus> s in statuses)
            {
                NUnit.Framework.Assert.IsTrue(s.IsDone());
                NUnit.Framework.Assert.IsTrue("Thread threw invalid exception", s.Get() == TestBookKeeperJournalManager.ThreadStatus
                                              .Completed || s.Get() == TestBookKeeperJournalManager.ThreadStatus.Goodexception
                                              );
                if (s.Get() == TestBookKeeperJournalManager.ThreadStatus.Completed)
                {
                    numCompleted++;
                }
            }
            Log.Info("Completed " + numCompleted + " formats");
            NUnit.Framework.Assert.IsTrue("No thread managed to complete formatting", numCompleted
                                          > 0);
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
            public override List <Future <T> > invokeAll <T, T1>(Collection <T1> tasks) where T1 : Callable <T>
            {
                return(e.InvokeAll(tasks));
            }