io.pravega.segmentstore.server.host.ZKSegmentContainerMonitor.initialize()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(71)

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

ZKSegmentContainerMonitor.initialize介绍

[英]Initialize the monitor. This will start the monitor thread which will process the start/stop container events.
[中]初始化监视器。这将启动监视器线程,该线程将处理启动/停止容器事件。

代码示例

代码示例来源:origin: pravega/pravega

/**
 * Initialize the monitor. This will start the monitor thread which will process the start/stop container events.
 */
public void initialize() {
  initialize(MONITOR_INTERVAL);
}

代码示例来源:origin: pravega/pravega

@Override
public void initialize() {
  Exceptions.checkNotClosed(closed.get(), this);
  long traceId = LoggerHelpers.traceEnter(log, "initialize");
  try {
    // Initialize the container monitor.
    this.containerMonitor.initialize();
    // Advertise this segment store to the cluster.
    this.cluster.registerHost(this.host);
    log.info("Initialized.");
    LoggerHelpers.traceLeave(log, "initialize", traceId);
  } catch (Exception ex) {
    // Need to make sure we clean up resources if we failed to initialize.
    log.error("Initialization error. Cleaning up.", ex);
    close();
    throw ex;
  }
}

代码示例来源:origin: pravega/pravega

@Test
public void testClose() throws Exception {
  @Cleanup
  CuratorFramework zkClient = startClient();
  initializeHostContainerMapping(zkClient);
  SegmentContainerRegistry containerRegistry = mock(SegmentContainerRegistry.class);
  ContainerHandle containerHandle1 = mock(ContainerHandle.class);
  when(containerHandle1.getContainerId()).thenReturn(1);
  when(containerRegistry.startContainer(eq(1), any()))
      .thenReturn(CompletableFuture.completedFuture(containerHandle1));
  when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
  ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
  segMonitor.initialize(Duration.ofSeconds(1));
  segMonitor.close();
  assertEquals(0, segMonitor.getRegisteredContainers().size());
}

代码示例来源:origin: pravega/pravega

@Cleanup
ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
segMonitor.initialize(Duration.ofSeconds(1));

代码示例来源:origin: pravega/pravega

@Test
public void testRetryOnStartFailures() throws Exception {
  @Cleanup
  CuratorFramework zkClient = startClient();
  initializeHostContainerMapping(zkClient);
  SegmentContainerRegistry containerRegistry = createMockContainerRegistry();
  @Cleanup
  ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
  segMonitor.initialize(Duration.ofSeconds(1));
  // Simulate a container that fails to start.
  CompletableFuture<ContainerHandle> failedFuture = Futures.failedFuture(new RuntimeException());
  when(containerRegistry.startContainer(eq(2), any()))
      .thenReturn(failedFuture);
  // Use ZK to send that information to the Container Manager.
  HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH);
  currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2));
  zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));
  // Verify that it does not start.
  verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
  assertEquals(0, segMonitor.getRegisteredContainers().size());
  // Now simulate success for the same container.
  ContainerHandle containerHandle = mock(ContainerHandle.class);
  when(containerHandle.getContainerId()).thenReturn(2);
  when(containerRegistry.startContainer(eq(2), any()))
      .thenReturn(CompletableFuture.completedFuture(containerHandle));
  // Verify that it retries and starts the same container again.
  verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
  Thread.sleep(2000);
  assertEquals(1, segMonitor.getRegisteredContainers().size());
}

代码示例来源:origin: pravega/pravega

@Cleanup
ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
segMonitor.initialize(Duration.ofSeconds(1));

代码示例来源:origin: pravega/pravega

@Cleanup
ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
segMonitor.initialize(Duration.ofSeconds(1));

代码示例来源:origin: pravega/pravega

/**
 * Tests if we cannot connect to ZooKeeper (the exception must be propagated to the caller).
 *
 * @throws Exception if an error occurred.
 */
@Test
public void testInitializeError() throws Exception {
  @Cleanup
  CuratorFramework zkClient = startClient();
  @Cleanup
  ZKSegmentContainerMonitor segMonitor = createContainerMonitor(createMockContainerRegistry(), zkClient);
  zkClient.close();
  AssertExtensions.assertThrows(
      "initialize() did not throw an exception when ZooKeeper could not be accessed.",
      () -> segMonitor.initialize(),
      ex -> true); // Any exception will do, as long as it is propagated.
}

代码示例来源:origin: pravega/pravega

/**
 * Test if no mapping is present in zk.
 *
 * @throws Exception if an error occurred.
 */
@Test
public void testInitializeNoMapping() throws Exception {
  @Cleanup
  CuratorFramework zkClient = startClient();
  @Cleanup
  ZKSegmentContainerMonitor segMonitor = createContainerMonitor(createMockContainerRegistry(), zkClient);
  segMonitor.initialize();
  assertEquals("Unexpected number of handles.", 0, segMonitor.getRegisteredContainers().size());
}

相关文章