Search in sources :

Example 11 with Value

use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.

the class QueryIndexTest method testPredicateNotEqualWithIndex.

@Test(timeout = 1000 * 60)
public void testPredicateNotEqualWithIndex() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, Value> map1 = instance.getMap("testPredicateNotEqualWithIndex-ordered");
    IMap<Integer, Value> map2 = instance.getMap("testPredicateNotEqualWithIndex-unordered");
    testPredicateNotEqualWithIndex(map1, true);
    testPredicateNotEqualWithIndex(map2, false);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleObjects.Value) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with Value

use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.

the class QueryBasicTest method testIndexingEnumAttributeIssue597.

@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex("state", true);
    for (int i = 0; i < 4; i++) {
        Value v = new Value(i % 2 == 0 ? State.STATE1 : State.STATE2, new ValueType(), i);
        map.put(i, v);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("state").equal(State.STATE1);
    Collection<Value> values = map.values(predicate);
    int[] expectedValues = new int[] { 0, 2 };
    assertEquals(expectedValues.length, values.size());
    int[] indexes = new int[2];
    int index = 0;
    for (Value configObject : values) {
        indexes[index++] = configObject.getIndex();
    }
    Arrays.sort(indexes);
    assertArrayEquals(indexes, expectedValues);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with Value

use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.

the class QueryIndexMigrationTest method updateMapAndRunQuery.

private void updateMapAndRunQuery(final IMap<Object, Value> map, final int runCount) {
    String name = randomString();
    Predicate<?, ?> predicate = equal("name", name);
    map.put(name, new Value(name, 0));
    // helper call on nodes to sync partitions (see issue github.com/hazelcast/hazelcast/issues/1282)
    map.size();
    for (int i = 1; i <= runCount && !interrupted(); i++) {
        Value value = map.get(name);
        value.setIndex(i);
        map.put(name, value);
        sleepMillis(random.nextInt(100) + 1);
        Collection<Value> values = map.values(predicate);
        assertEquals(1, values.size());
        Value firstValue = IterableUtil.getFirst(values, null);
        assertEquals(value, firstValue);
    }
}
Also used : Value(com.hazelcast.query.SampleObjects.Value)

Example 14 with Value

use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.

the class QueryIndexMigrationTest method fillMap.

private static void fillMap(IMap<Object, Object> map, final String value, final int count, final int modulo) {
    for (int i = 0; i < count; i++) {
        String name = randomString();
        if (i % modulo == 0) {
            name = value;
        }
        map.put(randomString(), new Value(name, i));
    }
}
Also used : Value(com.hazelcast.query.SampleObjects.Value)

Example 15 with Value

use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.

the class QueryIndexMigrationTest method testIndexCleanupOnMigration.

/**
     * test for issue #359
     */
@Test(timeout = 4 * MINUTE)
public void testIndexCleanupOnMigration() throws Exception {
    int nodeCount = 6;
    final int runCount = 500;
    final Config config = newConfigWithIndex("testMap", "name");
    executor = Executors.newFixedThreadPool(nodeCount);
    List<Future<?>> futures = new ArrayList<Future<?>>();
    for (int i = 0; i < nodeCount; i++) {
        sleepMillis(random.nextInt((i + 1) * 100) + 10);
        futures.add(executor.submit(new Runnable() {

            public void run() {
                HazelcastInstance hz = nodeFactory.newHazelcastInstance(config);
                IMap<Object, Value> map = hz.getMap("testMap");
                updateMapAndRunQuery(map, runCount);
            }
        }));
    }
    for (Future<?> future : futures) {
        future.get();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) ArrayList(java.util.ArrayList) Value(com.hazelcast.query.SampleObjects.Value) Future(java.util.concurrent.Future) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Value (com.hazelcast.query.SampleObjects.Value)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Test (org.junit.Test)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 SqlPredicate (com.hazelcast.query.SqlPredicate)13 Predicate (com.hazelcast.query.Predicate)9 ArrayList (java.util.ArrayList)7 PredicateBuilder (com.hazelcast.query.PredicateBuilder)6 ValueType (com.hazelcast.query.SampleObjects.ValueType)6 Config (com.hazelcast.config.Config)2 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 EntryObject (com.hazelcast.query.EntryObject)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 Future (java.util.concurrent.Future)1 Matchers.anyString (org.mockito.Matchers.anyString)1