當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。