use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.
the class TestStateStoreLauncherAndProvider method testRegisterDiscoveryService.
@Test(timeOut = 5000, expectedExceptions = ThreadTimeoutException.class)
public void testRegisterDiscoveryService() throws Exception {
String failurehost = "failurehost";
String otherhost = "otherhost";
String localHostName = "localhost";
int port = 8888;
URI uri = new URI("http://" + localHostName + ":" + port);
MockStateMap discoveryServiceMap = new MockStateMap(DISCOVERY_SERVICE, new HashMap<>());
// Mock
StateStore stateStore = mock(StateStore.class);
Lock lock = mock(ReentrantLock.class);
InternalCommunicationConfig internalCommunicationConfig = mock(InternalCommunicationConfig.class);
HttpServerInfo httpServerInfo = mock(HttpServerInfo.class);
when(httpServerInfo.getHttpUri()).thenReturn(uri);
when(internalCommunicationConfig.isHttpsRequired()).thenReturn(false);
when(stateStore.getStateCollection(DISCOVERY_SERVICE)).thenReturn(discoveryServiceMap);
when(stateStore.getLock(DISCOVERY_SERVICE_LOCK)).thenReturn(lock);
EmbeddedStateStoreLauncher launcher = new EmbeddedStateStoreLauncher(new SeedStoreManager(new FileSystemClientManager()), internalCommunicationConfig, httpServerInfo, new HetuConfig());
launcher.setStateStore(stateStore);
when(lock.tryLock(DISCOVERY_REGISTRY_LOCK_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(true);
// discoveryServiceMap is empty, so the current coordinator can get the lock and register itself(register=true)
discoveryServiceMap.clear();
assertTrue(launcher.registerDiscoveryService(failurehost));
assertEquals(discoveryServiceMap.size(), 1);
assertTrue(discoveryServiceMap.getAll().keySet().contains(localHostName));
// discoveryServiceMap contains the failure host, so the current coordinator can get the lock and register itself(register=true)
discoveryServiceMap.clear();
discoveryServiceMap.put(failurehost, String.valueOf(port));
assertTrue(launcher.registerDiscoveryService(failurehost));
assertEquals(discoveryServiceMap.size(), 1);
assertTrue(discoveryServiceMap.getAll().keySet().contains(localHostName));
// discoveryServiceMap is already updated by other coordinator(otherhosts)
// the current coordinator can grab the lock but will not register itself(register=false)
discoveryServiceMap.clear();
discoveryServiceMap.put(otherhost, String.valueOf(port));
assertFalse(launcher.registerDiscoveryService(failurehost));
assertEquals(discoveryServiceMap.size(), 1);
assertFalse(discoveryServiceMap.containsKey(localHostName));
when(lock.tryLock(DISCOVERY_REGISTRY_LOCK_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(false);
// discoveryServiceMap is already updated by other coordinator(otherhosts)
// the current coordinator cannot grab the lock and not register itself
discoveryServiceMap.clear();
discoveryServiceMap.put(otherhost, String.valueOf(port));
assertFalse(launcher.registerDiscoveryService(failurehost));
assertEquals(discoveryServiceMap.size(), 1);
assertFalse(discoveryServiceMap.containsKey(localHostName));
// discoveryServiceMap contains failure host.
// The current coordinator cannot get the lock and retry will cause timeout exception
discoveryServiceMap.clear();
discoveryServiceMap.put(failurehost, String.valueOf(port));
launcher.registerDiscoveryService(failurehost);
}
use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.
the class TestHetuServiceInventory method testGetDiscoveryUriSupplierHttp.
@Test
public void testGetDiscoveryUriSupplierHttp() {
InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig().setHttpsRequired(false);
HetuConfig hetuConfig = new HetuConfig();
hetuConfig.setMultipleCoordinatorEnabled(true);
HetuServiceInventory inventory = new HetuServiceInventory(hetuConfig, null, createMockStateStoreProvider(), internalCommunicationConfig, new ServiceInventoryConfig(), new NodeInfo(new NodeConfig().setEnvironment("hetutest")), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), new TestingHttpClient(new MockExchangeRequestProcessor(new DataSize(0, BYTE))));
Iterable<ServiceDescriptor> serviceDescriptors = inventory.getServiceDescriptors("discovery");
List<URI> uris = new ArrayList<>();
serviceDescriptors.forEach(serviceDescriptor -> {
uris.add(URI.create(serviceDescriptor.getProperties().get("http")));
});
URI checkUri = URI.create("http://127.0.0.1:8090");
assertEquals(uris.size(), 1);
uris.contains(checkUri);
}
use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.
the class TestHetuServiceInventory method testGetDiscoveryUriSupplierHttps.
@Test
public void testGetDiscoveryUriSupplierHttps() {
InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig().setHttpsRequired(true);
HetuConfig hetuConfig = new HetuConfig();
hetuConfig.setMultipleCoordinatorEnabled(true);
HetuServiceInventory inventory = new HetuServiceInventory(hetuConfig, null, createMockStateStoreProvider(), internalCommunicationConfig, new ServiceInventoryConfig(), new NodeInfo(new NodeConfig().setEnvironment("hetutest")), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), new TestingHttpClient(new MockExchangeRequestProcessor(new DataSize(0, BYTE))));
Iterable<ServiceDescriptor> serviceDescriptors = inventory.getServiceDescriptors("discovery");
List<URI> uris = new ArrayList<>();
serviceDescriptors.forEach(serviceDescriptor -> {
uris.add(URI.create(serviceDescriptor.getProperties().get("https")));
});
URI checkUri = URI.create("https://127.0.0.1:8090");
assertEquals(uris.size(), 1);
uris.contains(checkUri);
}
use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.
the class TestStateStoreLauncherAndProvider method testLaunchAndFailure.
// Test Launcher
@Test
public void testLaunchAndFailure() throws Exception {
Set<Seed> seeds = new HashSet<>();
SeedStore mockSeedStore = mock(SeedStore.class);
Seed mockSeed1 = mock(Seed.class);
Seed mockSeed2 = mock(Seed.class);
seeds.add(mockSeed1);
seeds.add(mockSeed2);
when(mockSeed1.getLocation()).thenReturn(LOCALHOST + ":" + PORT1);
when(mockSeed2.getLocation()).thenReturn(LOCALHOST + ":" + PORT2);
when(mockSeedStore.get()).thenReturn(seeds);
SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
when(mockSeedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST)).thenReturn(mockSeedStore);
when(mockSeedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, LOCALHOST, true)).thenReturn(seeds);
when(mockSeedStoreManager.getFileSystemClient()).thenReturn(new HetuLocalFileSystemClient(new LocalConfig(new Properties()), Paths.get("/")));
InternalCommunicationConfig mockInternalCommunicationConfig = mock(InternalCommunicationConfig.class);
HttpServerInfo mockHttpServerInfo = mock(HttpServerInfo.class);
when(mockHttpServerInfo.getHttpsUri()).thenReturn(new URI("https://" + LOCALHOST + ":" + PORT1));
when(mockInternalCommunicationConfig.isHttpsRequired()).thenReturn(true);
EmbeddedStateStoreLauncher launcher = new EmbeddedStateStoreLauncher(mockSeedStoreManager, mockInternalCommunicationConfig, mockHttpServerInfo, new HetuConfig());
StateStoreBootstrapper bootstrapper = new HazelcastStateStoreBootstrapper();
launcher.addStateStoreBootstrapper(bootstrapper);
launcher.launchStateStore();
StateStore second = setupSecondInstance();
// mock "remove" second instance from cluster (delete from seed store)
seeds.remove(mockSeed2);
when(mockSeed1.getLocation()).thenReturn(LOCALHOST + ":" + PORT1);
when(mockSeedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, LOCALHOST, true)).thenReturn(seeds);
((HazelcastStateStore) second).shutdown();
// Allow the first node to handle failure
Thread.sleep(3000L);
}
use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.
the class TestHttpRemoteTask method createHttpRemoteTaskFactory.
private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource) throws Exception {
Bootstrap app = new Bootstrap(new JsonModule(), new SmileModule(), new HandleJsonModule(), new Module() {
@Override
public void configure(Binder binder) {
binder.bind(JsonMapper.class);
binder.bind(Metadata.class).toInstance(createTestMetadataManager());
jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
jsonCodecBinder(binder).bindJsonCodec(TaskStatus.class);
jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
jsonCodecBinder(binder).bindJsonCodec(TaskUpdateRequest.class);
smileCodecBinder(binder).bindSmileCodec(TaskStatus.class);
smileCodecBinder(binder).bindSmileCodec(TaskInfo.class);
smileCodecBinder(binder).bindSmileCodec(TaskUpdateRequest.class);
}
@Provides
private HttpRemoteTaskFactory createHttpRemoteTaskFactory(JsonMapper jsonMapper, JsonCodec<TaskStatus> taskStatusJsonCodec, SmileCodec<TaskStatus> taskStatusSmileCodec, JsonCodec<TaskInfo> taskInfoJsonCodec, SmileCodec<TaskInfo> taskInfoSmileCodec, JsonCodec<TaskUpdateRequest> taskUpdateRequestJsonCodec, SmileCodec<TaskUpdateRequest> taskUpdateRequestSmileCodec) {
JaxrsTestingHttpProcessor jaxrsTestingHttpProcessor = new JaxrsTestingHttpProcessor(URI.create("http://fake.invalid/"), testingTaskResource, jsonMapper);
TestingHttpClient testingHttpClient = new TestingHttpClient(jaxrsTestingHttpProcessor.setTrace(TRACE_HTTP));
testingTaskResource.setHttpClient(testingHttpClient);
return new HttpRemoteTaskFactory(new QueryManagerConfig(), TASK_MANAGER_CONFIG, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusJsonCodec, taskStatusSmileCodec, taskInfoJsonCodec, taskInfoSmileCodec, taskUpdateRequestJsonCodec, taskUpdateRequestSmileCodec, new RemoteTaskStats(), new InternalCommunicationConfig());
}
});
Injector injector = app.strictConfig().doNotInitializeLogging().quiet().initialize();
HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
handleResolver.addConnectorName("test", new TestingHandleResolver());
return injector.getInstance(HttpRemoteTaskFactory.class);
}
Aggregations