Search in sources :

Example 11 with StateStore

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();
}
Also used : StateStore(io.prestosql.spi.statestore.StateStore) Test(org.testng.annotations.Test)

Example 12 with StateStore

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();
}
Also used : FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) HashMap(java.util.HashMap) StateCollection(io.prestosql.spi.statestore.StateCollection) StateMap(io.prestosql.spi.statestore.StateMap) StateStore(io.prestosql.spi.statestore.StateStore) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Seed(io.prestosql.spi.seedstore.Seed) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) SeedStore(io.prestosql.spi.seedstore.SeedStore) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Test(org.testng.annotations.Test)

Example 13 with StateStore

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;
}
Also used : HashMap(java.util.HashMap) StateStore(io.prestosql.spi.statestore.StateStore) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider)

Example 14 with StateStore

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();
}
Also used : HashMap(java.util.HashMap) StateStore(io.prestosql.spi.statestore.StateStore) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider)

Example 15 with StateStore

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);
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) Optional(java.util.Optional) LocalConfig(io.hetu.core.filesystem.LocalConfig) StateStore(io.prestosql.spi.statestore.StateStore) PrestoException(io.prestosql.spi.PrestoException) ImmutableMap(com.google.common.collect.ImmutableMap) PrestoException(io.prestosql.spi.PrestoException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) HetuMetastore(io.prestosql.spi.metastore.HetuMetastore) Field(java.lang.reflect.Field) MBeanServerModule(io.prestosql.plugin.base.jmx.MBeanServerModule) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) List(java.util.List) HetuLocalFileSystemClient(io.hetu.core.filesystem.HetuLocalFileSystemClient) HetuFsMetastoreModule(io.hetu.core.metastore.hetufilesystem.HetuFsMetastoreModule) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

StateStore (io.prestosql.spi.statestore.StateStore)40 StateMap (io.prestosql.spi.statestore.StateMap)16 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)14 StateStoreProvider (io.prestosql.statestore.StateStoreProvider)11 ImmutableMap (com.google.common.collect.ImmutableMap)8 StateCollection (io.prestosql.spi.statestore.StateCollection)8 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 PrestoException (io.prestosql.spi.PrestoException)7 Map (java.util.Map)7 Set (java.util.Set)6 Symbol (io.prestosql.spi.plan.Symbol)5 Optional (java.util.Optional)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Duration (io.airlift.units.Duration)4 DynamicFilter (io.prestosql.spi.dynamicfilter.DynamicFilter)4 StateSet (io.prestosql.spi.statestore.StateSet)4 StateStoreBootstrapper (io.prestosql.spi.statestore.StateStoreBootstrapper)4 BeforeTest (org.testng.annotations.BeforeTest)4