本文整理汇总了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();
}
示例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;
}
示例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());
}
示例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());
}
示例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);
}
}
}
示例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;
}
示例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));
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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));
}
}
示例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());
}
}