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

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

java 1次浏览

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

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

示例1: getQueryOptions

点赞 2

import com.orbitz.consul.option.ImmutableQueryOptions; //导入依赖的package包/类
private ImmutableQueryOptions getQueryOptions() {

        ImmutableQueryOptions.Builder queryOptions = ImmutableQueryOptions.builder();

        if (System.getenv(Constants.CONSUL_TOKEN_ENVIRONMENT) != null) {
            queryOptions.token(System.getenv(Constants.CONSUL_TOKEN_ENVIRONMENT));
            log.debug("using token for query options");
        }

        return queryOptions.build();
    }
 

开发者ID:pellepelster,
项目名称:hivemq-consul-cluster-discovery,
代码行数:12,
代码来源:ConsulDiscoveryCallback.java

示例2: getAclToken

点赞 2

import com.orbitz.consul.option.ImmutableQueryOptions; //导入依赖的package包/类
/**
 * Method to build an ACL token in a query option.
 * 
 * @param token
 * @return QueryOption
 */
public static QueryOptions getAclToken(String token){
	
	if(token == null || token.trim().isEmpty()){
		return ImmutableQueryOptions.BLANK;
	}
	
	//ACL token for registering as a service on consul, check health and get service catalog
	ImmutableQueryOptions.Builder optionBuilder = ImmutableQueryOptions.builder().token(token);
	return optionBuilder.build();
}
 

开发者ID:bitsofinfo,
项目名称:hazelcast-consul-discovery-spi,
代码行数:17,
代码来源:ConsulUtility.java

示例3: fullPluginLifecycleWithDefaultConfiguration

点赞 2

import com.orbitz.consul.option.ImmutableQueryOptions; //导入依赖的package包/类
@Test
public void fullPluginLifecycleWithDefaultConfiguration() throws ExecutionException, InterruptedException {

    // dummy consul client
    Consul consul = mock(Consul.class);
    AgentClient agentClient = mock(AgentClient.class);
    when(consul.agentClient()).thenReturn(agentClient);

    // empty config
    ConfigurationReader configurationReader = mock(ConfigurationReader.class);
    Properties properties = new Properties();
    when(configurationReader.getProperties()).thenReturn(properties);
    Configuration configuration = new Configuration(configurationReader);

    PluginExecutorService pluginExecutorService = mock(PluginExecutorService.class);

    ConsulDiscoveryCallback callback = new ConsulDiscoveryCallback(consul, configuration, pluginExecutorService);
    callback.init("clusternode1", new ClusterNodeAddress("clusternode1-hostname", 1234));

    // check if registration job gets scheduled
    ArgumentCaptor<Runnable> runnableArgument = ArgumentCaptor.forClass(Runnable.class);
    verify(pluginExecutorService, times(2)).scheduleAtFixedRate(runnableArgument.capture(), anyLong(), eq(60l), eq(TimeUnit.SECONDS));

    // run registration job
    Runnable registrationRunnable = runnableArgument.getAllValues().get(0);
    Runnable updateRunnable = runnableArgument.getAllValues().get(1);

    registrationRunnable.run();

    // verify service registration
    ArgumentCaptor<Registration> argument = ArgumentCaptor.forClass(Registration.class);
    verify(agentClient).register(argument.capture(), any());


    Registration registration = argument.getValue();
    assertEquals("cluster-discovery-hivemq", registration.getName());
    assertEquals("clusternode1-hostname", registration.getAddress().get());
    assertEquals(Integer.valueOf(1234), registration.getPort().get());
    assertEquals("cluster-discovery-hivemq", registration.getName());

    String registrationId = registration.getId();
    assertThat(registrationId).containsOnlyDigits();
    assertEquals(1, registration.getChecks().size());

    Registration.RegCheck regCheck = registration.getChecks().get(0);
    assertEquals("120s", regCheck.getTtl().get());

     // run updater job and check consul service pass call
    updateRunnable.run();
    try {
        verify(agentClient).pass(eq(registrationId));
    } catch (NotRegisteredException e) {
        throw new RuntimeException(e);
    }

    HealthClient healthClient = mock(HealthClient.class);
    List<ServiceHealth> nodes = new ArrayList<>();

    Service service = ImmutableService.builder()
            .address("host1")
            .id("not important")
            .service("doesnt matter")
            .port(5678).build();

    Node node = ImmutableNode.builder().node("node1").address("address1").build();
    ServiceHealth serviceHealth = ImmutableServiceHealth.builder().service(service).node(node).build();

    nodes.add(serviceHealth);
    ConsulResponse response = new ConsulResponse(nodes, 0, true, BigInteger.ZERO);
    when(healthClient.getHealthyServiceInstances(anyString(), ArgumentMatchers.<ImmutableQueryOptions>any())).thenReturn(response);
    when(consul.healthClient()).thenReturn(healthClient);

    List<ClusterNodeAddress> addresses = callback.getNodeAddresses().get();
    assertEquals(1, addresses.size());
    assertEquals("host1", addresses.get(0).getHost());
    assertEquals(5678, addresses.get(0).getPort());

    callback.destroy();
    verify(agentClient).deregister(eq(registrationId));
}
 

开发者ID:pellepelster,
项目名称:hivemq-consul-cluster-discovery,
代码行数:81,
代码来源:ConsulDiscoveryCallbackTest.java


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