Esempio n. 1
0
 public virtual void TestNativeCodeLoaded()
 {
     if (RequireTestJni() == false)
     {
         Log.Info("TestNativeCodeLoader: libhadoop.so testing is not required.");
         return;
     }
     if (!NativeCodeLoader.IsNativeCodeLoaded())
     {
         NUnit.Framework.Assert.Fail("TestNativeCodeLoader: libhadoop.so testing was required, but "
                                     + "libhadoop.so was not loaded.");
     }
     NUnit.Framework.Assert.IsFalse(NativeCodeLoader.GetLibraryName().IsEmpty());
     // library names are depended on platform and build envs
     // so just check names are available
     NUnit.Framework.Assert.IsFalse(ZlibFactory.GetLibraryName().IsEmpty());
     if (NativeCodeLoader.BuildSupportsSnappy())
     {
         NUnit.Framework.Assert.IsFalse(SnappyCodec.GetLibraryName().IsEmpty());
     }
     if (NativeCodeLoader.BuildSupportsOpenssl())
     {
         NUnit.Framework.Assert.IsFalse(OpensslCipher.GetLibraryName().IsEmpty());
     }
     NUnit.Framework.Assert.IsFalse(Lz4Codec.GetLibraryName().IsEmpty());
     Log.Info("TestNativeCodeLoader: libhadoop.so is loaded.");
 }
        private void ExpectOutput(string[] args)
        {
            ExitUtil.DisableSystemExit();
            ByteArrayOutputStream outContent = new ByteArrayOutputStream();
            TextWriter            originalPs = System.Console.Out;

            Runtime.SetOut(new TextWriter(outContent));
            try
            {
                NativeLibraryChecker.Main(args);
            }
            catch (ExitUtil.ExitException)
            {
                ExitUtil.ResetFirstExitException();
            }
            finally
            {
                if (Shell.Windows)
                {
                    Assert.Equal(outContent.ToString().IndexOf("winutils: true") !=
                                 -1, true);
                }
                if (NativeCodeLoader.IsNativeCodeLoaded())
                {
                    Assert.Equal(outContent.ToString().IndexOf("hadoop:  true") !=
                                 -1, true);
                }
                Runtime.SetOut(originalPs);
            }
        }
 public virtual void TestNativeLibraryChecker()
 {
     ExitUtil.DisableSystemExit();
     // help should return normally
     NativeLibraryChecker.Main(new string[] { "-h" });
     // illegal argmuments should exit
     ExpectExit(new string[] { "-a", "-h" });
     ExpectExit(new string[] { "aaa" });
     if (NativeCodeLoader.IsNativeCodeLoaded())
     {
         // no argument should return normally
         NativeLibraryChecker.Main(new string[0]);
     }
     else
     {
         // no argument should exit
         ExpectExit(new string[0]);
     }
 }
Esempio n. 4
0
 /// <summary>Return true if the JNI-based native CRC extensions are available.</summary>
 public static bool IsAvailable()
 {
     return(NativeCodeLoader.IsNativeCodeLoaded());
 }
        /// <summary>A tool to test native library availability,</summary>
        public static void Main(string[] args)
        {
            string usage = "NativeLibraryChecker [-a|-h]\n" + "  -a  use -a to check all libraries are available\n"
                           + "      by default just check hadoop library (and\n" + "      winutils.exe on Windows OS) is available\n"
                           + "      exit with error code 1 if check failed\n" + "  -h  print this message\n";

            if (args.Length > 1 || (args.Length == 1 && !(args[0].Equals("-a") || args[0].Equals
                                                              ("-h"))))
            {
                System.Console.Error.WriteLine(usage);
                ExitUtil.Terminate(1);
            }
            bool checkAll = false;

            if (args.Length == 1)
            {
                if (args[0].Equals("-h"))
                {
                    System.Console.Out.WriteLine(usage);
                    return;
                }
                checkAll = true;
            }
            Configuration conf = new Configuration();
            bool          nativeHadoopLoaded = NativeCodeLoader.IsNativeCodeLoaded();
            bool          zlibLoaded         = false;
            bool          snappyLoaded       = false;
            // lz4 is linked within libhadoop
            bool   lz4Loaded         = nativeHadoopLoaded;
            bool   bzip2Loaded       = Bzip2Factory.IsNativeBzip2Loaded(conf);
            bool   openSslLoaded     = false;
            bool   winutilsExists    = false;
            string openSslDetail     = string.Empty;
            string hadoopLibraryName = string.Empty;
            string zlibLibraryName   = string.Empty;
            string snappyLibraryName = string.Empty;
            string lz4LibraryName    = string.Empty;
            string bzip2LibraryName  = string.Empty;
            string winutilsPath      = null;

            if (nativeHadoopLoaded)
            {
                hadoopLibraryName = NativeCodeLoader.GetLibraryName();
                zlibLoaded        = ZlibFactory.IsNativeZlibLoaded(conf);
                if (zlibLoaded)
                {
                    zlibLibraryName = ZlibFactory.GetLibraryName();
                }
                snappyLoaded = NativeCodeLoader.BuildSupportsSnappy() && SnappyCodec.IsNativeCodeLoaded
                                   ();
                if (snappyLoaded && NativeCodeLoader.BuildSupportsSnappy())
                {
                    snappyLibraryName = SnappyCodec.GetLibraryName();
                }
                if (OpensslCipher.GetLoadingFailureReason() != null)
                {
                    openSslDetail = OpensslCipher.GetLoadingFailureReason();
                    openSslLoaded = false;
                }
                else
                {
                    openSslDetail = OpensslCipher.GetLibraryName();
                    openSslLoaded = true;
                }
                if (lz4Loaded)
                {
                    lz4LibraryName = Lz4Codec.GetLibraryName();
                }
                if (bzip2Loaded)
                {
                    bzip2LibraryName = Bzip2Factory.GetLibraryName(conf);
                }
            }
            // winutils.exe is required on Windows
            winutilsPath = Shell.GetWinUtilsPath();
            if (winutilsPath != null)
            {
                winutilsExists = true;
            }
            else
            {
                winutilsPath = string.Empty;
            }
            System.Console.Out.WriteLine("Native library checking:");
            System.Console.Out.Printf("hadoop:  %b %s%n", nativeHadoopLoaded, hadoopLibraryName
                                      );
            System.Console.Out.Printf("zlib:    %b %s%n", zlibLoaded, zlibLibraryName);
            System.Console.Out.Printf("snappy:  %b %s%n", snappyLoaded, snappyLibraryName);
            System.Console.Out.Printf("lz4:     %b %s%n", lz4Loaded, lz4LibraryName);
            System.Console.Out.Printf("bzip2:   %b %s%n", bzip2Loaded, bzip2LibraryName);
            System.Console.Out.Printf("openssl: %b %s%n", openSslLoaded, openSslDetail);
            if (Shell.Windows)
            {
                System.Console.Out.Printf("winutils: %b %s%n", winutilsExists, winutilsPath);
            }
            if ((!nativeHadoopLoaded) || (Shell.Windows && (!winutilsExists)) || (checkAll &&
                                                                                  !(zlibLoaded && snappyLoaded && lz4Loaded && bzip2Loaded)))
            {
                // return 1 to indicated check failed
                ExitUtil.Terminate(1);
            }
        }