use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoNodesWithIndexes.
@Test
public void testTwoNodesWithIndexes() throws Exception {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance1.getMap("employees");
map.addIndex("name", false);
map.addIndex("city", false);
map.addIndex("age", true);
map.addIndex("active", false);
for (int i = 0; i < 5000; i++) {
Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
map.put(String.valueOf(i), employee);
}
assertEquals(2, instance1.getCluster().getMembers().size());
assertEquals(2, instance2.getCluster().getMembers().size());
map = instance2.getMap("employees");
map.addIndex("name", false);
map.addIndex("city", false);
map.addIndex("age", true);
map.addIndex("active", false);
Collection<Employee> entries = map.values(new SqlPredicate("name='name3' and city='city3' and age > 2"));
assertEquals(50, entries.size());
for (Employee employee : entries) {
assertEquals("name3", employee.getName());
assertEquals("city3", employee.getCity());
}
entries = map.values(new SqlPredicate("name LIKE '%name3' and city like '%city3' and age > 2"));
assertEquals(50, entries.size());
for (Employee employee : entries) {
assertEquals("name3", employee.getName());
assertEquals("city3", employee.getCity());
assertTrue(employee.getAge() > 2);
}
entries = map.values(new SqlPredicate("name LIKE '%name3%' and city like '%city30%'"));
assertEquals(50, entries.size());
for (Employee employee : entries) {
assertTrue(employee.getName().startsWith("name3"));
assertTrue(employee.getCity().startsWith("city3"));
}
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class QueryAdvancedTest method testMapWithIndexAfterShutDown.
@Test
public void testMapWithIndexAfterShutDown() {
Config config = getConfig();
String mapName = "default";
config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("typeName", false));
HazelcastInstance[] instances = createHazelcastInstanceFactory(3).newInstances(config);
final IMap<Integer, ValueType> map = instances[0].getMap(mapName);
final int sampleSize1 = 100;
final int sampleSize2 = 30;
int totalSize = sampleSize1 + sampleSize2;
for (int i = 0; i < sampleSize1; i++) {
map.put(i, new ValueType("type" + i));
}
for (int i = sampleSize1; i < totalSize; i++) {
map.put(i, new ValueType("typex"));
}
Collection typexValues = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, typexValues.size());
instances[1].shutdown();
assertEquals(totalSize, map.size());
assertTrueEventually(new AssertTask() {
public void run() {
final Collection values = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, values.size());
}
});
instances[2].shutdown();
assertEquals(totalSize, map.size());
assertTrueEventually(new AssertTask() {
public void run() {
final Collection values = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, values.size());
}
});
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class QueryBasicTest method testQueryUsingNestedPortableObject.
@Test
public void testQueryUsingNestedPortableObject() {
Config config = getConfig();
testQueryUsingNestedPortableObject(config, randomMapName());
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MemberMapRecordStateStressTest method all_records_are_readable_state_in_the_end.
@Test
public void all_records_are_readable_state_in_the_end() throws Exception {
HazelcastInstance member1 = factory.newHazelcastInstance();
HazelcastInstance member2 = factory.newHazelcastInstance();
Config config = new Config();
config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig());
HazelcastInstance nearCachedMember = factory.newHazelcastInstance(config);
IMap memberMap = member1.getMap(mapName);
// initial population of imap from member
for (int i = 0; i < KEY_SPACE; i++) {
memberMap.put(i, i);
}
List<Thread> threads = new ArrayList<Thread>();
// member
for (int i = 0; i < PUT_THREAD_COUNT; i++) {
Put put = new Put(memberMap);
threads.add(put);
}
// nearCachedMap
IMap nearCachedMap = nearCachedMember.getMap(mapName);
// member
for (int i = 0; i < PUT_LOCAL_THREAD_COUNT; i++) {
Put put = new Put(nearCachedMap);
threads.add(put);
}
for (int i = 0; i < GET_ALL_THREAD_COUNT; i++) {
GetAll getAll = new GetAll(nearCachedMap);
threads.add(getAll);
}
for (int i = 0; i < GET_THREAD_COUNT; i++) {
Get get = new Get(nearCachedMap);
threads.add(get);
}
for (int i = 0; i < REMOVE_THREAD_COUNT; i++) {
Remove remove = new Remove(nearCachedMap);
threads.add(remove);
}
for (int i = 0; i < CLEAR_THREAD_COUNT; i++) {
Clear clear = new Clear(nearCachedMap);
threads.add(clear);
}
// start threads
for (Thread thread : threads) {
thread.start();
}
// stress for a while
sleepSeconds(TEST_RUN_SECONDS);
// stop threads
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
assertFinalRecordStateIsReadPermitted(member1, ((NearCachedMapProxyImpl) nearCachedMap).getNearCache());
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class NearCacheBatchInvalidationTest method testBatchInvalidationRemovesEntries.
@Test
public void testBatchInvalidationRemovesEntries() throws Exception {
String mapName = randomMapName();
Config config = newConfig(mapName);
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
configureBatching(config, true, 12, 1);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
final IMap<Integer, Integer> map1 = node1.getMap(mapName);
final IMap<Integer, Integer> map2 = node2.getMap(mapName);
int size = 1000;
// fill map-1
for (int i = 0; i < size; i++) {
map1.put(i, i);
}
// fill Near Cache on node-1
for (int i = 0; i < size; i++) {
map1.get(i);
}
// fill Near Cache on node-2
for (int i = 0; i < size; i++) {
map2.get(i);
}
// generate invalidation data
for (int i = 0; i < size; i++) {
map1.put(i, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
assertEquals(0, nearCache1.size() + nearCache2.size());
}
});
}
Aggregations