use of org.apache.hadoop.ipc.RefreshHandler in project hadoop by apache.
the class TestGenericRefresh method testExceptionResultsInNormalError.
@Test
public void testExceptionResultsInNormalError() throws Exception {
// In this test, we ensure that all handlers are called even if we throw an exception in one
RefreshHandler exceptionalHandler = Mockito.mock(RefreshHandler.class);
Mockito.stub(exceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).toThrow(new RuntimeException("Exceptional Handler Throws Exception"));
RefreshHandler otherExceptionalHandler = Mockito.mock(RefreshHandler.class);
Mockito.stub(otherExceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).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);
// Exceptions result in a -1
assertEquals(-1, exitCode);
Mockito.verify(exceptionalHandler).handleRefresh("exceptional", new String[] {});
Mockito.verify(otherExceptionalHandler).handleRefresh("exceptional", new String[] {});
RefreshRegistry.defaultRegistry().unregisterAll("exceptional");
}
use of org.apache.hadoop.ipc.RefreshHandler in project hadoop by apache.
the class TestGenericRefresh method testUnregistrationReturnValue.
@Test
public void testUnregistrationReturnValue() {
RefreshHandler mockHandler = Mockito.mock(RefreshHandler.class);
RefreshRegistry.defaultRegistry().register("test", mockHandler);
boolean ret = RefreshRegistry.defaultRegistry().unregister("test", mockHandler);
assertTrue(ret);
}
use of org.apache.hadoop.ipc.RefreshHandler in project hadoop by apache.
the class TestGenericRefresh method testMultipleReturnCodeMerging.
@Test
public void testMultipleReturnCodeMerging() throws Exception {
// Two handlers which return two non-zero values
RefreshHandler handlerOne = Mockito.mock(RefreshHandler.class);
Mockito.stub(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).toReturn(new RefreshResponse(23, "Twenty Three"));
RefreshHandler handlerTwo = Mockito.mock(RefreshHandler.class);
Mockito.stub(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).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);
// We get -1 because of our logic for melding non-zero return codes
assertEquals(-1, exitCode);
// Verify we called both
Mockito.verify(handlerOne).handleRefresh("shared", new String[] {});
Mockito.verify(handlerTwo).handleRefresh("shared", new String[] {});
RefreshRegistry.defaultRegistry().unregisterAll("shared");
}
Aggregations