示例#1
0
        public virtual void TestExceptionResultsInNormalError()
        {
            // In this test, we ensure that all handlers are called even if we throw an exception in one
            RefreshHandler exceptionalHandler = Org.Mockito.Mockito.Mock <RefreshHandler>();

            Org.Mockito.Mockito.Stub(exceptionalHandler.HandleRefresh(Org.Mockito.Mockito.AnyString
                                                                          (), Org.Mockito.Mockito.Any <string[]>())).ToThrow(new RuntimeException("Exceptional Handler Throws Exception"
                                                                                                                                                  ));
            RefreshHandler otherExceptionalHandler = Org.Mockito.Mockito.Mock <RefreshHandler>
                                                         ();

            Org.Mockito.Mockito.Stub(otherExceptionalHandler.HandleRefresh(Org.Mockito.Mockito
                                                                           .AnyString(), Org.Mockito.Mockito.Any <string[]>())).ToThrow(new RuntimeException
                                                                                                                                            ("More Exceptions"));
            RefreshRegistry.DefaultRegistry().Register("exceptional", exceptionalHandler);
            RefreshRegistry.DefaultRegistry().Register("exceptional", otherExceptionalHandler
                                                       );
            DFSAdmin admin = new DFSAdmin(config);

            string[] args = new string[] { "-refresh", "localhost:" + cluster.GetNameNodePort
                                               (), "exceptional" };
            int exitCode = admin.Run(args);

            NUnit.Framework.Assert.AreEqual(-1, exitCode);
            // Exceptions result in a -1
            Org.Mockito.Mockito.Verify(exceptionalHandler).HandleRefresh("exceptional", new string
                                                                         [] {  });
            Org.Mockito.Mockito.Verify(otherExceptionalHandler).HandleRefresh("exceptional",
                                                                              new string[] {  });
            RefreshRegistry.DefaultRegistry().UnregisterAll("exceptional");
        }
示例#2
0
        public virtual void TestMultipleReturnCodeMerging()
        {
            // Two handlers which return two non-zero values
            RefreshHandler handlerOne = Org.Mockito.Mockito.Mock <RefreshHandler>();

            Org.Mockito.Mockito.Stub(handlerOne.HandleRefresh(Org.Mockito.Mockito.AnyString()
                                                              , Org.Mockito.Mockito.Any <string[]>())).ToReturn(new RefreshResponse(23, "Twenty Three"
                                                                                                                                    ));
            RefreshHandler handlerTwo = Org.Mockito.Mockito.Mock <RefreshHandler>();

            Org.Mockito.Mockito.Stub(handlerTwo.HandleRefresh(Org.Mockito.Mockito.AnyString()
                                                              , Org.Mockito.Mockito.Any <string[]>())).ToReturn(new RefreshResponse(10, "Ten"));
            // Then registered to the same ID
            RefreshRegistry.DefaultRegistry().Register("shared", handlerOne);
            RefreshRegistry.DefaultRegistry().Register("shared", handlerTwo);
            // We refresh both
            DFSAdmin admin = new DFSAdmin(config);

            string[] args = new string[] { "-refresh", "localhost:" + cluster.GetNameNodePort
                                               (), "shared" };
            int exitCode = admin.Run(args);

            NUnit.Framework.Assert.AreEqual(-1, exitCode);
            // We get -1 because of our logic for melding non-zero return codes
            // Verify we called both
            Org.Mockito.Mockito.Verify(handlerOne).HandleRefresh("shared", new string[] {  });
            Org.Mockito.Mockito.Verify(handlerTwo).HandleRefresh("shared", new string[] {  });
            RefreshRegistry.DefaultRegistry().UnregisterAll("shared");
        }
示例#3
0
        public virtual void TestUnregistrationReturnValue()
        {
            RefreshHandler mockHandler = Org.Mockito.Mockito.Mock <RefreshHandler>();

            RefreshRegistry.DefaultRegistry().Register("test", mockHandler);
            bool ret = RefreshRegistry.DefaultRegistry().Unregister("test", mockHandler);

            NUnit.Framework.Assert.IsTrue(ret);
        }
示例#4
0
        public virtual void TestUnregistration()
        {
            RefreshRegistry.DefaultRegistry().UnregisterAll("firstHandler");
            // And now this should fail
            DFSAdmin admin = new DFSAdmin(config);

            string[] args = new string[] { "-refresh", "localhost:" + cluster.GetNameNodePort
                                               (), "firstHandler" };
            int exitCode = admin.Run(args);

            NUnit.Framework.Assert.AreEqual("DFSAdmin should return -1", -1, exitCode);
        }
示例#5
0
 public virtual void SetUp()
 {
     // Register Handlers, first one just sends an ok response
     firstHandler = Org.Mockito.Mockito.Mock <RefreshHandler>();
     Org.Mockito.Mockito.Stub(firstHandler.HandleRefresh(Org.Mockito.Mockito.AnyString
                                                             (), Org.Mockito.Mockito.Any <string[]>())).ToReturn(RefreshResponse.SuccessResponse
                                                                                                                     ());
     RefreshRegistry.DefaultRegistry().Register("firstHandler", firstHandler);
     // Second handler has conditional response for testing args
     secondHandler = Org.Mockito.Mockito.Mock <RefreshHandler>();
     Org.Mockito.Mockito.Stub(secondHandler.HandleRefresh("secondHandler", new string[]
                                                          { "one", "two" })).ToReturn(new RefreshResponse(3, "three"));
     Org.Mockito.Mockito.Stub(secondHandler.HandleRefresh("secondHandler", new string[]
                                                          { "one" })).ToReturn(new RefreshResponse(2, "two"));
     RefreshRegistry.DefaultRegistry().Register("secondHandler", secondHandler);
 }
示例#6
0
        public virtual void TestMultipleRegistration()
        {
            RefreshRegistry.DefaultRegistry().Register("sharedId", firstHandler);
            RefreshRegistry.DefaultRegistry().Register("sharedId", secondHandler);
            // this should trigger both
            DFSAdmin admin = new DFSAdmin(config);

            string[] args = new string[] { "-refresh", "localhost:" + cluster.GetNameNodePort
                                               (), "sharedId", "one" };
            int exitCode = admin.Run(args);

            NUnit.Framework.Assert.AreEqual(-1, exitCode);
            // -1 because one of the responses is unregistered
            // verify we called both
            Org.Mockito.Mockito.Verify(firstHandler).HandleRefresh("sharedId", new string[] {
                "one"
            });
            Org.Mockito.Mockito.Verify(secondHandler).HandleRefresh("sharedId", new string[]
                                                                    { "one" });
            RefreshRegistry.DefaultRegistry().UnregisterAll("sharedId");
        }
示例#7
0
 public virtual void TearDown()
 {
     RefreshRegistry.DefaultRegistry().UnregisterAll("firstHandler");
     RefreshRegistry.DefaultRegistry().UnregisterAll("secondHandler");
 }