gpt4 book ai didi

org.apache.samza.zk.ZkUtils.registerProcessorAndGetId()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 22:25:31 27 4
gpt4 key购买 nike

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

ZkUtils.registerProcessorAndGetId介绍

[英]Returns a ZK generated identifier for this client. If the current client is registering for the first time, it creates an ephemeral sequential node in the ZK tree If the current client has already registered and is still within the same session, it returns the already existing value for the ephemeralPath
[中]返回此客户端的ZK生成的标识符。如果当前客户端是第一次注册,它会在ZK树中创建一个临时顺序节点。如果当前客户端已经注册并且仍在同一会话中,它会返回临时路径的现有值

代码示例

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

String currentPath = zkUtils.registerProcessorAndGetId(new ProcessorData(hostName, processorIdStr));

代码示例来源:origin: org.apache.samza/samza-core_2.12

String currentPath = zkUtils.registerProcessorAndGetId(new ProcessorData(hostName, processorIdStr));

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

@Test
public void testRegisterProcessorId() {
 String assignedPath = zkUtils.registerProcessorAndGetId(new ProcessorData("host", "1"));
 Assert.assertTrue(assignedPath.startsWith(KEY_BUILDER.getProcessorsPath()));
 // Calling registerProcessorId again should return the same ephemeralPath as long as the session is valid
 Assert.assertTrue(zkUtils.registerProcessorAndGetId(new ProcessorData("host", "1")).equals(assignedPath));
}

代码示例来源:origin: org.apache.samza/samza-core_2.11

String currentPath = zkUtils.registerProcessorAndGetId(new ProcessorData(hostName, processorIdStr));

代码示例来源:origin: org.apache.samza/samza-core

String currentPath = zkUtils.registerProcessorAndGetId(new ProcessorData(hostName, processorIdStr));

代码示例来源:origin: org.apache.samza/samza-core_2.10

String currentPath = zkUtils.registerProcessorAndGetId(new ProcessorData(hostName, processorIdStr));

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

@Test
public void testGetActiveProcessors() {
 Assert.assertEquals(0, zkUtils.getSortedActiveProcessorsZnodes().size());
 zkUtils.registerProcessorAndGetId(new ProcessorData("processorData", "1"));
 Assert.assertEquals(1, zkUtils.getSortedActiveProcessorsZnodes().size());
}

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

@Test
public void testLeaderElectionRegistersProcessor() {
 List<String> activeProcessors = new ArrayList<String>() {
  {
   add("0000000000");
  }
 };
 ZkUtils mockZkUtils = mock(ZkUtils.class);
 when(mockZkUtils.registerProcessorAndGetId(any())).
   thenReturn(KEY_BUILDER.getProcessorsPath() + "/0000000000");
 when(mockZkUtils.getSortedActiveProcessorsZnodes()).thenReturn(activeProcessors);
 Mockito.doNothing().when(mockZkUtils).validatePaths(any(String[].class));
 ZkKeyBuilder kb = mock(ZkKeyBuilder.class);
 when(kb.getProcessorsPath()).thenReturn("");
 when(mockZkUtils.getKeyBuilder()).thenReturn(kb);
 ZkLeaderElector leaderElector = new ZkLeaderElector("1", mockZkUtils, null);
 BooleanResult isLeader = new BooleanResult();
 leaderElector.setLeaderElectorListener(() -> isLeader.res = true);
 leaderElector.tryBecomeLeader();
 Assert.assertTrue(TestZkUtils.testWithDelayBackOff(() -> isLeader.res, 2, 100));
}

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

@Test
public void testDeleteProcessorNodeShouldDeleteTheCorrectProcessorNode() {
 String testProcessorId1 = "processorId1";
 String testProcessorId2 = "processorId2";
 ZkUtils zkUtils = getZkUtils();
 ZkUtils zkUtils1 = getZkUtils();
 zkUtils.registerProcessorAndGetId(new ProcessorData("host1", testProcessorId1));
 zkUtils1.registerProcessorAndGetId(new ProcessorData("host2", testProcessorId2));
 zkUtils.deleteProcessorNode(testProcessorId1);
 List<String> expectedProcessors = ImmutableList.of(testProcessorId2);
 List<String> actualProcessors = zkUtils.getSortedActiveProcessorsIDs();
 Assert.assertEquals(expectedProcessors, actualProcessors);
}

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

/**
 * Create two duplicate processors with same processorId.
 * Second creation should fail with exception.
 */
@Test
public void testRegisterProcessorAndGetIdShouldFailForDuplicateProcessorRegistration() {
 final String testHostName = "localhost";
 final String testProcessId = "testProcessorId";
 ProcessorData processorData1 = new ProcessorData(testHostName, testProcessId);
 // Register processor 1 which is not duplicate, this registration should succeed.
 zkUtils.registerProcessorAndGetId(processorData1);
 ZkUtils zkUtils1 = getZkUtils();
 zkUtils1.connect();
 ProcessorData duplicateProcessorData = new ProcessorData(testHostName, testProcessId);
 // Registration of the duplicate processor should fail.
 expectedException.expect(SamzaException.class);
 zkUtils1.registerProcessorAndGetId(duplicateProcessorData);
}

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

@Test
public void testGetProcessorsIDs() {
 Assert.assertEquals(0, zkUtils.getSortedActiveProcessorsIDs().size());
 zkUtils.registerProcessorAndGetId(new ProcessorData("host1", "1"));
 List<String> l = zkUtils.getSortedActiveProcessorsIDs();
 Assert.assertEquals(1, l.size());
 new ZkUtils(KEY_BUILDER, zkClient, CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()).registerProcessorAndGetId(
   new ProcessorData("host2", "2"));
 l = zkUtils.getSortedActiveProcessorsIDs();
 Assert.assertEquals(2, l.size());
 Assert.assertEquals(" ID1 didn't match", "1", l.get(0));
 Assert.assertEquals(" ID2 didn't match", "2", l.get(1));
}

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

zkUtils1.registerProcessorAndGetId(new ProcessorData("processor1", "1"));
ZkLeaderElector leaderElector1 = new ZkLeaderElector("processor1", zkUtils1, new IZkDataListener() {
  @Override
zkUtils2.registerProcessorAndGetId(new ProcessorData("processor2", "2"));
ZkLeaderElector leaderElector2 = new ZkLeaderElector("processor2", zkUtils2, new IZkDataListener() {
 @Override
final String path3 = zkUtils3.registerProcessorAndGetId(new ProcessorData("processor3", "3"));
ZkLeaderElector leaderElector3 = new ZkLeaderElector("processor3", zkUtils3, new IZkDataListener() {
 @Override

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

zkUtils1.registerProcessorAndGetId(new ProcessorData("processor1", "1"));
ZkLeaderElector leaderElector1 = new ZkLeaderElector("processor1", zkUtils1, new IZkDataListener() {
 @Override
final String path2 = zkUtils2.registerProcessorAndGetId(new ProcessorData("processor2", "2"));
ZkLeaderElector leaderElector2 = new ZkLeaderElector("processor2", zkUtils2, new IZkDataListener() {
 @Override
zkUtils3.registerProcessorAndGetId(new ProcessorData("processor3", "3"));
ZkLeaderElector leaderElector3 = new ZkLeaderElector("processor3", zkUtils3, new IZkDataListener() {
 @Override

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com