use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.
the class QueryIndexTest method testInnerIndexSql.
@Test(timeout = 1000 * 60)
public void testInnerIndexSql() {
HazelcastInstance instance = createTestHazelcastInstance();
IMap<String, SampleTestObjects.Value> map = instance.getMap("default");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.HASH, "type.typeName");
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i, new ValueType("type" + i), i);
map.put("" + i, v);
}
Predicate predicate = Predicates.sql("type.typeName='type1'");
Collection<SampleTestObjects.Value> values = map.values(predicate);
assertEquals(1, values.size());
List<String> typeNames = new ArrayList<>();
for (Value configObject : values) {
typeNames.add(configObject.getType().getTypeName());
}
assertArrayEquals(typeNames.toString(), new String[] { "type1" }, typeNames.toArray(new String[0]));
}
use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.
the class QueryBasicTest method testIteratorContract.
@Test(timeout = 1000 * 90)
public void testIteratorContract() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, SampleTestObjects.ValueType> map = instance.getMap("testIteratorContract");
map.put("1", new ValueType("one"));
map.put("2", new ValueType("two"));
map.put("3", new ValueType("three"));
Predicate predicate = Predicates.sql("typeName in ('one','two')");
assertEquals(2, map.values(predicate).size());
assertEquals(2, map.keySet(predicate).size());
testIterator(map.keySet().iterator(), 3);
testIterator(map.keySet(predicate).iterator(), 2);
testIterator(map.entrySet().iterator(), 3);
testIterator(map.entrySet(predicate).iterator(), 2);
testIterator(map.values().iterator(), 3);
testIterator(map.values(predicate).iterator(), 2);
}
use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.
the class QueryBasicTest method testInPredicate.
@Test(timeout = 1000 * 90)
public void testInPredicate() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, SampleTestObjects.ValueType> map = instance.getMap("testIteratorContract");
map.put("1", new ValueType("one"));
map.put("2", new ValueType("two"));
map.put("3", new ValueType("three"));
map.put("4", new ValueType("four"));
map.put("5", new ValueType("five"));
map.put("6", new ValueType("six"));
map.put("7", new ValueType("seven"));
Predicate predicate = Predicates.sql("typeName in ('one','two')");
for (int i = 0; i < 10; i++) {
Collection<SampleTestObjects.ValueType> values = map.values(predicate);
assertEquals(2, values.size());
}
}
use of com.hazelcast.query.SampleTestObjects.ValueType 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);
}
Aggregations