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


Java JournalFaultInjector类代码示例

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


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

示例1: testCrashBetweenSyncLogAndPersistPaxosData

import org.apache.hadoop.hdfs.qjournal.server.JournalFaultInjector; //导入依赖的package包/类
@Test(timeout=20000)
public void testCrashBetweenSyncLogAndPersistPaxosData() throws Exception {
  JournalFaultInjector faultInjector =
      JournalFaultInjector.instance = Mockito.mock(JournalFaultInjector.class);

  setupLoggers345();

  // Run recovery where the client only talks to JN0, JN1, such that it
  // decides that the correct length is through txid 4.
  // Only allow it to call acceptRecovery() on JN0.
  qjm = createSpyingQJM();
  spies = qjm.getLoggerSetForTests().getLoggersForTests();    
  cluster.getJournalNode(2).stopAndJoin(0);
  injectIOE().when(spies.get(1)).acceptRecovery(
      Mockito.<SegmentStateProto>any(), Mockito.<URL>any());
  
  tryRecoveryExpectingFailure();

  cluster.restartJournalNode(2);
  
  // State at this point:
  // JN0: edit log for 1-4, paxos recovery data for txid 4
  // JN1: edit log for 1-4,
  // JN2: edit log for 1-5
  
  // Run recovery again, but don't allow JN0 to respond to the
  // prepareRecovery() call. This will cause recovery to decide
  // on txid 5.
  // Additionally, crash all of the nodes before they persist
  // any new paxos data.
  qjm = createSpyingQJM();
  spies = qjm.getLoggerSetForTests().getLoggersForTests();    
  injectIOE().when(spies.get(0)).prepareRecovery(Mockito.eq(1L));

  Mockito.doThrow(new IOException("Injected")).when(faultInjector)
    .beforePersistPaxosData();
  tryRecoveryExpectingFailure();
  Mockito.reset(faultInjector);
  
  // State at this point:
  // JN0: edit log for 1-5, paxos recovery data for txid 4
  // !!!   This is the interesting bit, above. The on-disk data and the
  //       paxos data don't match up!
  // JN1: edit log for 1-5,
  // JN2: edit log for 1-5,

  // Now, stop JN2, and see if we can still start up even though
  // JN0 is in a strange state where its log data is actually newer
  // than its accepted Paxos state.

  cluster.getJournalNode(2).stopAndJoin(0);
  
  qjm = createSpyingQJM();
  try {
    long recovered = QJMTestUtil.recoverAndReturnLastTxn(qjm);
    assertTrue(recovered >= 4); // 4 was committed to a quorum
  } finally {
    qjm.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:61,代码来源:TestQuorumJournalManager.java

示例2: testCrashBetweenSyncLogAndPersistPaxosData

import org.apache.hadoop.hdfs.qjournal.server.JournalFaultInjector; //导入依赖的package包/类
@Test(timeout=20000)
public void testCrashBetweenSyncLogAndPersistPaxosData() throws Exception {
  JournalFaultInjector faultInjector =
      JournalFaultInjector.instance = Mockito.mock(JournalFaultInjector.class);

  setupLoggers345();

  // Run recovery where the client only talks to JN0, JN1, such that it
  // decides that the correct length is through txid 4.
  // Only allow it to call acceptRecovery() on JN0.
  qjm = createSpyingQJM();
  spies = qjm.getLoggerSetForTests().getLoggersForTests();    
  cluster.getJournalNode(2).stopAndJoin(0);
  injectIOE().when(spies.get(1)).acceptRecovery(
      Mockito.<SegmentStateProto>any(), Mockito.<String>any());
  
  tryRecoveryExpectingFailure();

  cluster.restartJournalNode(2);
  
  // State at this point:
  // JN0: edit log for 1-4, paxos recovery data for txid 4
  // JN1: edit log for 1-4,
  // JN2: edit log for 1-5
  
  // Run recovery again, but don't allow JN0 to respond to the
  // prepareRecovery() call. This will cause recovery to decide
  // on txid 5.
  // Additionally, crash all of the nodes before they persist
  // any new paxos data.
  qjm = createSpyingQJM();
  spies = qjm.getLoggerSetForTests().getLoggersForTests();    
  injectIOE().when(spies.get(0)).prepareRecovery(Mockito.eq(1L));

  Mockito.doThrow(new IOException("Injected")).when(faultInjector)
    .beforePersistPaxosData();
  tryRecoveryExpectingFailure();
  Mockito.reset(faultInjector);
  
  // State at this point:
  // JN0: edit log for 1-5, paxos recovery data for txid 4
  // !!!   This is the interesting bit, above. The on-disk data and the
  //       paxos data don't match up!
  // JN1: edit log for 1-5,
  // JN2: edit log for 1-5,

  // Now, stop JN2, and see if we can still start up even though
  // JN0 is in a strange state where its log data is actually newer
  // than its accepted Paxos state.

  cluster.getJournalNode(2).stopAndJoin(0);
  
  qjm = createSpyingQJM();
  try {
    long recovered = QJMTestUtil.recoverAndReturnLastTxn(qjm);
    assertTrue(recovered >= 4); // 4 was committed to a quorum
  } finally {
    qjm.close();
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:61,代码来源:TestQuorumJournalManager.java


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