use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryIndexingTest method assertGettersCalledNTimes.
private static void assertGettersCalledNTimes(Collection<Employee> matchingEmployees, int expectedCalls) {
for (Employee employee : matchingEmployees) {
verify(employee, times(expectedCalls)).getCity();
verify(employee, times(expectedCalls)).getName();
}
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class SqlPredicateTest method testSql_withEnum.
@Test
public void testSql_withEnum() {
Employee value = createValue();
value.setState(SampleTestObjects.State.STATE2);
Employee nullNameValue = createValue(null);
assertSqlMatching("state == TestUtil.State.STATE2", value);
assertSqlMatching("state == " + SampleTestObjects.State.STATE2, value);
assertSqlNotMatching("state == TestUtil.State.STATE1", value);
assertSqlNotMatching("state == TestUtil.State.STATE1", nullNameValue);
assertSqlMatching("state == NULL", nullNameValue);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class PredicatesTest method testCriteriaAPI.
@Test
public void testCriteriaAPI() {
Object value = new Employee(12, "abc-123-xvz", 34, true, 10D);
EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
EntryObject e2 = e.get("age");
Predicate predicate = e2.greaterEqual(29).and(e2.lessEqual(36));
assertTrue(predicate.apply(createEntry("1", value)));
e = Predicates.newPredicateBuilder().getEntryObject();
assertTrue(e.get("id").equal(12).apply(createEntry("1", value)));
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class EvictionTest method testMaxIdle_readThroughIndex.
private void testMaxIdle_readThroughIndex(IndexType type) {
String mapName = randomMapName();
Config config = getConfig();
config.getMapConfig("default").setPerEntryStatsEnabled(true);
// "disable" the cleaner task
config.setProperty(PROP_TASK_PERIOD_SECONDS, Integer.toString(MAX_VALUE));
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Employee> map = node.getMap(mapName);
map.addIndex(type, "city");
int entryCount = 5;
Map<Integer, Long> lastAccessTimes = new HashMap<>();
for (int i = 0; i < entryCount; ++i) {
String cityName = i % 2 == 0 ? "cityname" : null;
Employee emp = new Employee(i, "name" + i, cityName, 0, true, i);
map.put(i, emp, 0L, SECONDS, 60L, SECONDS);
// we do get to set the last access time
map.get(i);
EntryView view = map.getEntryView(i);
long lastAccessTime = view.getLastAccessTime();
assertTrue(lastAccessTime > 0);
lastAccessTimes.put(i, lastAccessTime);
}
sleepAtLeastSeconds(1);
EntryObject entryObject = new PredicateBuilderImpl().getEntryObject();
Predicate predicateCityNull = entryObject.get("city").isNull();
Collection<Employee> valuesNullCity = map.values(predicateCityNull);
Collection<Employee> valuesNotNullCity = map.values(Predicates.equal("city", "cityname"));
assertEquals(entryCount, valuesNullCity.size() + valuesNotNullCity.size());
// check that evaluating the predicate didn't update the last access time of the returned records
for (int i = 0; i < entryCount; ++i) {
EntryView view = map.getEntryView(i);
assertNotNull(view);
long lastAccessTime = view.getLastAccessTime();
long prevLastAccessTime = lastAccessTimes.get(i);
assertTrue("lastAccessTime=" + lastAccessTime + ", prevLastAccessTime=" + prevLastAccessTime, lastAccessTime == prevLastAccessTime);
}
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.
@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() {
Config config = getConfig();
String mapName = "testIssue1115";
MapStore mapStore = new ProcessingStore();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(mapStore);
config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
nodeFactory.newHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap(mapName);
Random random = new Random();
// testing put with new object
for (int i = 0; i < 10; i++) {
Employee emp = new Employee();
emp.setAge(random.nextInt(20) + 20);
map.put(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with existing object
for (int i = 0; i < 10; i++) {
Employee emp = map.get(i);
emp.setAge(random.nextInt(20) + 20);
map.put(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with replace
for (int i = 0; i < 10; i++) {
Employee emp = map.get(i);
emp.setAge(random.nextInt(20) + 20);
map.replace(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with putIfAbsent
for (int i = 10; i < 20; i++) {
Employee emp = new Employee();
emp.setAge(random.nextInt(20) + 20);
map.putIfAbsent(i, emp);
}
for (int i = 10; i < 20; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
}
Aggregations