org.apache.storm.utils.Utils.setInstance()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(104)

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

Utils.setInstance介绍

[英]Provide an instance of this class for delegates to use. To mock out delegated methods, provide an instance of a subclass that overrides the implementation of the delegated method.
[中]提供此类的实例供代理使用。要模拟委托方法,请提供重写委托方法实现的子类的实例。

代码示例

代码示例来源:origin: apache/storm

public UtilsInstaller(Utils instance) {
  _oldInstance = Utils.setInstance(instance);
  _curInstance = instance;
}

代码示例来源:origin: apache/storm

@Override
  public void close() throws Exception {
    if (Utils.setInstance(_oldInstance) != _curInstance) {
      throw new IllegalStateException(
        "Instances of this resource must be closed in reverse order of opening.");
    }
  }
}

代码示例来源:origin: apache/storm

@Test
public void testLogviewerLinkCentersTheMatchInThePage() throws UnknownHostException {
  String expectedFname = "foobar.log";
  LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
  Utils prevUtils = null;
  try {
    Utils mockedUtil = mock(Utils.class);
    prevUtils = Utils.setInstance(mockedUtil);
    when(mockedUtil.hostname()).thenReturn(expectedHost);
    String actualUrl = handler.urlToMatchCenteredInLogPage(new byte[42], new File(expectedFname).toPath(), 27526, 8888);
    assertEquals("http://" + expectedHost + ":" + expectedPort + "/api/v1/log?file=" + expectedFname
        + "&start=1947&length=" + LogviewerConstant.DEFAULT_BYTES_PER_PAGE, actualUrl);
  } finally {
    Utils.setInstance(prevUtils);
  }
}

代码示例来源:origin: apache/storm

@Test
public void testLogviewerLinkCentersTheMatchInThePageDaemon() throws UnknownHostException {
  String expectedFname = "foobar.log";
  LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
  Utils prevUtils = null;
  try {
    Utils mockedUtil = mock(Utils.class);
    prevUtils = Utils.setInstance(mockedUtil);
    when(mockedUtil.hostname()).thenReturn(expectedHost);
    String actualUrl = handler.urlToMatchCenteredInLogPageDaemonFile(new byte[42], new File(expectedFname).toPath(), 27526, 8888);
    assertEquals("http://" + expectedHost + ":" + expectedPort + "/api/v1/daemonlog?file=" + expectedFname
        + "&start=1947&length=" + LogviewerConstant.DEFAULT_BYTES_PER_PAGE, actualUrl);
  } finally {
    Utils.setInstance(prevUtils);
  }
}

代码示例来源:origin: apache/storm

@Test
public void testReturnsZeroMatchesForUnseenPattern() throws UnknownHostException, InvalidRequestException {
  Utils prevUtils = null;
  try {
    Utils mockedUtil = mock(Utils.class);
    prevUtils = Utils.setInstance(mockedUtil);
    String pattern = "Not There";
    when(mockedUtil.hostname()).thenReturn(expectedHost);
    final File file = new File(String.join(File.separator, "src", "test", "resources"),
        "test-worker.log.test");
    Map<String, Object> expected = new HashMap<>();
    expected.put("isDaemon", "no");
    expected.put("searchString", pattern);
    expected.put("startByteOffset", 0);
    expected.put("matches", Collections.emptyList());
    LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
    Map<String, Object> searchResult = handler.substringSearch(file, pattern);
    assertEquals(expected, searchResult);
  } finally {
    Utils.setInstance(prevUtils);
  }
}

代码示例来源:origin: apache/storm

@Test
public void testAreallySmallLogDaemonFile() throws InvalidRequestException, UnknownHostException {
  Utils prevUtils = null;
  try {
    Utils mockedUtil = mock(Utils.class);
    prevUtils = Utils.setInstance(mockedUtil);
    when(mockedUtil.hostname()).thenReturn(expectedHost);
    final File file = new File(String.join(File.separator, "src", "test", "resources"),
        "small-worker.log.test");
    Map<String, Object> expected = new HashMap<>();
    expected.put("isDaemon", "yes");
    expected.put("searchString", pattern);
    expected.put("startByteOffset", 0);
    List<Map<String, Object>> matches = new ArrayList<>();
    matches.add(buildMatchData(7, "000000 ",
        " 000000\n",
        pattern,
        "/api/v1/daemonlog?file=" + file.getName() + "&start=0&length=51200"
    ));
    expected.put("matches", matches);
    LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
    Map<String, Object> searchResult = handler.substringSearchDaemonLog(file, pattern);
    assertEquals(expected, searchResult);
  } finally {
    Utils.setInstance(prevUtils);
  }
}

代码示例来源:origin: apache/storm

try {
  Utils mockedUtil = mock(Utils.class);
  prevUtils = Utils.setInstance(mockedUtil);
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

@Test
public void testAreallySmallLogFile() throws Exception {
  Utils prevUtils = null;
  try {
    Utils mockedUtil = mock(Utils.class);
    prevUtils = Utils.setInstance(mockedUtil);
    when(mockedUtil.hostname()).thenReturn(expectedHost);
    final File file = new File(String.join(File.separator, "src", "test", "resources"),
        "small-worker.log.test");
    Map<String, Object> expected = new HashMap<>();
    expected.put("isDaemon", "no");
    expected.put("searchString", pattern);
    expected.put("startByteOffset", 0);
    List<Map<String, Object>> matches = new ArrayList<>();
    matches.add(buildMatchData(7, "000000 ",
        " 000000\n",
        pattern,
        "/api/v1/log?file=test" + encodedFileSeparator() + "resources" + encodedFileSeparator() + file.getName()
          + "&start=0&length=51200"
    ));
    expected.put("matches", matches);
    LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
    Map<String, Object> searchResult = handler.substringSearch(file, pattern);
    
    assertEquals(expected, searchResult);
  } finally {
    Utils.setInstance(prevUtils);
  }
}

代码示例来源:origin: apache/storm

try {
  Utils mockedUtil = mock(Utils.class);
  prevUtils = Utils.setInstance(mockedUtil);
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockedUtil = mock(Utils.class);
  prevUtils = Utils.setInstance(mockedUtil);
  assertEquals(expected, searchResult2);
} finally {
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockedUtil = mock(Utils.class);
  prevUtils = Utils.setInstance(mockedUtil);
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockedUtil = mock(Utils.class);
  prevUtils = Utils.setInstance(mockedUtil);
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockUtils = mock(Utils.class);
  prevUtils = Utils.setInstance(mockUtils);
  assertEquals(mockFile2.getCanonicalPath(), forceDeleteArgs.get(1));
} finally {
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockedUtil = mock(Utils.class);
  prevUtils = Utils.setInstance(mockedUtil);
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockUtils = mock(Utils.class);
  prevUtils = Utils.setInstance(mockUtils);
  assertEquals(Integer.valueOf(4), deletedFiles.get(deletedFiles.size() - 1));
} finally {
  Utils.setInstance(prevUtils);

代码示例来源:origin: apache/storm

try {
  Utils mockUtils = mock(Utils.class);
  prevUtils = Utils.setInstance(mockUtils);
  assertEquals(18, deletedFiles);
} finally {
  Utils.setInstance(prevUtils);

相关文章

微信公众号

最新文章

更多

Utils类方法