use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class IndexTest method testRemoveEnumIndex.
@Test
public void testRemoveEnumIndex() {
Indexes is = new Indexes(ss, Extractors.empty());
is.addOrGetIndex("favoriteCity", false);
Data key = ss.toData(1);
Data value = ss.toData(new SerializableWithEnum(SerializableWithEnum.City.ISTANBUL));
is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
assertNotNull(is.getIndex("favoriteCity"));
Record record = recordFactory.newRecord(value);
((AbstractRecord) record).setKey(key);
is.removeEntryIndex(key, Records.getValueOrCachedValue(record, ss));
assertEquals(0, is.getIndex("favoriteCity").getRecords(SerializableWithEnum.City.ISTANBUL).size());
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class IndexTest method testIt.
private void testIt(boolean ordered) {
IndexImpl index = new IndexImpl(QueryConstants.THIS_ATTRIBUTE_NAME.value(), ordered, ss, Extractors.empty());
assertEquals(0, index.getRecords(0L).size());
assertEquals(0, index.getSubRecordsBetween(0L, 1000L).size());
QueryRecord record5 = newRecord(5L, 55L);
index.saveEntryIndex(record5, null);
assertEquals(Collections.<QueryableEntry>singleton(record5), index.getRecords(55L));
QueryRecord record6 = newRecord(6L, 66L);
index.saveEntryIndex(record6, null);
assertEquals(Collections.<QueryableEntry>singleton(record6), index.getRecords(66L));
QueryRecord newRecord5 = newRecord(5L, 555L);
index.saveEntryIndex(newRecord5, record5.getValue());
record5 = newRecord5;
assertEquals(0, index.getRecords(55L).size());
assertEquals(Collections.<QueryableEntry>singleton(record5), index.getRecords(555L));
assertEquals(1, index.getRecords(555L).size());
assertEquals(2, index.getSubRecordsBetween(55L, 555L).size());
assertEquals(2, index.getSubRecordsBetween(66L, 555L).size());
assertEquals(1, index.getSubRecordsBetween(555L, 555L).size());
QueryRecord record50 = newRecord(50L, 555L);
index.saveEntryIndex(record50, null);
assertEquals(new HashSet<QueryableEntry>(asList(record5, record50)), index.getRecords(555L));
Map<Data, QueryableEntry> records = getRecordMap(index, 555L);
assertNotNull(records);
assertEquals(2, records.size());
assertEquals(record5, records.get(record5.getKeyData()));
assertEquals(record50, records.get(record50.getKeyData()));
assertEquals(2, index.getRecords(555L).size());
assertEquals(3, index.getSubRecordsBetween(55L, 555L).size());
assertEquals(3, index.getSubRecordsBetween(66L, 555L).size());
assertEquals(2, index.getSubRecordsBetween(555L, 555L).size());
assertEquals(0, index.getSubRecords(ComparisonType.LESSER, 66L).size());
assertEquals(1, index.getSubRecords(ComparisonType.LESSER_EQUAL, 66L).size());
assertEquals(1, index.getSubRecords(ComparisonType.LESSER_EQUAL, 67L).size());
assertEquals(2, index.getSubRecords(ComparisonType.GREATER, 66L).size());
assertEquals(3, index.getSubRecords(ComparisonType.GREATER_EQUAL, 66L).size());
assertEquals(3, index.getSubRecords(ComparisonType.GREATER_EQUAL, 61L).size());
assertEquals(3, index.getSubRecords(ComparisonType.NOT_EQUAL, 61L).size());
assertEquals(2, index.getSubRecords(ComparisonType.NOT_EQUAL, 66L).size());
assertEquals(1, index.getSubRecords(ComparisonType.NOT_EQUAL, 555L).size());
assertEquals(3, index.getRecords(new Comparable[] { 66L, 555L, 34234L }).size());
assertEquals(2, index.getRecords(new Comparable[] { 555L, 34234L }).size());
Record recordToRemove = record5.toRecord();
index.removeEntryIndex(recordToRemove.getKey(), Records.getValueOrCachedValue(recordToRemove, ss));
assertEquals(Collections.<QueryableEntry>singleton(record50), index.getRecords(555L));
records = getRecordMap(index, 555L);
assertNotNull(records);
assertEquals(null, records.get(5L));
assertEquals(record50, records.get(toData(50L)));
assertEquals(1, index.getRecords(555L).size());
assertEquals(2, index.getSubRecordsBetween(55L, 555L).size());
assertEquals(2, index.getSubRecordsBetween(66L, 555L).size());
assertEquals(1, index.getSubRecordsBetween(555L, 555L).size());
assertEquals(0, index.getSubRecords(ComparisonType.LESSER, 66L).size());
assertEquals(1, index.getSubRecords(ComparisonType.LESSER_EQUAL, 66L).size());
assertEquals(1, index.getSubRecords(ComparisonType.LESSER_EQUAL, 67L).size());
assertEquals(1, index.getSubRecords(ComparisonType.GREATER, 66L).size());
assertEquals(2, index.getSubRecords(ComparisonType.GREATER_EQUAL, 66L).size());
assertEquals(2, index.getSubRecords(ComparisonType.GREATER_EQUAL, 61L).size());
recordToRemove = record50.toRecord();
index.removeEntryIndex(recordToRemove.getKey(), Records.getValueOrCachedValue(recordToRemove, ss));
assertEquals(0, index.getRecords(555L).size());
records = getRecordMap(index, 555L);
assertNull(records);
assertEquals(0, index.getRecords(555L).size());
assertEquals(1, index.getSubRecordsBetween(55L, 555L).size());
assertEquals(1, index.getSubRecordsBetween(66L, 555L).size());
assertEquals(0, index.getSubRecordsBetween(555L, 555L).size());
recordToRemove = record6.toRecord();
index.removeEntryIndex(recordToRemove.getKey(), Records.getValueOrCachedValue(recordToRemove, ss));
assertEquals(0, index.getRecords(66L).size());
assertNull(getRecordMap(index, 66L));
assertEquals(0, index.getRecords(555L).size());
assertEquals(0, index.getSubRecordsBetween(55L, 555L).size());
assertEquals(0, index.getSubRecordsBetween(66L, 555L).size());
assertEquals(0, index.getSubRecordsBetween(555L, 555L).size());
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class IndexTest method testIndex.
@Test
public void testIndex() throws QueryException {
Indexes is = new Indexes(ss, Extractors.empty());
Index dIndex = is.addOrGetIndex("d", false);
Index boolIndex = is.addOrGetIndex("bool", false);
Index strIndex = is.addOrGetIndex("str", false);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(i % 2 == 0, -10.34d, "joe" + i));
is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
}
assertEquals(1000, dIndex.getRecords(-10.34d).size());
assertEquals(1, strIndex.getRecords("joe23").size());
assertEquals(500, boolIndex.getRecords(true).size());
clearIndexes(dIndex, boolIndex, strIndex);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(false, 11.34d, "joe"));
is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
}
assertEquals(0, dIndex.getRecords(-10.34d).size());
assertEquals(0, strIndex.getRecords("joe23").size());
assertEquals(1000, strIndex.getRecords("joe").size());
assertEquals(1000, boolIndex.getRecords(false).size());
assertEquals(0, boolIndex.getRecords(true).size());
clearIndexes(dIndex, boolIndex, strIndex);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(false, -1 * (i + 1), "joe" + i));
is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
}
assertEquals(0, dIndex.getSubRecordsBetween(1d, 1001d).size());
assertEquals(1000, dIndex.getSubRecordsBetween(-1d, -1001d).size());
clearIndexes(dIndex, boolIndex, strIndex);
for (int i = 0; i < 1000; i++) {
Data key = ss.toData(i);
Data value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i));
is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
}
assertEquals(1000, dIndex.getSubRecordsBetween(1d, 1001d).size());
assertEquals(0, dIndex.getSubRecordsBetween(-1d, -1001d).size());
assertEquals(400, dIndex.getSubRecords(ComparisonType.GREATER, 600d).size());
assertEquals(401, dIndex.getSubRecords(ComparisonType.GREATER_EQUAL, 600d).size());
assertEquals(9, dIndex.getSubRecords(ComparisonType.LESSER, 10d).size());
assertEquals(10, dIndex.getSubRecords(ComparisonType.LESSER_EQUAL, 10d).size());
assertEquals(1, is.query(new AndPredicate(new EqualPredicate("d", 1d), new EqualPredicate("bool", "false"))).size());
assertEquals(1, is.query(new AndPredicate(new EqualPredicate("d", 1), new EqualPredicate("bool", Boolean.FALSE))).size());
assertEquals(1, is.query(new AndPredicate(new EqualPredicate("d", "1"), new EqualPredicate("bool", false))).size());
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class IndexTest method testIndexWithNull.
@Test
public void testIndexWithNull() throws QueryException {
Indexes is = new Indexes(ss, Extractors.empty());
Index strIndex = is.addOrGetIndex("str", true);
Data value = ss.toData(new MainPortable(false, 1, null));
Data key1 = ss.toData(0);
is.saveEntryIndex(new QueryEntry(ss, key1, value, Extractors.empty()), null);
value = ss.toData(new MainPortable(false, 2, null));
Data key2 = ss.toData(1);
is.saveEntryIndex(new QueryEntry(ss, key2, value, Extractors.empty()), null);
for (int i = 2; i < 1000; i++) {
Data key = ss.toData(i);
value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i));
is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
}
assertEquals(2, strIndex.getRecords((Comparable) null).size());
assertEquals(998, strIndex.getSubRecords(ComparisonType.NOT_EQUAL, null).size());
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class CachedQueryEntryTest method testGetTargetObject_givenKeyDataIsPortable_whenKeyFlagIsTrue_thenReturnKeyData.
@Test
public void testGetTargetObject_givenKeyDataIsPortable_whenKeyFlagIsTrue_thenReturnKeyData() {
//given
Data keyData = mockPortableData();
QueryableEntry entry = entry(keyData, new Object(), Extractors.empty());
//when
Object targetObject = entry.getTargetObject(true);
//then
assertSame(keyData, targetObject);
}
Aggregations