use of io.prestosql.utils.HetuConfig 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.utils.HetuConfig 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.utils.HetuConfig in project hetu-core by openlookeng.
the class TestAnalyzer method testTooManyGroupingElements.
@Test
public void testTooManyGroupingElements() {
Session session = testSessionBuilder(new SessionPropertyManager(new SystemSessionProperties(new QueryManagerConfig(), new TaskManagerConfig(), new MemoryManagerConfig(), new FeaturesConfig().setMaxGroupingSets(2048), new HetuConfig(), new SnapshotConfig()))).build();
analyze(session, "SELECT a, b, c, d, e, f, g, h, i, j, k, SUM(l)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l)\n" + "GROUP BY CUBE (a, b, c, d, e, f), CUBE (g, h, i, j, k)");
assertFails(session, TOO_MANY_GROUPING_SETS, "line 3:10: GROUP BY has 4096 grouping sets but can contain at most 2048", "SELECT a, b, c, d, e, f, g, h, i, j, k, l, SUM(m)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l, m)\n" + "GROUP BY CUBE (a, b, c, d, e, f), CUBE (g, h, i, j, k, l)");
assertFails(session, TOO_MANY_GROUPING_SETS, format("line 3:10: GROUP BY has more than %s grouping sets but can contain at most 2048", Integer.MAX_VALUE), "SELECT a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae, SUM(af)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, " + "17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae, af)\n" + "GROUP BY CUBE (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae)");
}
use of io.prestosql.utils.HetuConfig 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.utils.HetuConfig 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);
}
Aggregations