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);
}
}
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");
}
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));
}
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);
}
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);
}
Aggregations