当前位置: 首页>>代码示例>>Java>>正文


Java CreateBuilder类代码示例

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


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

示例1: shouldCreateSetupInProgressNode

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Test
public void shouldCreateSetupInProgressNode() throws Exception {
    Set<SetupStep> steps = new LinkedHashSet<>();
    SetupStep setupStep1 = mock(SetupStep.class);
    steps.add(setupStep1);

    when(configuration.
            getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
            thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("digest:user:pwd");

    List<ACL> aclList = Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("digest", "user:pwd")));
    setupServerIdSelectionMocks();
    CreateBuilder createBuilder = setupSetupInProgressPathMocks(aclList).getLeft();

    InterProcessMutex lock = mock(InterProcessMutex.class);
    when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
            thenReturn(lock);
    SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
    setupSteps.runSetup();

    verify(createBuilder).withACL(aclList);
    verify(createBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT+SetupSteps.SETUP_IN_PROGRESS_NODE,
            "id2".getBytes(Charsets.UTF_8));
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:26,代码来源:SetupStepsTest.java

示例2: testStart

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的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

示例3: testDeletesEphemeralNode

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的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

示例4: createNonExisting

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
public void createNonExisting() throws Exception {
	CuratorFramework client = mock(CuratorFramework.class);
	ExistsBuilder builder = mock(ExistsBuilder.class);
	CreateBuilder createBuilder = mock(CreateBuilder.class);
	
	
	//ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
	when(builder.forPath(anyString())).thenReturn(null);
	when(client.checkExists()).thenReturn(builder);
	when(client.create()).thenReturn(createBuilder);
	//when(createBuilder.creatingParentContainersIfNeeded()).thenReturn((ProtectACLCreateModeStatPathAndBytesable<String>)protector);
	new DistributedLockServiceCuratorImpl(client, "/", 0);
	//verify(protector).forPath(anyString(), anyObject());
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:15,代码来源:DistributedLockServiceCuratorImplTest.java

示例5: createNonExisting2

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
public void createNonExisting2() throws Exception {
	CuratorFramework client = mock(CuratorFramework.class);
	ExistsBuilder builder = mock(ExistsBuilder.class);
	CreateBuilder createBuilder = mock(CreateBuilder.class);
	
	//ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
	when(builder.forPath(anyString())).thenReturn(new Stat());
	when(client.checkExists()).thenReturn(builder);
	when(client.create()).thenReturn(createBuilder);
	//when(createBuilder.creatingParentContainersIfNeeded()).thenReturn(protector);
	new DistributedLockServiceCuratorImpl(client, "/", 0);
	//verify(protector, times(0)).forPath(anyString(), anyObject());
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:14,代码来源:DistributedLockServiceCuratorImplTest.java

示例6: writeBytes

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
public void writeBytes(String path, byte[] bytes) {
    try {
        if (_curator.checkExists().forPath(path) == null) {
            CreateBuilder builder = _curator.create();
            ProtectACLCreateModePathAndBytesable<String> createAble = (ProtectACLCreateModePathAndBytesable<String>) builder
                    .creatingParentsIfNeeded();
            createAble.withMode(CreateMode.PERSISTENT).forPath(path, bytes);
        } else {
            _curator.setData().forPath(path, bytes);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:15,代码来源:ZkState.java

示例7: createNonExisting

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Test
public void createNonExisting() throws Exception {
	CuratorFramework client = mock(CuratorFramework.class);
	ExistsBuilder builder = mock(ExistsBuilder.class);
	CreateBuilder createBuilder = mock(CreateBuilder.class);
	
	
	ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
	when(builder.forPath(anyString())).thenReturn(null);
	when(client.checkExists()).thenReturn(builder);
	when(client.create()).thenReturn(createBuilder);
	when(createBuilder.creatingParentContainersIfNeeded()).thenReturn((ProtectACLCreateModeStatPathAndBytesable<String>)protector);
	new DistributedLockServiceCuratorImpl(client, "/", 0);
	verify(protector).forPath(anyString(), anyObject());
}
 
开发者ID:aol,项目名称:micro-server,代码行数:16,代码来源:DistributedLockServiceCuratorImplTest.java

示例8: createNonExisting2

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Test
public void createNonExisting2() throws Exception {
	CuratorFramework client = mock(CuratorFramework.class);
	ExistsBuilder builder = mock(ExistsBuilder.class);
	CreateBuilder createBuilder = mock(CreateBuilder.class);
	
	ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
	when(builder.forPath(anyString())).thenReturn(new Stat());
	when(client.checkExists()).thenReturn(builder);
	when(client.create()).thenReturn(createBuilder);
	when(createBuilder.creatingParentContainersIfNeeded()).thenReturn(protector);
	new DistributedLockServiceCuratorImpl(client, "/", 0);
	verify(protector, times(0)).forPath(anyString(), anyObject());
}
 
开发者ID:aol,项目名称:micro-server,代码行数:15,代码来源:DistributedLockServiceCuratorImplTest.java

示例9: setupSetupInProgressPathMocks

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
private Pair<CreateBuilder, DeleteBuilder> setupSetupInProgressPathMocks(List<ACL> acls, Stat stat) throws Exception {
    when(curatorFactory.clientInstance()).thenReturn(client);
    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(createBuilder.withACL(acls)).thenReturn(createBuilder);
    when(client.create()).thenReturn(createBuilder);
    DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
    when(client.delete()).thenReturn(deleteBuilder);
    Pair<CreateBuilder, DeleteBuilder> pair = Pair.of(createBuilder, deleteBuilder);
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    when(client.checkExists()).thenReturn(existsBuilder);
    when(existsBuilder.forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT+SetupSteps.SETUP_IN_PROGRESS_NODE)).
            thenReturn(stat);
    return pair;
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:15,代码来源:SetupStepsTest.java

示例10: testSharedPathIsCreatedIfNotExists

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Test
public void testSharedPathIsCreatedIfNotExists() throws Exception {

    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
    when(configuration.getString(
            HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
            thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);

    when(curatorFactory.clientInstance()).thenReturn(curatorFramework);

    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(existsBuilder.forPath(getPath())).thenReturn(null);

    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(curatorFramework.create()).thenReturn(createBuilder);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
    when(createBuilder.withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)).thenReturn(createBuilder);

    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    activeInstanceState.update("id1");

    verify(createBuilder).forPath(getPath());
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:28,代码来源:ActiveInstanceStateTest.java

示例11: testSharedPathIsCreatedWithRightACLIfNotExists

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Test
public void testSharedPathIsCreatedWithRightACLIfNotExists() throws Exception {

    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
    when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("sasl:[email protected]");
    when(configuration.getString(
            HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
            thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);


    when(curatorFactory.clientInstance()).thenReturn(curatorFramework);

    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(existsBuilder.forPath(getPath())).thenReturn(null);

    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(curatorFramework.create()).thenReturn(createBuilder);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
    ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "[email protected]"));
    when(createBuilder.
            withACL(Arrays.asList(new ACL[]{expectedAcl}))).thenReturn(createBuilder);

    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    activeInstanceState.update("id1");

    verify(createBuilder).forPath(getPath());
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:32,代码来源:ActiveInstanceStateTest.java

示例12: testCreateNode

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的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

示例13: create

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Override
public CreateBuilder create() {
    return new MockCreateBuilder();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:MockCurator.java

示例14: testExceptionForwarding

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
/**
 *  Test that errors in the {@link LeaderElectionService} are correctly forwarded to the
 *  {@link LeaderContender}.
 */
@Test
public void testExceptionForwarding() throws Exception {
	ZooKeeperLeaderElectionService leaderElectionService = null;
	ZooKeeperLeaderRetrievalService leaderRetrievalService = null;
	TestingListener listener = new TestingListener();
	TestingContender testingContender;

	CuratorFramework client;
	final CreateBuilder mockCreateBuilder = mock(CreateBuilder.class, Mockito.RETURNS_DEEP_STUBS);
	final Exception testException = new Exception("Test exception");

	try {
		client = spy(ZooKeeperUtils.startCuratorFramework(configuration));

		Answer<CreateBuilder> answer = new Answer<CreateBuilder>() {
			private int counter = 0;

			@Override
			public CreateBuilder answer(InvocationOnMock invocation) throws Throwable {
				counter++;

				// at first we have to create the leader latch, there it mustn't fail yet
				if (counter < 2) {
					return (CreateBuilder) invocation.callRealMethod();
				} else {
					return mockCreateBuilder;
				}
			}
		};

		doAnswer(answer).when(client).create();

		when(
			mockCreateBuilder
			.creatingParentsIfNeeded()
			.withMode(Matchers.any(CreateMode.class))
			.forPath(anyString(), any(byte[].class))).thenThrow(testException);

		leaderElectionService = new ZooKeeperLeaderElectionService(client, "/latch", "/leader");
		leaderRetrievalService = ZooKeeperUtils.createLeaderRetrievalService(client, configuration);

		testingContender = new TestingContender(TEST_URL, leaderElectionService);

		leaderElectionService.start(testingContender);
		leaderRetrievalService.start(listener);

		testingContender.waitForError(timeout.toMillis());

		assertNotNull(testingContender.getError());
		assertEquals(testException, testingContender.getError().getCause());
	} finally {
		if (leaderElectionService != null) {
			leaderElectionService.stop();
		}

		if (leaderRetrievalService != null) {
			leaderRetrievalService.stop();
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:65,代码来源:ZooKeeperLeaderElectionTest.java

示例15: create

import org.apache.curator.framework.api.CreateBuilder; //导入依赖的package包/类
@Override
public CreateBuilder create() {
    return namespaceDelegate().create();
}
 
开发者ID:ReadyTalk,项目名称:cultivar,代码行数:5,代码来源:NamespacedCuratorFramework.java


注:本文中的org.apache.curator.framework.api.CreateBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。