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


Java ServiceRegistration类代码示例

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


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

示例1: testUnRegistrationNotRefreshedAnyMore

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testUnRegistrationNotRefreshedAnyMore() throws Exception {
  final SkyDnsServiceRegistrar registrar = makeRegistrar();
  when(client.set(ETCD_KEY, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));

  final ServiceRegistrationHandle handle = registrar.register(
      new ServiceRegistration(ENDPOINTS));
  verify(client, timeout(WAIT_TIMEOUT)).set(ETCD_KEY, EXPECTED, TTL);

  when(client.delete(ETCD_KEY)).thenReturn(Futures.immediateFuture(response));
  registrar.unregister(handle);
  verify(client, timeout(WAIT_TIMEOUT)).delete(ETCD_KEY);

  Thread.sleep(2000);
  verify(client, VerificationModeFactory.noMoreInteractions()).set(ETCD_KEY, EXPECTED, TTL);
  registrar.close();
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:19,代码来源:SkyDnsServiceRegistrarTest.java

示例2: register

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Override
public ServiceRegistrationHandle register(final ServiceRegistration registration) {
    final ServiceRegistrationHandle newHandle = new ServiceRegistrationHandle() {};
    handles.put(newHandle, registration);

    for (final ServiceRegistration.Endpoint endpoint : registration.getEndpoints()) {
        if (!endpoints.add(endpoint.getName())) {
            log.error("Endpoint names must be unique since they map to a Consul Service ID. " +
                      "'{}' already present.", endpoint.getName());
        }
    }

    try {
        sendRegistration(registration);
    } catch (Exception e) {
        log.warn("Error performing registration", e);
    }
    return newHandle;
}
 
开发者ID:SVT,项目名称:helios-consul,代码行数:20,代码来源:ConsulServiceRegistrar.java

示例3: testRegister

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testRegister() throws Exception {
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);

    RegistrarConfig config = ConsulServiceRegistrarFactory.createConfig();
    ConsulServiceRegistrar registrar = new ConsulServiceRegistrar(consulClient, config);
    registrar.register(new ServiceRegistration(Arrays.asList(ENDPOINT_CHECK_FROM_TAG)));
    registrar.close();

    verify(consulClient).register(serviceCaptor.capture());
    verify(consulClient).close();

    Service service = serviceCaptor.getValue();
    assertEquals("redis", service.getName());
    assertEquals(9000, service.getPort().intValue());
    assertTrue(service.getTags().contains("protocol-http"));
    assertEquals("redis-http-9000", service.getCheck().getId());
    assertEquals("HTTP health check for http://example.com:9000/health", service.getCheck().getName());
    assertEquals("HTTP health check requesting http://example.com:9000/health every 10s",
            service.getCheck().getNotes());
    assertEquals("http://example.com:9000/health", service.getCheck().getHttp());
    assertEquals("10s", service.getCheck().getInterval());
}
 
开发者ID:SVT,项目名称:helios-consul,代码行数:24,代码来源:ServiceRegistrarTest.java

示例4: testRegisterWithoutCheck

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testRegisterWithoutCheck() throws Exception {
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);

    RegistrarConfig config = ConsulServiceRegistrarFactory.createConfig();
    ConsulServiceRegistrar registrar = new ConsulServiceRegistrar(consulClient, config);
    registrar.register(new ServiceRegistration(Arrays.asList(ENDPOINT_WITHOUT_TAGS)));
    registrar.close();

    verify(consulClient).register(serviceCaptor.capture());
    verify(consulClient).close();

    Service service = serviceCaptor.getValue();
    assertEquals("redis", service.getName());
    assertEquals(9000, service.getPort().intValue());
    assertTrue(service.getTags().contains("protocol-http"));
    assertNull(service.getCheck());
}
 
开发者ID:SVT,项目名称:helios-consul,代码行数:19,代码来源:ServiceRegistrarTest.java

示例5: run

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Override public void run() {
  for (ServiceRegistration handle : handles.values()) {
    try {
      log.debug("handles is {}", handles);
      sendRegistration(handle);
    } catch (Exception e) {
      log.error("Caught exception sending registration for handle {}", handle, e);
    }
  }
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:11,代码来源:SkyDnsServiceRegistrar.java

示例6: register

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Override
public ServiceRegistrationHandle register(ServiceRegistration registration) {
  final ServiceRegistrationHandle newHandle = new ServiceRegistrationHandle(){};

  handles.put(newHandle, registration);
  try {
    sendRegistration(registration);
  } catch (Exception e) {
    log.warn("Error performing registration", e);
  }
  return newHandle;
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:13,代码来源:SkyDnsServiceRegistrar.java

示例7: sendDeRegistration

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
private void sendDeRegistration(ServiceRegistrationHandle handle) {
  final ServiceRegistration registration = handles.get(handle);
  if (registration == null) {
    return;
  }
  for (Endpoint endpoint : registration.getEndpoints()) {
    etcdClient.delete(makeKey(endpoint));
  }
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:10,代码来源:SkyDnsServiceRegistrar.java

示例8: sendRegistration

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
private void sendRegistration(ServiceRegistration registration) throws JsonProcessingException {
  for (Endpoint endpoint : registration.getEndpoints()) {
    final String value = OBJECT_MAPPER.writeValueAsString(SkyDnsEntry.builder()
        .setHost(makeHostnameCanonical(endpoint.getHost()))
        .setPort(endpoint.getPort())
        // could set TTL, but skydns goes by the min(ttl, etcd entry ttl) anyhow
        .build());
    etcdClient.set(makeKey(endpoint), value, timeToLiveSeconds);
  }
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:11,代码来源:SkyDnsServiceRegistrar.java

示例9: testRegistration_alternateFormat

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testRegistration_alternateFormat() throws Exception {
  // set some weird domain format
  final SkyDnsServiceRegistrar registrar = new SkyDnsServiceRegistrar(client, TTL,
      "${domain}.${service}");
  final String key = "helios/com/foo/services" + SUFFIX_KEY;
  when(client.set(key, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));
  registrar.register(new ServiceRegistration(ImmutableList.of(
      new ServiceRegistration.Endpoint(PORT_NAME, PROTOCOL, 4242, DOMAIN, HOSTNAME))));
  verify(client, timeout(WAIT_TIMEOUT)).set(key, EXPECTED, TTL);
  registrar.close();
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:14,代码来源:SkyDnsServiceRegistrarTest.java

示例10: testRegistration

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testRegistration() throws Exception {
  final SkyDnsServiceRegistrar registrar = makeRegistrar();
  when(client.set(ETCD_KEY, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));
  registrar.register(new ServiceRegistration(ImmutableList.of(
      new ServiceRegistration.Endpoint(PORT_NAME, PROTOCOL, 4242, DOMAIN, HOSTNAME))));
  verify(client, timeout(WAIT_TIMEOUT)).set(ETCD_KEY, EXPECTED, TTL);
  registrar.close();
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:11,代码来源:SkyDnsServiceRegistrarTest.java

示例11: testRegistrationWithFullyQualifiedDomain

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testRegistrationWithFullyQualifiedDomain() throws Exception {
  final SkyDnsServiceRegistrar registrar = makeRegistrar();
  when(client.set(ETCD_KEY, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));
  registrar.register(new ServiceRegistration(ImmutableList.of(
      new ServiceRegistration.Endpoint(PORT_NAME, PROTOCOL, 4242, DOMAIN + ".", HOSTNAME))));
  verify(client, timeout(WAIT_TIMEOUT)).set(ETCD_KEY, EXPECTED, TTL);
  registrar.close();
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:11,代码来源:SkyDnsServiceRegistrarTest.java

示例12: testDeregistration

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testDeregistration() {
  final SkyDnsServiceRegistrar registrar = makeRegistrar();
  when(client.set(ETCD_KEY, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));
  final ServiceRegistrationHandle handle = registrar.register(new ServiceRegistration(ENDPOINTS));

  when(client.delete(ETCD_KEY)).thenReturn(Futures.immediateFuture(response));
  registrar.unregister(handle);
  verify(client, timeout(WAIT_TIMEOUT)).delete(ETCD_KEY);
  registrar.close();
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:13,代码来源:SkyDnsServiceRegistrarTest.java

示例13: testRegistrationAndRefresh

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
@Test
public void testRegistrationAndRefresh() throws Exception {
  final SkyDnsServiceRegistrar registrar = makeRegistrar();
  when(client.set(ETCD_KEY, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));
  registrar.register(new ServiceRegistration(ENDPOINTS));
  verify(client, timeout(WAIT_TIMEOUT)).set(ETCD_KEY, EXPECTED, TTL);
  verify(client, timeout(2000).atLeast(2)).set(ETCD_KEY, EXPECTED, TTL);
  registrar.close();
}
 
开发者ID:spotify,项目名称:helios-skydns,代码行数:11,代码来源:SkyDnsServiceRegistrarTest.java

示例14: sendRegistration

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
private void sendRegistration(ServiceRegistration registration)
        throws JsonProcessingException {

    for (final ServiceRegistration.Endpoint endpoint : registration.getEndpoints()) {
        consulClient.register(serviceUtil.createService(endpoint));
    }
}
 
开发者ID:SVT,项目名称:helios-consul,代码行数:8,代码来源:ConsulServiceRegistrar.java

示例15: sendDeRegistration

import com.spotify.helios.serviceregistration.ServiceRegistration; //导入依赖的package包/类
private void sendDeRegistration(ServiceRegistrationHandle handle) {
    final ServiceRegistration registration = handles.get(handle);
    if (registration == null) {
        return;
    }
    for (ServiceRegistration.Endpoint endpoint : registration.getEndpoints()) {
        consulClient.deregister(endpoint.getName());
        endpoints.remove(endpoint.getName());
    }
}
 
开发者ID:SVT,项目名称:helios-consul,代码行数:11,代码来源:ConsulServiceRegistrar.java


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