use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testKeysWithPredicateShouldLoadMapStore.
@Test(timeout = 120000)
public void testKeysWithPredicateShouldLoadMapStore() {
EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>().insert("key1", 17).insert("key2", 23).insert("key3", 47);
HazelcastInstance instance = createHazelcastInstance(newConfig(testMapStore, 0));
final IMap map = instance.getMap("default");
assertTrueEventually(new AssertTask() {
@Override
public void run() {
Set result = map.keySet();
assertContains(result, "key1");
assertContains(result, "key2");
assertContains(result, "key3");
}
});
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class NearCacheTest method multiple_get_on_non_existing_key_generates_one_miss.
@Test
public void multiple_get_on_non_existing_key_generates_one_miss() {
String mapName = "test";
Config config = getConfig();
NearCacheConfig nearCacheConfig = newNearCacheConfig();
nearCacheConfig.setCacheLocalEntries(true);
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap map = node.getMap(mapName);
map.get(1);
map.get(1);
map.get(1);
NearCacheStats nearCacheStats = map.getLocalMapStats().getNearCacheStats();
assertEquals(1, nearCacheStats.getMisses());
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class SimpleFunctionalMapTest method main.
/**
* This test runs continuously until an exception is thrown.
* No args
*/
public static void main(String[] args) {
int threadCount = 40;
final Stats stats = new Stats();
final HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(null);
ExecutorService es = Executors.newFixedThreadPool(threadCount);
for (int i = 0; i < threadCount; i++) {
es.submit(new Runnable() {
public void run() {
IMap map = hazelcast.getMap("default");
while (true) {
int keyInt = (int) (RANDOM.nextFloat() * ENTRY_COUNT);
int operation = ((int) (RANDOM.nextFloat() * 1000)) % 20;
Object key = String.valueOf(keyInt);
if (operation < 1) {
map.size();
stats.increment("size");
} else if (operation < 2) {
map.get(key);
stats.increment("get");
} else if (operation < 3) {
map.remove(key);
stats.increment("remove");
} else if (operation < 4) {
map.containsKey(key);
stats.increment("containsKey");
} else if (operation < 5) {
Object value = String.valueOf(key);
map.containsValue(value);
stats.increment("containsValue");
} else if (operation < 6) {
map.putIfAbsent(key, createValue());
stats.increment("putIfAbsent");
} else if (operation < 7) {
Collection col = map.values();
for (Object o : col) {
int i = 0;
}
stats.increment("values");
} else if (operation < 8) {
Collection col = map.keySet();
for (Object o : col) {
int i = 0;
}
stats.increment("keySet");
} else if (operation < 9) {
Collection col = map.entrySet();
for (Object o : col) {
int i = 0;
}
stats.increment("entrySet");
} else {
map.put(key, createValue());
stats.increment("put");
}
}
}
});
}
Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
while (true) {
try {
// noinspection BusyWait
Thread.sleep(STATS_SECONDS * 1000);
System.out.println("cluster size:" + hazelcast.getCluster().getMembers().size());
Stats currentStats = stats.getAndReset();
System.out.println(currentStats);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class MapTransactionTest method testReplace_whenSame.
@Test
public void testReplace_whenSame() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map1 = h1.getMap("default");
final IMap map2 = h2.getMap("default");
map2.put("1", "1");
map2.put("2", "2");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
assertTrue(txMap.replace("1", "1", "11"));
assertFalse(txMap.replace("5", "5", "55"));
assertFalse(txMap.replace("2", "1", "22"));
assertEquals("1", map1.get("1"));
assertEquals("11", txMap.get("1"));
assertEquals("2", map1.get("2"));
assertEquals("2", txMap.get("2"));
return true;
}
});
assertTrue(b);
assertEquals("11", map1.get("1"));
assertEquals("11", map2.get("1"));
assertEquals("2", map1.get("2"));
assertEquals("2", map2.get("2"));
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class MapTransactionTest method testRemove_whenSame.
@Test
public void testRemove_whenSame() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map1 = h1.getMap("default");
final IMap map2 = h2.getMap("default");
map2.put("1", "1");
map2.put("2", "2");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.put("3", "3");
map2.put("4", "4");
assertTrue(txMap.remove("1", "1"));
assertFalse(txMap.remove("2", "1"));
assertEquals("1", map1.get("1"));
assertNull(txMap.get("1"));
assertTrue(txMap.remove("2", "2"));
assertFalse(txMap.remove("5", "2"));
assertEquals(2, txMap.size());
return true;
}
});
assertTrue(b);
assertNull(map1.get("1"));
assertNull(map2.get("1"));
assertNull(map1.get("2"));
assertNull(map2.get("2"));
assertEquals("3", map1.get("3"));
assertEquals("3", map2.get("3"));
assertEquals("4", map1.get("4"));
assertEquals("4", map2.get("4"));
}
Aggregations