/// <exception cref="System.Exception"/> private void SingleRun() { FsUrlStreamHandlerFactory factory = new FsUrlStreamHandlerFactory(); Random random = new Random(); ExecutorService executor = Executors.NewFixedThreadPool(Threads); AList <Future <object> > futures = new AList <Future <object> >(Tasks); for (int i = 0; i < Tasks; i++) { int aux = i; futures.AddItem(executor.Submit(new _Runnable_55(aux, random, factory))); } executor.Shutdown(); try { executor.AwaitTermination(Timeout, TimeUnit.Seconds); executor.ShutdownNow(); } catch (Exception) { } // pass // check for exceptions foreach (Future future in futures) { if (!future.IsDone()) { break; } // timed out future.Get(); } }
public virtual void TestDfsUrls() { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Build(); FileSystem fs = cluster.GetFileSystem(); // Setup our own factory // setURLSteramHandlerFactor is can be set at most once in the JVM // the new URLStreamHandler is valid for all tests cases // in TestStreamHandler FsUrlStreamHandlerFactory factory = new FsUrlStreamHandlerFactory(); Uri.SetURLStreamHandlerFactory(factory); Path filePath = new Path("/thefile"); try { byte[] fileContent = new byte[1024]; for (int i = 0; i < fileContent.Length; ++i) { fileContent[i] = unchecked ((byte)i); } // First create the file through the FileSystem API OutputStream os = fs.Create(filePath); os.Write(fileContent); os.Close(); // Second, open and read the file content through the URL API URI uri = fs.GetUri(); Uri fileURL = new Uri(uri.GetScheme(), uri.GetHost(), uri.GetPort(), filePath.ToString ()); InputStream @is = fileURL.OpenStream(); NUnit.Framework.Assert.IsNotNull(@is); byte[] bytes = new byte[4096]; NUnit.Framework.Assert.AreEqual(1024, @is.Read(bytes)); @is.Close(); for (int i_1 = 0; i_1 < fileContent.Length; ++i_1) { NUnit.Framework.Assert.AreEqual(fileContent[i_1], bytes[i_1]); } // Cleanup: delete the file fs.Delete(filePath, false); } finally { fs.Close(); cluster.Shutdown(); } }
public _Runnable_55(int aux, Random random, FsUrlStreamHandlerFactory factory) { this.aux = aux; this.random = random; this.factory = factory; }