Beispiel #1
0
        public virtual void TestDisabledAuthorizationOfDefaultServlets()
        {
            Configuration conf = new Configuration();

            // Authorization is disabled by default
            conf.Set(HttpServer2.FilterInitializerProperty, typeof(TestHttpServer.DummyFilterInitializer
                                                                   ).FullName);
            conf.Set(CommonConfigurationKeys.HadoopSecurityGroupMapping, typeof(TestHttpServer.MyGroupsProvider
                                                                                ).FullName);
            Groups.GetUserToGroupsMappingService(conf);
            TestHttpServer.MyGroupsProvider.ClearMapping();
            TestHttpServer.MyGroupsProvider.mapping["userA"] = Arrays.AsList("groupA");
            TestHttpServer.MyGroupsProvider.mapping["userB"] = Arrays.AsList("groupB");
            HttpServer2 myServer = new HttpServer2.Builder().SetName("test").AddEndpoint(new
                                                                                         URI("http://localhost:0")).SetFindPort(true).Build();

            myServer.SetAttribute(HttpServer2.ConfContextAttribute, conf);
            myServer.Start();
            string serverURL = "http://" + NetUtils.GetHostPortString(myServer.GetConnectorAddress
                                                                          (0)) + "/";

            foreach (string servlet in new string[] { "conf", "logs", "stacks", "logLevel", "metrics" })
            {
                foreach (string user in new string[] { "userA", "userB" })
                {
                    Assert.Equal(HttpURLConnection.HttpOk, GetHttpStatusCode(serverURL
                                                                             + servlet, user));
                }
            }
            myServer.Stop();
        }
        /// <exception cref="System.Exception"/>
        private static HttpServer2 StartHttpServer()
        {
            new FilePath(Runtime.GetProperty("build.webapps", "build/webapps") + "/test").Mkdirs
                ();
            HttpServer2 server = new HttpServer2.Builder().SetName("test").AddEndpoint(URI.Create
                                                                                           ("http://localhost:0")).SetFindPort(true).Build();

            server.AddServlet("jobend", "/jobend", typeof(TestJobEndNotifier.JobEndServlet));
            server.Start();
            TestJobEndNotifier.JobEndServlet.calledTimes = 0;
            TestJobEndNotifier.JobEndServlet.requestUri  = null;
            TestJobEndNotifier.JobEndServlet.baseUrl     = "http://localhost:" + server.GetConnectorAddress
                                                               (0).Port + "/";
            TestJobEndNotifier.JobEndServlet.foundJobState = null;
            return(server);
        }
Beispiel #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestDynamicLogLevel()
        {
            string logName = typeof(TestLogLevel).FullName;

            Org.Apache.Commons.Logging.Log testlog = LogFactory.GetLog(logName);
            //only test Log4JLogger
            if (testlog is Log4JLogger)
            {
                Logger log = ((Log4JLogger)testlog).GetLogger();
                log.Debug("log.debug1");
                log.Info("log.info1");
                log.Error("log.error1");
                Assert.True(!Level.Error.Equals(log.GetEffectiveLevel()));
                HttpServer2 server = new HttpServer2.Builder().SetName("..").AddEndpoint(new URI(
                                                                                             "http://*****:*****@out.WriteLine("*** Connecting to " + url);
                URLConnection connection = url.OpenConnection();
                connection.Connect();
                BufferedReader @in = new BufferedReader(new InputStreamReader(connection.GetInputStream
                                                                                  ()));
                for (string line; (line = @in.ReadLine()) != null; @out.WriteLine(line))
                {
                }
                @in.Close();
                log.Debug("log.debug2");
                log.Info("log.info2");
                log.Error("log.error2");
                Assert.True(Level.Error.Equals(log.GetEffectiveLevel()));
                //command line
                string[] args = new string[] { "-setlevel", authority, logName, Level.Debug.ToString
                                                   () };
                LogLevel.Main(args);
                log.Debug("log.debug3");
                log.Info("log.info3");
                log.Error("log.error3");
                Assert.True(Level.Debug.Equals(log.GetEffectiveLevel()));
            }
            else
            {
                @out.WriteLine(testlog.GetType() + " not tested.");
            }
        }