protected ServiceRegistrar mockServiceRegistrar() { final ServiceRegistrar registrar = mock(ServiceRegistrar.class); when(registrar.register(any(ServiceRegistration.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { return mock(ServiceRegistrationHandle.class); } }); return registrar; }
private void pokeAndVerifyRegistration(final HeliosClient client, final JobId jobId, final int timeout) throws Exception { Polling.await(timeout, SECONDS, new Callable<Object>() { @Override public Object call() throws Exception { final JobStatus jobStatus = getOrNull(client.jobStatus(jobId)); final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(testHost()); final PortMapping port = taskStatus.getPorts().get("poke"); assert port.getExternalPort() != null; if (poke(port.getExternalPort())) { return true; } else { return null; } } }); awaitTaskState(jobId, testHost(), RUNNING); verify(registrar, timeout((int) SECONDS.toMillis(timeout))) .register(registrationCaptor.capture()); }
private void assertContainerRegistersAfterPoke(final HeliosClient client, final Job job) throws Exception { final JobId jobId = createJob(job); deployJob(jobId, testHost()); awaitTaskState(jobId, testHost(), HEALTHCHECKING); // wait a few seconds to see if the service gets registered Thread.sleep(3000); // shouldn't be registered, since we haven't poked it yet verify(registrar, never()).register(any(ServiceRegistration.class)); pokeAndVerifyRegistration(client, jobId, LONG_WAIT_SECONDS); final ServiceRegistration serviceRegistration = registrationCaptor.getValue(); final Map<String, Endpoint> registered = Maps.newHashMap(); for (final Endpoint endpoint : serviceRegistration.getEndpoints()) { registered.put(endpoint.getName(), endpoint); } assertEquals("wrong service", "foo_service", registered.get("foo_service").getName()); assertEquals("wrong protocol", "foo_proto", registered.get("foo_service").getProtocol()); }
@Test public void test() throws Exception { startDefaultMaster("--service-registry=" + registryAddress); verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))) .register(registrationCaptor.capture()); final ServiceRegistration registration = registrationCaptor.getValue(); final ServiceRegistration.Endpoint endpoint = getOnlyElement(registration.getEndpoints()); assertEquals("http", endpoint.getProtocol()); assertEquals("helios", endpoint.getName()); assertEquals(masterPort(), endpoint.getPort()); } }
serviceRegistrationHandle = Optional.fromNullable(registrar.register(config.registration())); final ContainerExit exit; try {
@Override protected void startUp() throws Exception { logBanner(); if (!config.getNoZooKeeperMasterRegistration()) { zkRegistrar.startAsync().awaitRunning(); } expiredJobReaper.startAsync().awaitRunning(); rollingUpdateService.startAsync().awaitRunning(); agentReaper.ifPresent(reaper -> reaper.startAsync().awaitRunning()); oldJobReaper.ifPresent(reaper -> reaper.startAsync().awaitRunning()); jobHistoryReaper.ifPresent(reaper -> reaper.startAsync().awaitRunning()); try { server.start(); } catch (Exception e) { log.error("Unable to start server, shutting down", e); server.stop(); } final ServiceRegistration serviceRegistration = ServiceRegistration.newBuilder() .endpoint("helios", "http", config.getHttpEndpoint().getPort(), config.getDomain(), config.getName()) .build(); registrar.register(serviceRegistration); }
.register(registrationCaptor.capture()); final ServiceRegistration serviceRegistration = registrationCaptor.getValue();
@Override protected void startUp() throws Exception { logBanner(); if (!config.getNoZooKeeperMasterRegistration()) { zkRegistrar.startAsync().awaitRunning(); } expiredJobReaper.startAsync().awaitRunning(); rollingUpdateService.startAsync().awaitRunning(); try { server.start(); } catch (Exception e) { log.error("Unable to start server, shutting down", e); server.stop(); } final ServiceRegistration serviceRegistration = ServiceRegistration.newBuilder() .endpoint("helios", "http", config.getHttpEndpoint().getPort(), config.getDomain(), config.getName()) .build(); registrar.register(serviceRegistration); }
serviceRegistrationHandle = Optional.fromNullable(registrar.register(config.registration())); final ContainerExit exit; try {