Search in sources :

Example 1 with FileBasedSeed

use of io.hetu.core.seedstore.filebased.FileBasedSeed 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 2 with FileBasedSeed

use of io.hetu.core.seedstore.filebased.FileBasedSeed in project hetu-core by openlookeng.

the class DistributedQueryRunnerWithStateStore method setupStateStore.

public void setupStateStore() throws Exception {
    int port = SslSocketUtil.getAvailablePort();
    for (TestingPrestoServer server : servers) {
        server.installPlugin(new StateStoreManagerPlugin());
        // State Store
        StateStoreLauncher launcher = server.getInstance(Key.get(StateStoreLauncher.class));
        if (launcher instanceof EmbeddedStateStoreLauncher) {
            Set<String> ips = Sets.newHashSet(Arrays.asList("127.0.0.1"));
            Map<String, String> stateStoreProperties = new HashMap<>();
            stateStoreProperties.put(DISCOVERY_PORT_CONFIG_NAME, port + "");
            stateStoreProperties.putIfAbsent(HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME, HazelcastConstants.DISCOVERY_MODE_TCPIP);
            this.stateStores.add(((EmbeddedStateStoreLauncher) launcher).launchStateStore(ips, stateStoreProperties));
        }
        launcher.launchStateStore();
        StateStoreProvider provider = server.getInstance(Key.get(StateStoreProvider.class));
        Seed seed = new FileBasedSeed("127.0.0.1:" + port, 0);
        SeedStore seedStore = new SeedStore() {

            @Override
            public Collection<Seed> add(Collection<Seed> seeds) throws IOException {
                return null;
            }

            @Override
            public Collection<Seed> get() throws IOException {
                return new ArrayList<>((Arrays.asList(seed)));
            }

            @Override
            public Collection<Seed> remove(Collection<Seed> seeds) throws IOException {
                return null;
            }

            @Override
            public Seed create(Map<String, String> properties) {
                return null;
            }

            @Override
            public String getName() {
                return null;
            }

            @Override
            public void setName(String name) {
            }
        };
        server.getInstance(Key.get(SeedStoreManager.class)).setSeedStore(SeedStoreSubType.HAZELCAST, seedStore);
        if (provider instanceof LocalStateStoreProvider) {
            Map<String, String> stateStoreProperties = new HashMap<>();
            stateStoreProperties.putIfAbsent(HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME, HazelcastConstants.DISCOVERY_MODE_TCPIP);
            stateStoreProperties.put(DISCOVERY_PORT_CONFIG_NAME, port + "");
            ((LocalStateStoreProvider) provider).setStateStore("hazelcast", stateStoreProperties);
            ((LocalStateStoreProvider) provider).createStateCollections();
        }
        provider.loadStateStore();
        this.providers.add(provider);
    }
}
Also used : EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) HashMap(java.util.HashMap) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) ArrayList(java.util.ArrayList) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) Seed(io.prestosql.spi.seedstore.Seed) StateStoreLauncher(io.prestosql.statestore.StateStoreLauncher) EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) SeedStore(io.prestosql.spi.seedstore.SeedStore) Collection(java.util.Collection) StateStoreManagerPlugin(io.hetu.core.statestore.StateStoreManagerPlugin) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

FileBasedSeed (io.hetu.core.seedstore.filebased.FileBasedSeed)2 Seed (io.prestosql.spi.seedstore.Seed)2 SeedStore (io.prestosql.spi.seedstore.SeedStore)2 HashMap (java.util.HashMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileBasedSeedStoreFactory (io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory)1 StateStoreManagerPlugin (io.hetu.core.statestore.StateStoreManagerPlugin)1 TestingPrestoServer (io.prestosql.server.testing.TestingPrestoServer)1 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)1 StateCollection (io.prestosql.spi.statestore.StateCollection)1 StateMap (io.prestosql.spi.statestore.StateMap)1 StateStore (io.prestosql.spi.statestore.StateStore)1 EmbeddedStateStoreLauncher (io.prestosql.statestore.EmbeddedStateStoreLauncher)1 LocalStateStoreProvider (io.prestosql.statestore.LocalStateStoreProvider)1 StateStoreLauncher (io.prestosql.statestore.StateStoreLauncher)1 StateStoreProvider (io.prestosql.statestore.StateStoreProvider)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1