org.easymock.EasyMock.makeThreadSafe()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中org.easymock.EasyMock.makeThreadSafe()方法的一些代码示例,展示了EasyMock.makeThreadSafe()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.makeThreadSafe()方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:makeThreadSafe

EasyMock.makeThreadSafe介绍

[英]By default, a mock is thread safe (unless #NOT_THREAD_SAFE_BY_DEFAULT is set). This method can change this behavior. Two reasons are known for someone to do that: Performance or dead-locking issues.
[中]默认情况下,模拟是线程安全的(除非设置了#NOT_thread_safe_By_default)。此方法可以更改此行为。有人这样做有两个原因:性能或死锁问题。

代码示例

代码示例来源:origin: org.apache.shindig/shindig-gadgets

@Before
public void setUp() throws Exception {
 cacheMock = new MockProvider();
 exportResponseMock = mockJsResponse(EXPORT_COMPILER_STRING);
 compilerMock = mockDefaultJsCompiler(exportResponseMock, EXPORT_COMPILER_CONTENTS);
 executorServiceMock = EasyMock.createMock(ExecutorService.class);
 EasyMock.makeThreadSafe(executorServiceMock, true);
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets

@Before
public void setUp() throws Exception {
 cacheMock = new MockProvider();
 exportResponseMock = mockJsResponse(EXPORT_COMPILER_STRING);
 compilerMock = mockDefaultJsCompiler(exportResponseMock, EXPORT_COMPILER_CONTENTS);
 executorServiceMock = EasyMock.createMock(ExecutorService.class);
 EasyMock.makeThreadSafe(executorServiceMock, true);
}

代码示例来源:origin: huxi/sulky

@Test
public void timeoutInFlush()
  throws IOException
{
  OutputStream mockStream = createStrictMock(OutputStream.class);
  makeThreadSafe(mockStream, true);
  mockStream.flush();
  expectLastCall().andAnswer(() -> {
    Thread.sleep(300);
    return null;
  });
  mockStream.close();
  replay(mockStream);
  TimeoutOutputStream instance = new TimeoutOutputStream(mockStream, 100);
  assertFalse("Stream is already closed!", instance.isClosed());
  assertTrue("Watchdog Thread is not running!", instance.isWatchdogThreadRunning());
  instance.flush(); // would throw exception in case of a real output stream.
  waitForSomeTime();
  verify(mockStream);
  assertTrue("Stream is not closed!", instance.isClosed());
  assertFalse("Watchdog Thread is still running!", instance.isWatchdogThreadRunning());
}

代码示例来源:origin: huxi/sulky

@Test
public void timeoutInWriteByte()
  throws IOException
{
  OutputStream mockStream = createStrictMock(OutputStream.class);
  makeThreadSafe(mockStream, true);
  mockStream.write(eq(17));
  expectLastCall().andAnswer(() -> {
    Thread.sleep(300);
    return null;
  });
  mockStream.close();
  replay(mockStream);
  TimeoutOutputStream instance = new TimeoutOutputStream(mockStream, 100);
  assertFalse("Stream is already closed!", instance.isClosed());
  assertTrue("Watchdog Thread is not running!", instance.isWatchdogThreadRunning());
  instance.write(17); // would throw exception in case of a real output stream.
  waitForSomeTime();
  verify(mockStream);
  assertTrue("Stream is not closed!", instance.isClosed());
  assertFalse("Watchdog Thread is still running!", instance.isWatchdogThreadRunning());
}

代码示例来源:origin: huxi/sulky

@Test
public void timeoutInWriteByteArray()
  throws IOException
{
  byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
  OutputStream mockStream = createStrictMock(OutputStream.class);
  makeThreadSafe(mockStream, true);
  mockStream.write(eq(bytes));
  expectLastCall().andAnswer(() -> {
    Thread.sleep(300);
    return null;
  });
  mockStream.close();
  replay(mockStream);
  TimeoutOutputStream instance = new TimeoutOutputStream(mockStream, 100);
  assertFalse("Stream is already closed!", instance.isClosed());
  assertTrue("Watchdog Thread is not running!", instance.isWatchdogThreadRunning());
  instance.write(bytes); // would throw exception in case of a real output stream.
  waitForSomeTime();
  verify(mockStream);
  assertTrue("Stream is not closed!", instance.isClosed());
  assertFalse("Watchdog Thread is still running!", instance.isWatchdogThreadRunning());
}

代码示例来源:origin: huxi/sulky

@Test
public void timeoutInClose()
  throws IOException
{
  OutputStream mockStream = createStrictMock(OutputStream.class);
  makeThreadSafe(mockStream, true);
  mockStream.close();
  expectLastCall().andAnswer(() -> {
    Thread.sleep(300);
    return null;
  });
  replay(mockStream);
  TimeoutOutputStream instance = new TimeoutOutputStream(mockStream, 100);
  assertFalse("Stream is already closed!", instance.isClosed());
  assertTrue("Watchdog Thread is not running!", instance.isWatchdogThreadRunning());
  instance.close(); // would throw exception in case of a real output stream.
  waitForSomeTime();
  verify(mockStream);
  assertTrue("Stream is not closed!", instance.isClosed());
  assertFalse("Watchdog Thread is still running!", instance.isWatchdogThreadRunning());
}

代码示例来源:origin: huxi/sulky

@Test
public void timeoutInWriteByteArrayOffset()
  throws IOException
{
  byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
  OutputStream mockStream = createStrictMock(OutputStream.class);
  makeThreadSafe(mockStream, true);
  mockStream.write(eq(bytes), eq(0), eq(5));
  expectLastCall().andAnswer(() -> {
    Thread.sleep(300);
    return null;
  });
  mockStream.close();
  replay(mockStream);
  TimeoutOutputStream instance = new TimeoutOutputStream(mockStream, 100);
  assertFalse("Stream is already closed!", instance.isClosed());
  assertTrue("Watchdog Thread is not running!", instance.isWatchdogThreadRunning());
  instance.write(bytes, 0, 5); // would throw exception in case of a real output stream.
  waitForSomeTime();
  verify(mockStream);
  assertTrue("Stream is not closed!", instance.isClosed());
  assertFalse("Watchdog Thread is still running!", instance.isWatchdogThreadRunning());
}

相关文章