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


Java InvocationOnMock.callRealMethod方法代码示例

本文整理汇总了Java中org.mockito.invocation.InvocationOnMock.callRealMethod方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationOnMock.callRealMethod方法的具体用法?Java InvocationOnMock.callRealMethod怎么用?Java InvocationOnMock.callRealMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mockito.invocation.InvocationOnMock的用法示例。


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

示例1: answer

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
  boolean interrupted = false;
  try {
    Thread.sleep(r.nextInt(maxSleepTime));
  } catch (InterruptedException ie) {
    interrupted = true;
  }
  try {
    return invocation.callRealMethod();
  } finally {
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:GenericTestUtils.java

示例2: answer

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
  Object[] args = invocation.getArguments();
  StorageDirectory sd = (StorageDirectory)args[1];

  if (count++ == 1) {
    LOG.info("Injecting fault for sd: " + sd);
    if (throwRTE) {
      throw new RuntimeException("Injected fault: saveFSImage second time");
    } else {
      throw new IOException("Injected fault: saveFSImage second time");
    }
  }
  LOG.info("Not injecting fault for sd: " + sd);
  return (Void)invocation.callRealMethod();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestSaveNamespace.java

示例3: answer

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
  if (r.nextBoolean()) {
    LOG.info("Throwing an exception for svc " + svcIdx);
    throw new HealthCheckFailedException("random failure");
  }
  return invocation.callRealMethod();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:9,代码来源:TestZKFailoverControllerStress.java

示例4: passThrough

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
protected Object passThrough(InvocationOnMock invocation) throws Throwable {
  try {
    Object ret = invocation.callRealMethod();
    returnValue = ret;
    return ret;
  } catch (Throwable t) {
    thrown = t;
    throw t;
  } finally {
    resultCounter.incrementAndGet();
    resultLatch.countDown();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:14,代码来源:GenericTestUtils.java

示例5: answer

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public ListenableFuture<T> answer(InvocationOnMock invocation)
    throws Throwable {
  if (r.nextFloat() < faultProbability) {
    return Futures.immediateFailedFuture(
        new IOException("Injected fault"));
  }
  return (ListenableFuture<T>)invocation.callRealMethod();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:11,代码来源:TestEpochsAreUnique.java

示例6: createIOEScannerTable

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
/**
 * Create a table that IOE's on first scanner next call
 * 
 * @throws IOException
 */
static Table createIOEScannerTable(byte[] name, final int failCnt)
    throws IOException {
  // build up a mock scanner stuff to fail the first time
  Answer<ResultScanner> a = new Answer<ResultScanner>() {
    int cnt = 0;

    @Override
    public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
      // first invocation return the busted mock scanner
      if (cnt++ < failCnt) {
        // create mock ResultScanner that always fails.
        Scan scan = mock(Scan.class);
        doReturn("bogus".getBytes()).when(scan).getStartRow(); // avoid npe
        ResultScanner scanner = mock(ResultScanner.class);
        // simulate TimeoutException / IOException
        doThrow(new IOException("Injected exception")).when(scanner).next();
        return scanner;
      }

      // otherwise return the real scanner.
      return (ResultScanner) invocation.callRealMethod();
    }
  };

  Table htable = spy(createTable(name));
  doAnswer(a).when(htable).getScanner((Scan) anyObject());
  return htable;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:34,代码来源:TestTableInputFormat.java

示例7: createDNRIOEScannerTable

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
/**
 * Create a table that throws a DoNoRetryIOException on first scanner next
 * call
 * 
 * @throws IOException
 */
static Table createDNRIOEScannerTable(byte[] name, final int failCnt)
    throws IOException {
  // build up a mock scanner stuff to fail the first time
  Answer<ResultScanner> a = new Answer<ResultScanner>() {
    int cnt = 0;

    @Override
    public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
      // first invocation return the busted mock scanner
      if (cnt++ < failCnt) {
        // create mock ResultScanner that always fails.
        Scan scan = mock(Scan.class);
        doReturn("bogus".getBytes()).when(scan).getStartRow(); // avoid npe
        ResultScanner scanner = mock(ResultScanner.class);

        invocation.callRealMethod(); // simulate NotServingRegionException
        doThrow(
            new NotServingRegionException("Injected simulated TimeoutException"))
            .when(scanner).next();
        return scanner;
      }

      // otherwise return the real scanner.
      return (ResultScanner) invocation.callRealMethod();
    }
  };

  Table htable = spy(createTable(name));
  doAnswer(a).when(htable).getScanner((Scan) anyObject());
  return htable;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:38,代码来源:TestTableInputFormat.java

示例8: createIOEScannerTable

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
/**
 * Create a table that IOE's on first scanner next call
 *
 * @throws IOException
 */
static Table createIOEScannerTable(byte[] name, final int failCnt)
    throws IOException {
  // build up a mock scanner stuff to fail the first time
  Answer<ResultScanner> a = new Answer<ResultScanner>() {
    int cnt = 0;

    @Override
    public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
      // first invocation return the busted mock scanner
      if (cnt++ < failCnt) {
        // create mock ResultScanner that always fails.
        Scan scan = mock(Scan.class);
        doReturn("bogus".getBytes()).when(scan).getStartRow(); // avoid npe
        ResultScanner scanner = mock(ResultScanner.class);
        // simulate TimeoutException / IOException
        doThrow(new IOException("Injected exception")).when(scanner).next();
        return scanner;
      }

      // otherwise return the real scanner.
      return (ResultScanner) invocation.callRealMethod();
    }
  };

  Table htable = spy(createTable(name));
  doAnswer(a).when(htable).getScanner((Scan) anyObject());
  return htable;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:34,代码来源:TestTableInputFormat.java

示例9: createDNRIOEScannerTable

import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
/**
 * Create a table that throws a NotServingRegionException on first scanner 
 * next call
 *
 * @throws IOException
 */
static Table createDNRIOEScannerTable(byte[] name, final int failCnt)
    throws IOException {
  // build up a mock scanner stuff to fail the first time
  Answer<ResultScanner> a = new Answer<ResultScanner>() {
    int cnt = 0;

    @Override
    public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
      // first invocation return the busted mock scanner
      if (cnt++ < failCnt) {
        // create mock ResultScanner that always fails.
        Scan scan = mock(Scan.class);
        doReturn("bogus".getBytes()).when(scan).getStartRow(); // avoid npe
        ResultScanner scanner = mock(ResultScanner.class);

        invocation.callRealMethod(); // simulate NotServingRegionException 
        doThrow(
            new NotServingRegionException("Injected simulated TimeoutException"))
            .when(scanner).next();
        return scanner;
      }

      // otherwise return the real scanner.
      return (ResultScanner) invocation.callRealMethod();
    }
  };

  Table htable = spy(createTable(name));
  doAnswer(a).when(htable).getScanner((Scan) anyObject());
  return htable;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:38,代码来源:TestTableInputFormat.java


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