use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method testLesserEqual.
@Test
public void testLesserEqual() {
final HazelcastInstance instance = createHazelcastInstance(getConfig());
final IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.SORTED, "index");
for (int i = 0; i < 10; i++) {
map.put("" + i, new Value("" + i, i));
}
final Predicate predicate = Predicates.sql("index<=5");
final Collection<Value> values = map.values(predicate);
final int[] expectedIndexValues = new int[6];
for (int i = 0; i < expectedIndexValues.length; i++) {
expectedIndexValues[i] = i;
}
assertEquals(expectedIndexValues.length, values.size());
final int[] actualIndexValues = new int[values.size()];
int i = 0;
for (Value value : values) {
actualIndexValues[i++] = value.getIndex();
}
Arrays.sort(actualIndexValues);
assertArrayEquals(expectedIndexValues, actualIndexValues);
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlInInteger.
@Test(timeout = 1000 * 90)
public void issue393SqlInInteger() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.HASH, "index");
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("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<>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[0]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlEq.
@Test(timeout = 1000 * 90)
public void issue393SqlEq() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.SORTED, "name");
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i);
map.put("" + i, v);
}
Predicate predicate = Predicates.sql("name='name0'");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[0]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.
/**
* see pull request 616
*/
@Test(timeout = 1000 * 90)
public void testIndexingEnumAttributeWithSqlIssue597() {
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);
}
Collection<Value> values = map.values(Predicates.sql("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.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393.
@Test(timeout = 1000 * 90)
public void issue393() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.SORTED, "name");
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i);
map.put("" + i, v);
}
Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("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<>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[0]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
Aggregations