use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlIn.
@Test(timeout = 1000 * 90)
public void issue393SqlIn() {
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 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);
}
use of com.hazelcast.query.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method testQueryIndexNullValues.
@Test
public void testQueryIndexNullValues() {
final HazelcastInstance instance = createHazelcastInstance(getConfig());
final IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.SORTED, "name");
map.put("first", new Value("first", 1));
map.put("second", new Value(null, 2));
map.put("third", new Value(null, 3));
final Predicate predicate = Predicates.sql("name=null");
final Collection<Value> values = map.values(predicate);
final int[] expectedIndexValues = { 2, 3 };
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 issue393Fail.
@Test(timeout = 1000 * 90)
public void issue393Fail() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.SORTED, "qwe");
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.SampleTestObjects.Value in project hazelcast by hazelcast.
the class QueryBasicTest method testNotEqual.
@Test
public void testNotEqual() {
final HazelcastInstance instance = createHazelcastInstance(getConfig());
final IMap<String, Value> map = instance.getMap("default");
map.addIndex(IndexType.SORTED, "name");
map.put("first", new Value("first", 1));
map.put("second", new Value(null, 2));
map.put("third", new Value(null, 3));
final Predicate predicate = Predicates.sql("name != null");
final Collection<Value> values = map.values(predicate);
final int[] expectedIndexValues = { 1 };
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 testInPredicateWithEmptyArray.
@Test(timeout = 1000 * 90)
public void testInPredicateWithEmptyArray() {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config cfg = getConfig();
cfg.setProperty(QueryEngineImpl.DISABLE_MIGRATION_FALLBACK.getName(), "true");
HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
final IMap<String, Value> map = instance.getMap("default");
for (int i = 0; i < 10; i++) {
final Value v = new Value("name" + i, new ValueType("type" + i), i);
map.put("" + i, v);
}
String[] emptyArray = new String[2];
final Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("name").in(emptyArray);
final Collection<Value> values = map.values(predicate);
assertEquals(values.size(), 0);
}
Aggregations