Search in sources :

Example 21 with Value

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

the class QueryBasicTest method testPredicateStringAttribute.

/**
 * Github issues 98 and 131
 */
@Test(timeout = 1000 * 90)
public void testPredicateStringAttribute() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("testPredicateStringWithString");
    testPredicateStringAttribute(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleTestObjects.Value) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with Value

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

the class QueryBasicTest method testIndexingEnumAttributeIssue597.

@Test(timeout = 1000 * 90)
public void testIndexingEnumAttributeIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "state");
    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 = Predicates.newPredicateBuilder().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.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with Value

use of com.hazelcast.query.SampleTestObjects.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<Object, Value> 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.SampleTestObjects.Value)

Example 24 with Value

use of com.hazelcast.query.SampleTestObjects.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) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) Value(com.hazelcast.query.SampleTestObjects.Value) Future(java.util.concurrent.Future) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 25 with Value

use of com.hazelcast.query.SampleTestObjects.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.SampleTestObjects.Value)

Aggregations

Value (com.hazelcast.query.SampleTestObjects.Value)25 Test (org.junit.Test)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)20 QuickTest (com.hazelcast.test.annotation.QuickTest)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 Predicate (com.hazelcast.query.Predicate)12 ArrayList (java.util.ArrayList)7 ValueType (com.hazelcast.query.SampleTestObjects.ValueType)6 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)1 SqlPredicate (com.hazelcast.query.impl.predicates.SqlPredicate)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 Future (java.util.concurrent.Future)1 Ignore (org.junit.Ignore)1