Пример #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 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);
 }
Пример #3
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");
        }