use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.
@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() throws Exception {
final int size = 10000;
TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
testMapStore.setLoadAllKeys(false);
Config config = newConfig(testMapStore, 0);
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(size);
MapConfig mapConfig = config.getMapConfig("default");
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
mapConfig.setMaxSizeConfig(maxSizeConfig);
mapConfig.setMinEvictionCheckMillis(0);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap("default");
final CountDownLatch countDownLatch = new CountDownLatch(size);
map.addEntryListener(new EntryAdapter() {
@Override
public void entryEvicted(EntryEvent event) {
countDownLatch.countDown();
}
}, false);
for (int i = 0; i < size * 2; i++) {
// trigger eviction.
if (i == (size * 2) - 1 || i == size) {
sleepMillis(1001);
}
map.put(i, new Employee("joe", i, true, 100.00));
}
assertEquals(testMapStore.getStore().size(), size * 2);
assertOpenEventually(countDownLatch);
final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
assertTrue(msgFailure, map.size() > size / 2);
assertTrue(msgFailure, map.size() <= size);
assertEquals(testMapStore.getStore().size(), size * 2);
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class MultiMapListenerTest method testConfigListenerRegistration.
@Test
public void testConfigListenerRegistration() throws InterruptedException {
Config config = new Config();
final String name = "default";
final CountDownLatch latch = new CountDownLatch(1);
config.getMultiMapConfig(name).addEntryListenerConfig(new EntryListenerConfig().setImplementation(new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch.countDown();
}
}));
final HazelcastInstance hz = createHazelcastInstance(config);
hz.getMultiMap(name).put(1, 1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCache_withLocalListener.
@Test
public void testQueryCache_withLocalListener() {
IMap<Integer, Integer> map = getMap(instances[0], mapName);
String cacheName = randomString();
config = new Config().setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
final AtomicInteger countAddEvent = new AtomicInteger();
final AtomicInteger countRemoveEvent = new AtomicInteger();
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(cacheName, new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
countAddEvent.incrementAndGet();
}
@Override
public void entryRemoved(EntryEvent event) {
countRemoveEvent.incrementAndGet();
}
}, SQL_PREDICATE, true);
for (int i = 0; i < 30; i++) {
map.remove(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, queryCache.size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of add events wrong!", 9, countAddEvent.get());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get());
}
});
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientServiceTest method testPendingEventPacketsWithEvents.
@Test(timeout = 120000)
public void testPendingEventPacketsWithEvents() throws InterruptedException, UnknownHostException {
HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
IMap map = client.getMap(randomName());
map.addEntryListener(new EntryAdapter(), false);
for (int i = 0; i < 10; i++) {
map.put(randomString(), randomString());
}
HazelcastClientInstanceImpl clientInstanceImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
InetSocketAddress socketAddress = hazelcastInstance.getCluster().getLocalMember().getSocketAddress();
Address address = new Address(socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
ClientConnectionManager connectionManager = clientInstanceImpl.getConnectionManager();
final ClientConnection connection = (ClientConnection) connectionManager.getConnection(address);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, connection.getPendingPacketCount());
}
});
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCache_withLocalListener.
@Test
public void testQueryCache_withLocalListener() {
String mapName = randomString();
String queryCacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap(mapName);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
final AtomicInteger countAddEvent = new AtomicInteger();
final AtomicInteger countRemoveEvent = new AtomicInteger();
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
countAddEvent.incrementAndGet();
}
@Override
public void entryRemoved(EntryEvent event) {
countRemoveEvent.incrementAndGet();
}
}, new SqlPredicate("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.remove(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, queryCache.size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of add events wrong!", 9, countAddEvent.get());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get());
}
});
}
Aggregations