本文整理汇总了Java中com.spotify.helios.serviceregistration.ServiceRegistrationHandle类的典型用法代码示例。如果您正苦于以下问题:Java ServiceRegistrationHandle类的具体用法?Java ServiceRegistrationHandle怎么用?Java ServiceRegistrationHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceRegistrationHandle类属于com.spotify.helios.serviceregistration包,在下文中一共展示了ServiceRegistrationHandle类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnRegistrationNotRefreshedAnyMore
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的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.ServiceRegistrationHandle; //导入依赖的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: testEndpointTags
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的package包/类
@Test
public void testEndpointTags() throws Exception {
final String serviceId = "test-service-with-tags-v2";
// Register a service
final ConsulServiceRegistrar registrar = newRegistrar();
final ServiceRegistrationHandle handle = registrar.register(
newService(serviceId, Arrays.asList("tag-1", "tag-2")));
final ConsulClient client = registrar.getConsulClient();
Thread.sleep(1000);
AgentService service = client.getAgentServicesWithTag(TAG).get(serviceId);
Set<String> expectedTags = ImmutableSet.of(TAG, "protocol-tcp", "v2", "tag-1", "tag-2");
Set<String> actualTags = ImmutableSet.copyOf(service.getTags());
assertEquals(expectedTags, actualTags);
// Cleanup
registrar.unregister(handle);
Thread.sleep(1000);
assertTrue(registrar.getConsulClient().getAgentServicesWithTag(TAG).isEmpty());
}
示例4: register
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的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;
}
示例5: unregister
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的package包/类
@Override
public void unregister(final ServiceRegistrationHandle handle) {
if (!handles.containsKey(handle)) {
return;
}
try {
sendDeRegistration(handle);
} catch (Exception e) {
log.warn("error removing registration handle {}", handle, e);
}
handles.remove(handle);
}
示例6: sendDeRegistration
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的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));
}
}
示例7: testDeregistration
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的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();
}
示例8: unregister
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的package包/类
@Override
public void unregister(ServiceRegistrationHandle handle) {
if (!handles.containsKey(handle)) {
return;
}
try {
sendDeRegistration(handle);
} catch (Exception e) {
log.warn("Error removing registration handle {}", handle, e);
}
handles.remove(handle);
}
示例9: sendDeRegistration
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的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());
}
}
示例10: testUnregister
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的package包/类
@Test
public void testUnregister() throws Exception {
RegistrarConfig config = ConsulServiceRegistrarFactory.createConfig();
ServiceRegistrar registrar = new ConsulServiceRegistrar(consulClient, config);
ServiceRegistrationHandle handle = registrar.register(new ServiceRegistration(Arrays.asList(ENDPOINT_WITHOUT_TAGS)));
registrar.unregister(handle);
registrar.close();
verify(consulClient).register((Service) anyObject());
verify(consulClient).deregister(ENDPOINT_WITHOUT_TAGS.getName());
verify(consulClient).close();
}
示例11: testReRegister
import com.spotify.helios.serviceregistration.ServiceRegistrationHandle; //导入依赖的package包/类
@Test
public void testReRegister() throws Exception {
final String serviceId = "test-2-service-v12";
// Register a service
final ConsulServiceRegistrar registrar = newRegistrar();
final ServiceRegistrationHandle handle = registrar.register(newService(serviceId));
final ConsulClient client = registrar.getConsulClient();
Thread.sleep(1000);
// Check that the service actually is registered
assertTrue(client.getAgentServicesWithTag(TAG).containsKey(serviceId));
// Consul "forgets" about the service (i.e. manually de-register it)
client.deregister(serviceId).get();
assertTrue(client.getAgentServicesWithTag(TAG).isEmpty());
// Force re-registration
registrar.syncState();
// Check that the service is re-registered
assertTrue(client.getAgentServicesWithTag(TAG).containsKey(serviceId));
// Cleanup
registrar.unregister(handle);
Thread.sleep(1000);
assertTrue(registrar.getConsulClient().getAgentServicesWithTag(TAG).isEmpty());
}