• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ACLBackgroundPathAndBytesable类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.apache.curator.framework.api.ACLBackgroundPathAndBytesable的典型用法代码示例。如果您正苦于以下问题:Java ACLBackgroundPathAndBytesable类的具体用法?Java ACLBackgroundPathAndBytesable怎么用?Java ACLBackgroundPathAndBytesable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ACLBackgroundPathAndBytesable类属于org.apache.curator.framework.api包,在下文中一共展示了ACLBackgroundPathAndBytesable类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testStart

点赞 3

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testStart() throws Exception {
    CuratorFramework framework = mockFramework();
    ExistsBuilder ceBuilder = mock(ExistsBuilder.class);
    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(framework.checkExists()).thenReturn(ceBuilder);
    when(ceBuilder.forPath("/services/myservice/nodes")).thenReturn(mock(Stat.class));
    when(framework.create()).thenReturn(createBuilder);
    when(framework.getState()).thenReturn(CuratorFrameworkState.STARTED);
    ACLBackgroundPathAndBytesable<String> os = mock(ACLBackgroundPathAndBytesable.class);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(os);
    DiscoService service = new DiscoService(framework, "myservice");
    byte[] payload = "foo bar baz bingo".getBytes();
    service.start("foo", 4321, true, payload);
    verify(os).forPath(eq("/services/myservice/nodes/foo:4321"), eq(payload));
}
 

开发者ID:librato,
项目名称:disco-java
代码行数:18,
代码来源:DiscoServiceTest.java

示例2: testDeletesEphemeralNode

点赞 3

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testDeletesEphemeralNode() throws Exception {
    CuratorFramework framework = mockFramework();
    ExistsBuilder ceBuilder = mock(ExistsBuilder.class);
    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(framework.checkExists()).thenReturn(ceBuilder);
    when(ceBuilder.forPath("/services/myservice/nodes")).thenReturn(mock(Stat.class));
    when(ceBuilder.forPath("/services/myservice/nodes/foo:4321")).thenReturn(mock(Stat.class));
    when(framework.create()).thenReturn(createBuilder);
    when(framework.getState()).thenReturn(CuratorFrameworkState.STARTED);
    DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
    when(framework.delete()).thenReturn(deleteBuilder);
    ACLBackgroundPathAndBytesable<String> os = mock(ACLBackgroundPathAndBytesable.class);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(os);
    DiscoService service = new DiscoService(framework, "myservice");
    byte[] payload = "foo bar baz bingo".getBytes();
    service.start("foo", 4321, true, payload);
    verify(deleteBuilder).forPath("/services/myservice/nodes/foo:4321");
    verify(os).forPath(eq("/services/myservice/nodes/foo:4321"), eq(payload));
}
 

开发者ID:librato,
项目名称:disco-java
代码行数:22,
代码来源:DiscoServiceTest.java

示例3: createPath

点赞 2

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
public static void createPath(CuratorFramework client, String path, String content, CreateMode mode) {
    try {
        ((ACLBackgroundPathAndBytesable) client.create().creatingParentsIfNeeded().withMode(mode))
                .forPath(path, List2StringUtil.toBytes(content));
    } catch (Exception e) {
        LOGGER.error("ZKUtil-->>createPath(CuratorFramework client, String path, String content, CreateMode mode) error,", e);
    }
}
 

开发者ID:classtag,
项目名称:scratch_zookeeper_netty,
代码行数:9,
代码来源:ZKUtil.java

示例4: setPath

点赞 2

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
public static void setPath(CuratorFramework client, String path, String content, CreateMode mode) {
    try {
        if (client.checkExists().forPath(path) == null) {
            ((ACLBackgroundPathAndBytesable) client.create().creatingParentsIfNeeded().withMode(mode))
                    .forPath(path, List2StringUtil.toBytes(content));
        } else { client.setData().forPath(path, List2StringUtil.toBytes(content)); }
    } catch (Exception e) {
        LOGGER.error("ZKUtil-->>setPath(CuratorFramework client, String path, String content, CreateMode mode) error,", e);
    }
}
 

开发者ID:classtag,
项目名称:scratch_zookeeper_netty,
代码行数:11,
代码来源:ZKUtil.java

示例5: createEphemeralSequential

点赞 2

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
public static String createEphemeralSequential(CuratorFramework client, String path, byte[] payload) {
    try {
        return (String) ((ACLBackgroundPathAndBytesable) client.create().withProtection()
                                                               .withMode(CreateMode.EPHEMERAL_SEQUENTIAL))
                .forPath(path, payload);
    } catch (Exception e) {
        LOGGER.error("ZKUtil-->>createEphemeralSequential", e);
    }
    return null;
}
 

开发者ID:classtag,
项目名称:scratch_zookeeper_netty,
代码行数:11,
代码来源:ZKUtil.java

示例6: testCreateNode

点赞 2

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
/**
 * test createNode method
 * @throws Exception
 */
@Test
public void testCreateNode() throws Exception {
  CuratorStateManager spyStateManager = spy(new CuratorStateManager());
  CuratorFramework mockClient = mock(CuratorFramework.class);
  CreateBuilder mockCreateBuilder = mock(CreateBuilder.class);
  // Mockito doesn't support mock type-parametrized class, thus suppress the warning
  @SuppressWarnings("rawtypes")
  ACLBackgroundPathAndBytesable mockPath = spy(ACLBackgroundPathAndBytesable.class);

  final byte[] data = new byte[10];

  doReturn(mockClient)
      .when(spyStateManager).getCuratorClient();
  doReturn(true)
      .when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
  doReturn(mockCreateBuilder)
      .when(mockClient).create();
  doReturn(mockPath)
      .when(mockCreateBuilder).withMode(any(CreateMode.class));

  spyStateManager.initialize(config);

  // Verify the node is created successfully
  ListenableFuture<Boolean> result = spyStateManager.createNode(PATH, data, false);
  verify(mockCreateBuilder).withMode(any(CreateMode.class));
  verify(mockPath).forPath(PATH, data);
  assertTrue(result.get());
}
 

开发者ID:twitter,
项目名称:heron,
代码行数:33,
代码来源:CuratorStateManagerTest.java

示例7: withMode

点赞 2

import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable; //导入依赖的package包/类
public ACLBackgroundPathAndBytesable<T> withMode(CreateMode createMode) {
    throw new UnsupportedOperationException("Not implemented in MockCurator");
}
 

开发者ID:vespa-engine,
项目名称:vespa,
代码行数:4,
代码来源:MockCurator.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)