Search in sources :

Example 21 with StateMap

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

the class StateStoreListenerManager method removeStateStoreListener.

@PreDestroy
public void removeStateStoreListener() {
    for (Map.Entry<String, MapListener> entry : listeners.entrySet()) {
        String map = entry.getKey();
        MapListener listener = entry.getValue();
        StateMap<?, ?> stateMap = (StateMap<?, ?>) stateStoreProvider.getStateStore().getOrCreateStateCollection(map, StateCollection.Type.MAP);
        stateMap.removeEntryListener(listener);
        LOG.info("Remove state store listener " + listener + " for map " + map);
    }
}
Also used : MapListener(io.prestosql.spi.statestore.listener.MapListener) StateMap(io.prestosql.spi.statestore.StateMap) StateMap(io.prestosql.spi.statestore.StateMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PreDestroy(javax.annotation.PreDestroy)

Example 22 with StateMap

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

the class TestHazelcastStateMap method testAddAndRemoveListeners.

@Test
public void testAddAndRemoveListeners() throws InterruptedException {
    AtomicInteger count = new AtomicInteger();
    EntryAddedListener<String, String> addedListener = event -> {
        if (event.getKey().equals("Key") && event.getValue().equals("Created")) {
            count.getAndIncrement();
        }
    };
    StateMap<String, String> testMap = stateStore.createStateMap("Test_Add_Remove_Listeners_Map");
    testMap.addEntryListener(addedListener);
    testMap.put("Key", "Created");
    TimeUnit.MILLISECONDS.sleep(500);
    assertEquals(count.get(), 1, "Events were not triggered or values did not match");
    testMap.remove("Key");
    testMap.removeEntryListener(addedListener);
    testMap.put("Key", "Created");
    TimeUnit.MILLISECONDS.sleep(500);
    assertEquals(count.get(), 1, "Events triggered again when listener removed");
}
Also used : BeforeSuite(org.testng.annotations.BeforeSuite) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) StateStore(io.prestosql.spi.statestore.StateStore) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) Type(io.prestosql.spi.statestore.StateCollection.Type) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EntryRemovedListener(io.prestosql.spi.statestore.listener.EntryRemovedListener) SerializerConfig(com.hazelcast.config.SerializerConfig) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ImmutableSet(com.google.common.collect.ImmutableSet) StateMap(io.prestosql.spi.statestore.StateMap) EntryUpdatedListener(io.prestosql.spi.statestore.listener.EntryUpdatedListener) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) NetworkConfig(com.hazelcast.config.NetworkConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Hazelcast(com.hazelcast.core.Hazelcast) EntryAddedListener(io.prestosql.spi.statestore.listener.EntryAddedListener) Assert.assertTrue(org.testng.Assert.assertTrue) AfterSuite(org.testng.annotations.AfterSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Example 23 with StateMap

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

the class TestHazelcastStateMap method testGetAllMatching.

/**
 * Test getAllMatching
 */
@Test
public void testGetAllMatching() {
    StateMap<String, String> stateMap = setUpStateMap("TestGetAllMatching");
    stateMap.put(TEST_KEY1, TEST_VALUE1);
    stateMap.put(TEST_KEY2, TEST_VALUE2);
    Map states = stateMap.getAll(ImmutableSet.of(TEST_KEY1, NOT_EXIST));
    assertEquals(states.size(), 1);
    assertEquals(states.get(TEST_KEY1), TEST_VALUE1);
    assertNull(states.get(NOT_EXIST));
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) StateMap(io.prestosql.spi.statestore.StateMap) Test(org.testng.annotations.Test)

Example 24 with StateMap

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

the class TestHazelcastStateMap method testGetAll.

/**
 * Test getAll
 */
@Test
public void testGetAll() {
    final int size = 2;
    StateMap<String, String> stateMap = setUpStateMap("TestGetAll");
    stateMap.put(TEST_KEY1, TEST_VALUE1);
    stateMap.put(TEST_KEY2, TEST_VALUE2);
    Map states = stateMap.getAll();
    assertEquals(states.size(), size);
    assertEquals(states.get(TEST_KEY1), TEST_VALUE1);
    assertEquals(states.get(TEST_KEY2), TEST_VALUE2);
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) StateMap(io.prestosql.spi.statestore.StateMap) Test(org.testng.annotations.Test)

Example 25 with StateMap

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

the class TestHazelcastStateMap method testSliceSerializer.

/**
 * Test Hazelcast Slice serializer
 */
@Test
public void testSliceSerializer() {
    Slice s3 = utf8Slice("test3");
    Slice s1 = utf8Slice("test1");
    StateMap<String, Slice> ss = (StateMap<String, Slice>) stateStore.createStateCollection("slicecheck", STATE_COLLECTION_TYPE);
    ss.put("s1", s1);
    Slice s2 = ss.get("s1");
    assertEquals(s1, s2);
}
Also used : Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) StateMap(io.prestosql.spi.statestore.StateMap) Test(org.testng.annotations.Test)

Aggregations

StateMap (io.prestosql.spi.statestore.StateMap)27 StateStore (io.prestosql.spi.statestore.StateStore)16 HashMap (java.util.HashMap)11 Map (java.util.Map)10 StateCollection (io.prestosql.spi.statestore.StateCollection)8 Test (org.testng.annotations.Test)8 ImmutableSet (com.google.common.collect.ImmutableSet)5 Symbol (io.prestosql.spi.plan.Symbol)5 IOException (java.io.IOException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 PrestoException (io.prestosql.spi.PrestoException)3 DynamicFilter (io.prestosql.spi.dynamicfilter.DynamicFilter)3 StateSet (io.prestosql.spi.statestore.StateSet)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3