Search in sources :

Example 26 with StateStore

use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.

the class TestStateFetcher method stateStoreMockData.

private void stateStoreMockData() {
    stateFetcher.registerStateCollection(STATE_COLLECTION_QUERY);
    stateStoreFactory = Mockito.mock(StateStoreFactory.class);
    when(stateStoreFactory.getName()).then(new Returns(STATE_STORE_HAZELCAST));
    stateStore = Mockito.mock(StateStore.class);
    when(stateStore.getName()).then(new Returns(STATE_COLLECTION_QUERY));
    when(stateStoreFactory.create(any(), any(), any())).then(new Returns(stateStore));
    stateCollection = Mockito.mock(StateMap.class);
    when(stateStoreProvider.getStateStore()).then(new Returns(stateStore));
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) StateMap(io.prestosql.spi.statestore.StateMap) StateStore(io.prestosql.spi.statestore.StateStore) StateStoreFactory(io.prestosql.spi.statestore.StateStoreFactory)

Example 27 with StateStore

use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.

the class TestStateStoreLauncherAndProvider method testGetStateStore.

@Test
public void testGetStateStore() throws Exception {
    // stateStore should be empty at initialization
    createStateStoreCluster(PORT3);
    StateStore stateStore = stateStoreProvider.getStateStore();
    assertNull(stateStore);
    stateStoreProvider.loadStateStore();
    stateStore = stateStoreProvider.getStateStore();
    assertNotNull(stateStore);
}
Also used : StateStore(io.prestosql.spi.statestore.StateStore) HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 28 with StateStore

use of io.prestosql.spi.statestore.StateStore 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);
}
Also used : HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) LocalConfig(io.hetu.core.filesystem.LocalConfig) StateStore(io.prestosql.spi.statestore.StateStore) HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) Properties(java.util.Properties) HazelcastStateStoreBootstrapper(io.hetu.core.statestore.hazelcast.HazelcastStateStoreBootstrapper) URI(java.net.URI) HetuConfig(io.prestosql.utils.HetuConfig) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) HetuLocalFileSystemClient(io.hetu.core.filesystem.HetuLocalFileSystemClient) HttpServerInfo(io.airlift.http.server.HttpServerInfo) HazelcastStateStoreBootstrapper(io.hetu.core.statestore.hazelcast.HazelcastStateStoreBootstrapper) StateStoreBootstrapper(io.prestosql.spi.statestore.StateStoreBootstrapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 29 with StateStore

use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.

the class TestHetuMetastoreGlobalCache method setUp.

@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));
        createStateStoreCluster(PORT3);
        stateStoreProvider.loadStateStore();
        StateStore stateStore = stateStoreProvider.getStateStore();
        String type = GLOBAL;
        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)

Example 30 with StateStore

use of io.prestosql.spi.statestore.StateStore in project hetu-core by openlookeng.

the class TestDistributedResourceGroup method setup.

@BeforeClass
public void setup() {
    statestore = Mockito.mock(StateStore.class);
    when(statestore.getLock(anyString())).then(new Returns(new ReentrantLock()));
    internalNodeManager = Mockito.mock(InternalNodeManager.class);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Returns(org.mockito.internal.stubbing.answers.Returns) InternalNodeManager(io.prestosql.metadata.InternalNodeManager) StateStore(io.prestosql.spi.statestore.StateStore) 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