use of com.hazelcast.query.SampleObjects.ValueType in project hazelcast by hazelcast.
the class QueryAdvancedTest method testMapWithIndexAfterShutDown.
@Test
public void testMapWithIndexAfterShutDown() {
Config config = getConfig();
String mapName = "default";
config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("typeName", false));
HazelcastInstance[] instances = createHazelcastInstanceFactory(3).newInstances(config);
final IMap<Integer, ValueType> map = instances[0].getMap(mapName);
final int sampleSize1 = 100;
final int sampleSize2 = 30;
int totalSize = sampleSize1 + sampleSize2;
for (int i = 0; i < sampleSize1; i++) {
map.put(i, new ValueType("type" + i));
}
for (int i = sampleSize1; i < totalSize; i++) {
map.put(i, new ValueType("typex"));
}
Collection typexValues = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, typexValues.size());
instances[1].shutdown();
assertEquals(totalSize, map.size());
assertTrueEventually(new AssertTask() {
public void run() {
final Collection values = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, values.size());
}
});
instances[2].shutdown();
assertEquals(totalSize, map.size());
assertTrueEventually(new AssertTask() {
public void run() {
final Collection values = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, values.size());
}
});
}
use of com.hazelcast.query.SampleObjects.ValueType in project hazelcast by hazelcast.
the class QueryIndexTest method testInnerIndex.
@Test(timeout = 1000 * 60)
public void testInnerIndex() {
HazelcastInstance instance = createHazelcastInstance();
IMap<String, SampleObjects.Value> map = instance.getMap("default");
map.addIndex("name", false);
map.addIndex("type.typeName", false);
for (int i = 0; i < 10; i++) {
Value v = new Value("name" + i, i < 5 ? null : new ValueType("type" + i), i);
map.put("" + i, v);
}
Predicate predicate = new PredicateBuilder().getEntryObject().get("type.typeName").in("type8", "type6");
Collection<SampleObjects.Value> values = map.values(predicate);
assertEquals(2, values.size());
List<String> typeNames = new ArrayList<String>();
for (Value configObject : values) {
typeNames.add(configObject.getType().getTypeName());
}
String[] array = typeNames.toArray(new String[typeNames.size()]);
Arrays.sort(array);
assertArrayEquals(typeNames.toString(), new String[] { "type6", "type8" }, array);
}
use of com.hazelcast.query.SampleObjects.ValueType in project hazelcast by hazelcast.
the class QueryIndexTest method testInnerIndexSql.
@Test(timeout = 1000 * 60)
public void testInnerIndexSql() {
HazelcastInstance instance = createHazelcastInstance();
IMap<String, SampleObjects.Value> map = instance.getMap("default");
map.addIndex("name", false);
map.addIndex("type.typeName", 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("type.typeName='type1'");
Collection<SampleObjects.Value> values = map.values(predicate);
assertEquals(1, values.size());
List<String> typeNames = new ArrayList<String>();
for (Value configObject : values) {
typeNames.add(configObject.getType().getTypeName());
}
assertArrayEquals(typeNames.toString(), new String[] { "type1" }, typeNames.toArray(new String[typeNames.size()]));
}
use of com.hazelcast.query.SampleObjects.ValueType in project hazelcast by hazelcast.
the class QueryBasicTest method testInPredicateWithEmptyArray.
@Test(timeout = 1000 * 60)
public void testInPredicateWithEmptyArray() {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config cfg = getConfig();
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 = new PredicateBuilder().getEntryObject().get("name").in(emptyArray);
final Collection<Value> values = map.values(predicate);
assertEquals(values.size(), 0);
}
use of com.hazelcast.query.SampleObjects.ValueType 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);
}
Aggregations