use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.
the class TestHazelcastClusterMembershipListener method testMemberRemoved.
/**
* Test Hazelcast member removed
*
* @throws InterruptedException InterruptedException when thread sleep interrupted
*/
@Test
public void testMemberRemoved() throws InterruptedException {
final long sleep500 = 500L;
final long sleep50 = 50L;
final long timeout3000 = 3000L;
StateStore member1 = setupHazelcastInstance(PORT1);
member1.registerNodeFailureHandler(node -> {
assertEquals((String) node, MEMBER_2_ADDRESS);
isNotified = true;
});
StateStore member2 = setupHazelcastInstance(PORT2);
TimeUnit.MILLISECONDS.sleep(sleep500);
((HazelcastStateStore) member2).shutdown();
long timeout = timeout3000;
while (isNotified == false && timeout > 0L) {
TimeUnit.MILLISECONDS.sleep(sleep50);
timeout -= sleep50;
}
assertTrue(isNotified);
((HazelcastStateStore) member1).shutdown();
}
use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.
the class TestHazelcastStateStoreFactory method testTcpipCreate.
/**
* Test state store creation with tcp-ip mode
*
* @throws IOException IOException thrown if seedStore read write errors happen
*/
@Test
public void testTcpipCreate() throws IOException {
HazelcastStateStoreFactory factory = new HazelcastStateStoreFactory();
assertEquals(factory.getName(), HAZELCAST);
SeedStoreFactory seedStoreFactory = new FileBasedSeedStoreFactory();
assertEquals(seedStoreFactory.getName(), "filebased");
Map<String, String> properties = new HashMap<>(0);
properties.put(STATE_STORE_CLUSTER_CONFIG_NAME, TEST_CLUSTER_NAME);
properties.put(DISCOVERY_MODE_CONFIG_NAME, DISCOVERY_MODE_TCPIP);
SeedStore seedStore = mock(SeedStore.class);
Seed seed = new FileBasedSeed(MEMBER_ADDRESS, 0);
when(seedStore.get()).thenReturn(ImmutableList.of(seed));
setupHazelcastInstance();
StateStore stateStore = factory.create(TEST_STATE_STORE_NAME, seedStore, properties);
assertEquals(stateStore.getName(), TEST_STATE_STORE_NAME);
StateCollection collection = stateStore.createStateCollection("test", StateCollection.Type.MAP);
((StateMap<String, String>) collection).put(TEST_KEY, TEST_VALUE);
assertEquals(collection.size(), 1);
assertEquals(((StateMap<String, String>) collection).get(TEST_KEY), TEST_VALUE);
((HazelcastStateStore) stateStore).shutdown();
}
use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.
the class TestHetuServiceInventory method createMockStateStoreProvider.
private StateStoreProvider createMockStateStoreProvider() {
StateStoreProvider mockStateStoreProvider = mock(LocalStateStoreProvider.class);
StateStore mockStateStore = mock(StateStore.class);
when(mockStateStoreProvider.getStateStore()).thenReturn(mockStateStore);
StateMap<String, String> mockDiscoveryInfo = mock(StateMap.class);
Map<String, String> mockDiscoveryMap = new HashMap<>();
mockDiscoveryMap.put(TESTING_HOST, TESTING_PORT);
when(mockDiscoveryInfo.getAll()).thenReturn(mockDiscoveryMap);
when(mockStateStore.getStateCollection(StateStoreConstants.DISCOVERY_SERVICE_COLLECTION_NAME)).thenReturn(mockDiscoveryInfo);
return mockStateStoreProvider;
}
use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method createMockStateStore.
private StateStore createMockStateStore() {
StateStoreProvider mockStateStoreProvider = mock(LocalStateStoreProvider.class);
StateStore mockStateStore = mock(StateStore.class);
when(mockStateStoreProvider.getStateStore()).thenReturn(mockStateStore);
StateMap<String, String> mockDiscoveryInfo = mock(StateMap.class);
Map<String, String> mockDiscoveryMap = new HashMap<>();
mockDiscoveryMap.put(TESTING_HOST, TESTING_PORT);
when(mockDiscoveryInfo.getAll()).thenReturn(mockDiscoveryMap);
when(mockStateStore.getStateCollection(StateStoreConstants.DISCOVERY_SERVICE_COLLECTION_NAME)).thenReturn(mockDiscoveryInfo);
return mockStateStoreProvider.getStateStore();
}
use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method setUp.
/**
* setUp
*
* @throws Exception Exception
*/
@BeforeClass
public void setUp() throws Throwable {
try {
Map<String, String> config = new ImmutableMap.Builder<String, String>().put("hetu.metastore.hetufilesystem.path", path).put("hetu.metastore.hetufilesystem.profile-name", "local-config-catalog").put("hetu.metastore.cache.size", "10000").put("hetu.metastore.cache.ttl", "10h").build();
LocalConfig localConfig = new LocalConfig(null);
client = new HetuLocalFileSystemClient(localConfig, Paths.get(path));
if (!client.exists(Paths.get(path))) {
client.createDirectories(Paths.get(path));
}
client.deleteRecursively(Paths.get(path));
StateStore stateStore = createMockStateStore();
String type = LOCAL;
Bootstrap app = new Bootstrap(new MBeanModule(), new MBeanServerModule(), new HetuFsMetastoreModule(client, stateStore, type));
Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
metastore = injector.getInstance(HetuMetastore.class);
} catch (Exception ex) {
throwIfUnchecked(ex);
throw new PrestoException(HETU_METASTORE_CODE, "init hetu metastore module failed.");
}
// create default catalog and database
defaultCatalog = CatalogEntity.builder().setCatalogName("hetu1").setOwner("hetu1").build();
metastore.createCatalog(defaultCatalog);
defaultDatabase = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db1").build();
metastore.createDatabase(defaultDatabase);
// get metastore catalog cache
Field catalogCacheField = metastore.getClass().getSuperclass().getDeclaredField("catalogCache");
catalogCacheField.setAccessible(true);
catalogCache = (HetuCache<String, Optional<CatalogEntity>>) catalogCacheField.get(metastore);
Field catalogsCacheField = metastore.getClass().getSuperclass().getDeclaredField("catalogsCache");
catalogsCacheField.setAccessible(true);
catalogsCache = (HetuCache<String, List<CatalogEntity>>) catalogsCacheField.get(metastore);
// get metastore database cache
Field databaseCacheField = metastore.getClass().getSuperclass().getDeclaredField("databaseCache");
databaseCacheField.setAccessible(true);
databaseCache = (HetuCache<String, Optional<DatabaseEntity>>) databaseCacheField.get(metastore);
Field databasesCacheField = metastore.getClass().getSuperclass().getDeclaredField("databasesCache");
databasesCacheField.setAccessible(true);
databasesCache = (HetuCache<String, List<DatabaseEntity>>) databasesCacheField.get(metastore);
// get metastore table cache
Field tableCacheField = metastore.getClass().getSuperclass().getDeclaredField("tableCache");
tableCacheField.setAccessible(true);
tableCache = (HetuCache<String, Optional<TableEntity>>) tableCacheField.get(metastore);
Field tablesCacheField = metastore.getClass().getSuperclass().getDeclaredField("tablesCache");
tablesCacheField.setAccessible(true);
tablesCache = (HetuCache<String, List<TableEntity>>) tablesCacheField.get(metastore);
}
Aggregations