当前位置: 首页>>代码示例>>Java>>正文


Java LoggingStateChangeListener类代码示例

本文整理汇总了Java中org.apache.hadoop.service.LoggingStateChangeListener的典型用法代码示例。如果您正苦于以下问题:Java LoggingStateChangeListener类的具体用法?Java LoggingStateChangeListener怎么用?Java LoggingStateChangeListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LoggingStateChangeListener类属于org.apache.hadoop.service包,在下文中一共展示了LoggingStateChangeListener类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStopFailingInitAndStop

import org.apache.hadoop.service.LoggingStateChangeListener; //导入依赖的package包/类
/**
 * Show that if the service failed during an init
 * operation, stop was called.
 */

@Test
public void testStopFailingInitAndStop() throws Throwable {
  BreakableService svc = new BreakableService(true, false, true);
  svc.registerServiceListener(new LoggingStateChangeListener());
  try {
    svc.init(new Configuration());
    fail("Expected a failure, got " + svc);
  } catch (BreakableService.BrokenLifecycleEvent e) {
    assertEquals(Service.STATE.INITED, e.state);
  }
  //the service state is stopped
  assertServiceStateStopped(svc);
  assertEquals(Service.STATE.INITED, svc.getFailureState());

  Throwable failureCause = svc.getFailureCause();
  assertNotNull("Null failure cause in " + svc, failureCause);
  BreakableService.BrokenLifecycleEvent cause =
    (BreakableService.BrokenLifecycleEvent) failureCause;
  assertNotNull("null state in " + cause + " raised by " + svc, cause.state);
  assertEquals(Service.STATE.INITED, cause.state);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:27,代码来源:TestServiceLifecycle.java

示例2: testListenerChain

import org.apache.hadoop.service.LoggingStateChangeListener; //导入依赖的package包/类
/**
 * Create a chain of listeners and set one in the middle to fail; verify that
 * those in front got called, and those after did not.
 */
@Test
public void testListenerChain() {

  //create and register the listeners
  LoggingStateChangeListener logListener = new LoggingStateChangeListener();
  register(logListener);
  BreakableStateChangeListener l0 = new BreakableStateChangeListener("l0");
  register(l0);
  listener.setFailingState(Service.STATE.STARTED);
  register();
  BreakableStateChangeListener l3 = new BreakableStateChangeListener("l3");
  register(l3);

  //create and init a service.
  BreakableService service = new BreakableService();
  service.init(new Configuration());
  assertServiceStateInited(service);
  assertListenerState(l0, Service.STATE.INITED);
  assertListenerState(listener, Service.STATE.INITED);
  assertListenerState(l3, Service.STATE.INITED);

  service.start();
  //expect that listener l1 and the failing listener are in start, but
  //not the final one
  assertServiceStateStarted(service);
  assertListenerState(l0, Service.STATE.STARTED);
  assertListenerEventCount(l0, 2);
  assertListenerState(listener, Service.STATE.STARTED);
  assertListenerEventCount(listener, 2);
  //this is the listener that is not expected to have been invoked
  assertListenerState(l3, Service.STATE.INITED);
  assertListenerEventCount(l3, 1);

  //stop the service
  service.stop();
  //listeners are all updated
  assertListenerEventCount(l0, 3);
  assertListenerEventCount(listener, 3);
  assertListenerEventCount(l3, 2);
  //can all be unregistered in any order
  unregister(logListener);
  unregister(l0);
  unregister(l3);

  //check that the listeners are all unregistered, even
  //though they were registered in a different order.
  //rather than do this by doing unregister checks, a new service is created
  service = new BreakableService();
  //this service is initialized
  service.init(new Configuration());
  //it is asserted that the event count has not changed for the unregistered
  //listeners
  assertListenerEventCount(l0, 3);
  assertListenerEventCount(l3, 2);
  //except for the one listener that was not unregistered, which
  //has incremented by one
  assertListenerEventCount(listener, 4);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:63,代码来源:TestGlobalStateChangeListener.java


注:本文中的org.apache.hadoop.service.LoggingStateChangeListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。