Search in sources :

Example 26 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class MultiValueMapTest method query.

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

Example 27 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class MapPredicateTest method sqlString.

@TimeStep(prob = 0.2)
public void sqlString(ThreadState state) {
    long startMs = System.currentTimeMillis();
    boolean active = state.randomBoolean();
    int age = state.randomInt(Employee.MAX_AGE);
    SqlPredicate predicate = new SqlPredicate("active=" + active + " AND age >" + age);
    Collection<Employee> employees = map.values(predicate);
    for (Employee emp : employees) {
        String assertMessage = format(baseAssertMessage, emp, predicate);
        assertTrue(assertMessage, emp.isActive() == active);
        assertTrue(assertMessage, emp.getAge() > age);
    }
    state.operationCounter.sqlStringCount++;
    updateStats(state, startMs);
}
Also used : Employee(com.hazelcast.simulator.tests.map.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 28 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class MapPredicateTest method updateEmployee.

@TimeStep(prob = 0.3)
public void updateEmployee(ThreadState state) {
    Integer key = state.randomInt(keyCount);
    Employee employee = map.get(key);
    if (employee != null) {
        employee.randomizeProperties();
        map.put(key, employee);
        state.operationCounter.updateEmployeeCount++;
    }
}
Also used : Employee(com.hazelcast.simulator.tests.map.helpers.Employee) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 29 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class MapReduceTest method mapReduce.

@TimeStep(prob = 0.5)
public void mapReduce(ThreadState state) throws Exception {
    JobTracker tracker = targetInstance.getJobTracker(Thread.currentThread().getName() + name);
    KeyValueSource<Integer, Employee> source = KeyValueSource.fromMap(map);
    Job<Integer, Employee> job = tracker.newJob(source);
    ICompletableFuture<Map<Integer, Set<Employee>>> future = job.mapper(new ModIdMapper(2)).combiner(new RangeIdCombinerFactory(10, 30)).reducer(new IdReducerFactory(10, 20, 30)).submit();
    Map<Integer, Set<Employee>> result = future.get();
    for (Set<Employee> set : result.values()) {
        for (Employee employee : set) {
            assertTrue(employee.getId() % 2 == 0);
            assertTrue(employee.getId() >= 10 && employee.getId() <= 30);
            assertTrue(employee.getId() != 10);
            assertTrue(employee.getId() != 20);
            assertTrue(employee.getId() != 30);
        }
    }
    state.operationCounter.mapReduce++;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) JobTracker(com.hazelcast.mapreduce.JobTracker) Employee(com.hazelcast.simulator.tests.map.helpers.Employee) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 30 with TimeStep

use of com.hazelcast.simulator.test.annotations.TimeStep in project hazelcast-simulator by hazelcast.

the class ProducerConsumerTest method consume.

@TimeStep(executionGroup = "consumer")
public void consume(ConsumerState state) throws Exception {
    Long item = workQueue.take();
    if (item.equals(-1L)) {
        workQueue.add(item);
        throw new StopException();
    }
    state.consumed++;
    Thread.sleep(state.randomInt(maxIntervalMillis));
}
Also used : IAtomicLong(com.hazelcast.core.IAtomicLong) StopException(com.hazelcast.simulator.test.StopException) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Aggregations

TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)32 IAtomicLong (com.hazelcast.core.IAtomicLong)6 Predicate (com.hazelcast.query.Predicate)6 Employee (com.hazelcast.simulator.tests.map.helpers.Employee)6 SqlPredicate (com.hazelcast.query.SqlPredicate)5 ILock (com.hazelcast.core.ILock)4 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)4 Duration (javax.cache.expiry.Duration)4 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)4 AsyncAtomicLong (com.hazelcast.core.AsyncAtomicLong)2 EntryObject (com.hazelcast.query.EntryObject)2 PagingPredicate (com.hazelcast.query.PagingPredicate)2 PredicateBuilder (com.hazelcast.query.PredicateBuilder)2 TestException (com.hazelcast.simulator.test.TestException)2 TransactionContext (com.hazelcast.transaction.TransactionContext)2 Cache (javax.cache.Cache)2 JsonObject (com.couchbase.client.java.document.json.JsonObject)1 IExecutorService (com.hazelcast.core.IExecutorService)1 IMap (com.hazelcast.core.IMap)1 JobTracker (com.hazelcast.mapreduce.JobTracker)1