Search in sources :

Example 21 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast-simulator by hazelcast.

the class ExtractorMapTest method query.

@TimeStep(prob = -1)
public void query(ThreadState state, Probe probe, @StartNanos long startedNanos) {
    int key = state.getRandomKey();
    int index = key % nestedValuesCount;
    String query = format("payloadFromExtractor[%d]", index);
    Predicate predicate = Predicates.equal(query, key);
    Collection<Object> result = null;
    try {
        result = map.values(predicate);
    } finally {
        probe.done(startedNanos);
    }
    if (throttlingLogger.requestLogSlot()) {
        throttlingLogger.logInSlot(Level.INFO, format("Query 'payloadFromExtractor[%d]= %d' returned %d results.", index, key, result.size()));
    }
    for (Object resultSillySequence : result) {
        state.assertValidSequence(key, resultSillySequence);
    }
}
Also used : Predicate(com.hazelcast.query.Predicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 22 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast-simulator by hazelcast.

the class MapGetVsQueryTest method predicateBuilder.

@TimeStep(prob = 0)
public void predicateBuilder(ThreadState state) {
    int id = state.randomInt(itemCount);
    EntryObject entryObject = new PredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.get("id").equal(id);
    map.values(predicate);
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 23 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast-simulator by hazelcast.

the class MapPredicateTest method pagePredicate.

@TimeStep(prob = 0.2)
public void pagePredicate(ThreadState state) {
    double maxSalary = state.randomDouble() * Employee.MAX_SALARY;
    Predicate predicate = Predicates.lessThan("salary", maxSalary);
    SalaryComparator salaryComparator = new SalaryComparator();
    PagingPredicate pagingPredicate = new PagingPredicate(predicate, salaryComparator, pageSize);
    Collection<Employee> employees;
    List<Employee> employeeList;
    do {
        employees = map.values(pagingPredicate);
        employeeList = fillListWithQueryResultSet(employees);
        Employee nextEmployee;
        Employee currentEmployee;
        for (int i = 0; i < employeeList.size() - 1; i++) {
            currentEmployee = employeeList.get(i);
            nextEmployee = employeeList.get(i + 1);
            // check the order & max salary
            assertTrue(format(baseAssertMessage, currentEmployee.getSalary(), predicate), currentEmployee.getSalary() <= nextEmployee.getSalary() && nextEmployee.getSalary() < maxSalary);
        }
        pagingPredicate.nextPage();
    } while (!employees.isEmpty());
    state.operationCounter.pagePredicateCount++;
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) Employee(com.hazelcast.simulator.tests.map.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 24 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast-simulator by hazelcast.

the class MapPredicateTest method predicateBuilder.

@TimeStep(prob = 0.2)
public void predicateBuilder(ThreadState state) {
    long startMs = System.currentTimeMillis();
    int age = state.randomInt(Employee.MAX_AGE);
    String name = Employee.getRandomName();
    // TODO: Still broken because it relies on reflection which is dog slow, so we need an explicit AgeNamePredicate
    EntryObject entryObject = new PredicateBuilder().getEntryObject();
    Predicate agePredicate = entryObject.get("age").lessThan(age);
    Predicate ageNamePredicate = entryObject.get("name").equal(name).and(agePredicate);
    Collection<Employee> employees = map.values(ageNamePredicate);
    for (Employee emp : employees) {
        String assertMessage = format(baseAssertMessage, emp, ageNamePredicate);
        assertTrue(assertMessage, emp.getAge() < age);
        assertTrue(assertMessage, emp.getName().equals(name));
    }
    state.operationCounter.predicateBuilderCount++;
    updateStats(state, startMs);
}
Also used : EntryObject(com.hazelcast.query.EntryObject) Employee(com.hazelcast.simulator.tests.map.helpers.Employee) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 25 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast-simulator by hazelcast.

the class SerializationStrategyTest method getByStringIndex.

@TimeStep(prob = 1)
public void getByStringIndex(ThreadState state) {
    String string = state.getUniqueString();
    Predicate predicate = Predicates.equal("stringVal", string);
    Set<Map.Entry<String, DomainObject>> entries = map.entrySet(predicate);
    throttlingLogger.log(Level.INFO, "GetByStringIndex: " + entries.size() + " entries");
}
Also used : Predicate(com.hazelcast.query.Predicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Aggregations

Predicate (com.hazelcast.query.Predicate)248 Test (org.junit.Test)165 QuickTest (com.hazelcast.test.annotation.QuickTest)159 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)105 HazelcastInstance (com.hazelcast.core.HazelcastInstance)38 MapListener (com.hazelcast.map.listener.MapListener)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)17 EntryListener (com.hazelcast.core.EntryListener)16 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)15 ArrayList (java.util.ArrayList)15 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)14 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)14 Value (com.hazelcast.query.SampleTestObjects.Value)10 SqlPredicate (com.hazelcast.query.SqlPredicate)10 Config (com.hazelcast.config.Config)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 EntryEvent (com.hazelcast.core.EntryEvent)8 Data (com.hazelcast.internal.serialization.Data)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 Indexes (com.hazelcast.query.impl.Indexes)8