Search in sources :

Example 1 with PdxString

use of org.apache.geode.pdx.internal.PdxString in project geode by apache.

the class PdxStringJUnitTest method testHashCodeEquals.

@Test
public void testHashCodeEquals() throws Exception {
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeString("secId", "abc");
    PdxInstanceImpl pi = (PdxInstanceImpl) pf.create();
    PdxString pdx1 = (PdxString) pi.getRawField("secId");
    Map<PdxString, String> map = new HashMap<PdxString, String>();
    map.put(pdx1, "abc");
    PdxString pdx2 = new PdxString("abc");
    assertEquals(map.get(pdx2), "abc");
    map = new Object2ObjectOpenHashMap();
    map.put(pdx1, "abc");
    assertEquals(map.get(pdx2), "abc");
}
Also used : Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) HashMap(java.util.HashMap) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) PdxString(org.apache.geode.pdx.internal.PdxString) PdxString(org.apache.geode.pdx.internal.PdxString) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with PdxString

use of org.apache.geode.pdx.internal.PdxString in project geode by apache.

the class PdxStringJUnitTest method testEquals.

@Test
public void testEquals() throws Exception {
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeString("secId", "abc");
    PdxInstanceImpl pi = (PdxInstanceImpl) pf.create();
    PdxString pdx1 = (PdxString) pi.getRawField("secId");
    assertEquals(false, pdx1.equals(null));
    assertEquals(false, pdx1.equals(new Date(37)));
    PdxString pdx2 = new PdxString("abc");
    assertEquals(pdx1, pdx2);
    pdx2 = new PdxString("ABC");
    assertEquals(false, pdx1.equals(pdx2));
}
Also used : PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) PdxString(org.apache.geode.pdx.internal.PdxString) Date(java.util.Date) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with PdxString

use of org.apache.geode.pdx.internal.PdxString in project geode by apache.

the class PdxStringQueryJUnitTest method testQueriesWithCompactRangeIndexPdxInstances.

@Test
public void testQueriesWithCompactRangeIndexPdxInstances() throws Exception {
    Index index = qs.createIndex("index1", "secId", "/exampleRegion");
    assertTrue(index instanceof CompactRangeIndex);
    putPdxInstances();
    CloseableIterator<IndexStoreEntry> indexIterator = null;
    try {
        indexIterator = ((CompactRangeIndex) index).getIndexStorage().iterator(null);
        while (indexIterator.hasNext()) {
            assertTrue(indexIterator.next().getDeserializedKey() instanceof PdxString);
        }
    } finally {
        if (indexIterator != null) {
            indexIterator.close();
        }
    }
    executeQueriesValidateResults(INDEX_TYPE_COMPACTRANGE);
    r.clear();
}
Also used : CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) IndexStoreEntry(org.apache.geode.cache.query.internal.index.IndexStore.IndexStoreEntry) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) PdxString(org.apache.geode.pdx.internal.PdxString) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with PdxString

use of org.apache.geode.pdx.internal.PdxString in project geode by apache.

the class PdxStringQueryJUnitTest method testQueriesWithRangeIndex.

@Test
public void testQueriesWithRangeIndex() throws Exception {
    Index index = qs.createIndex("index2", "p.secId", "/exampleRegion p, p.positions.values");
    assertTrue(index instanceof RangeIndex);
    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 111);
    pf.writeString("secId", "IBM");
    pf.writeString("status", "active");
    HashMap positions = new HashMap();
    positions.put("price", "50");
    positions.put("price", "60");
    pf.writeObject("positions", positions);
    PdxInstance pi = pf.create();
    r.put("IBM", pi);
    positions = new HashMap();
    positions.put("price", "100");
    positions.put("price", "120");
    r.put("YHOO", new TestObject(222, "YHOO", positions, "inactive"));
    pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
    pf.writeInt("ID", 333);
    pf.writeString("secId", "GOOGL");
    pf.writeString("status", "active");
    positions = new HashMap();
    positions.put("price", "130");
    positions.put("price", "150");
    pf.writeObject("positions", positions);
    pi = pf.create();
    positions = new HashMap();
    positions.put("price", "200");
    positions.put("price", "220");
    r.put("VMW", new TestObject(111, "VMW", positions, "inactive"));
    r.put("GOOGL", pi);
    Map map = ((RangeIndex) index).getValueToEntriesMap();
    for (Object key : map.keySet()) {
        assertTrue(key instanceof PdxString);
    }
    executeQueriesValidateResults(INDEX_TYPE_RANGE);
    qs.removeIndex(index);
    r.clear();
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory) PdxInstance(org.apache.geode.pdx.PdxInstance) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) PdxString(org.apache.geode.pdx.internal.PdxString) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with PdxString

use of org.apache.geode.pdx.internal.PdxString in project geode by apache.

the class PdxStringQueryJUnitTest method testQueriesWithCompactRangeIndexPdxInstancesREUpdateInProgress.

@Test
public void testQueriesWithCompactRangeIndexPdxInstancesREUpdateInProgress() throws Exception {
    Index index = qs.createIndex("index1", "secId", "/exampleRegion");
    assertTrue(index instanceof CompactRangeIndex);
    putPdxInstancesWithREUpdateInProgress();
    CloseableIterator<IndexStoreEntry> indexIterator = null;
    try {
        indexIterator = ((CompactRangeIndex) index).getIndexStorage().iterator(null);
        while (indexIterator.hasNext()) {
            assertTrue(indexIterator.next().getDeserializedKey() instanceof PdxString);
        }
    } finally {
        if (indexIterator != null) {
            indexIterator.close();
        }
    }
    executeQueriesValidateResults(INDEX_TYPE_COMPACTRANGE);
    r.clear();
}
Also used : CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) IndexStoreEntry(org.apache.geode.cache.query.internal.index.IndexStore.IndexStoreEntry) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) PdxString(org.apache.geode.pdx.internal.PdxString) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PdxString (org.apache.geode.pdx.internal.PdxString)36 Test (org.junit.Test)22 Region (org.apache.geode.cache.Region)13 CacheException (org.apache.geode.cache.CacheException)11 CompactRangeIndex (org.apache.geode.cache.query.internal.index.CompactRangeIndex)11 RangeIndex (org.apache.geode.cache.query.internal.index.RangeIndex)11 SelectResults (org.apache.geode.cache.query.SelectResults)10 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)10 Host (org.apache.geode.test.dunit.Host)10 VM (org.apache.geode.test.dunit.VM)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)10 QueryService (org.apache.geode.cache.query.QueryService)9 PdxInstance (org.apache.geode.pdx.PdxInstance)9 IOException (java.io.IOException)8 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)8 IgnoredException (org.apache.geode.test.dunit.IgnoredException)8 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)7 Index (org.apache.geode.cache.query.Index)7