Search in sources :

Example 46 with Data

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());
}
Also used : AbstractRecord(com.hazelcast.map.impl.record.AbstractRecord) TestUtil.toData(com.hazelcast.instance.TestUtil.toData) Data(com.hazelcast.nio.serialization.Data) AbstractRecord(com.hazelcast.map.impl.record.AbstractRecord) Record(com.hazelcast.map.impl.record.Record) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with Data

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());
}
Also used : TestUtil.toData(com.hazelcast.instance.TestUtil.toData) Data(com.hazelcast.nio.serialization.Data) AbstractRecord(com.hazelcast.map.impl.record.AbstractRecord) Record(com.hazelcast.map.impl.record.Record)

Example 48 with Data

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());
}
Also used : AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) TestUtil.toData(com.hazelcast.instance.TestUtil.toData) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with Data

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());
}
Also used : TestUtil.toData(com.hazelcast.instance.TestUtil.toData) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with Data

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);
}
Also used : Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Data (com.hazelcast.nio.serialization.Data)773 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)140 Test (org.junit.Test)121 QuickTest (com.hazelcast.test.annotation.QuickTest)118 ParallelTest (com.hazelcast.test.annotation.ParallelTest)108 ArrayList (java.util.ArrayList)81 Map (java.util.Map)64 SerializationService (com.hazelcast.spi.serialization.SerializationService)54 HashMap (java.util.HashMap)54 NodeEngine (com.hazelcast.spi.NodeEngine)50 HashSet (java.util.HashSet)39 Address (com.hazelcast.nio.Address)28 AbstractMap (java.util.AbstractMap)28 Record (com.hazelcast.map.impl.record.Record)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 HeapData (com.hazelcast.internal.serialization.impl.HeapData)26 List (java.util.List)20 Future (java.util.concurrent.Future)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 Operation (com.hazelcast.spi.Operation)18