use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlInInteger.
@Test(timeout = 1000 * 60)
public void issue393SqlInInteger() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("index", false);
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i, new ValueType("type" + i), i);
map.put("" + i, v);
}
Predicate predicate = new SqlPredicate("index IN (0, 2)");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0", "name2" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<String>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[names.size()]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.
/**
* see pull request 616
*/
@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeWithSqlIssue597() {
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);
}
Collection<Value> values = map.values(new SqlPredicate("state = 'STATE1'"));
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);
}
use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393Fail.
@Test(timeout = 1000 * 60)
public void issue393Fail() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("qwe", true);
Value v = new Value("name");
try {
map.put("0", v);
fail();
} catch (Throwable e) {
assertContains(e.getMessage(), "There is no suitable accessor for 'qwe'");
}
}
use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlIn.
@Test(timeout = 1000 * 60)
public void issue393SqlIn() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("name", true);
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i);
map.put("" + i, v);
}
Predicate predicate = new SqlPredicate("name IN ('name0', 'name2')");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0", "name2" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<String>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[names.size()]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.SampleObjects.Value in project hazelcast by hazelcast.
the class PredicatesTest method testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed.
@Test
public void testAndPredicate_whenFirstIndexAwarePredicateIsNotIndexed() throws Exception {
final HazelcastInstance instance = createHazelcastInstance();
final IMap<Object, Object> map = instance.getMap("map");
map.addIndex("name", false);
String name = randomString();
map.put("key", new Value(name));
final ShouldExecuteOncePredicate<?, ?> indexAwareNotIndexedPredicate = new ShouldExecuteOncePredicate<Object, Object>();
final EqualPredicate equalPredicate = new EqualPredicate("name", name);
final AndPredicate andPredicate = new AndPredicate(indexAwareNotIndexedPredicate, equalPredicate);
map.values(andPredicate);
}
Aggregations