Search in sources :

Example 1 with CollectionType

use of org.apache.geode.cache.query.types.CollectionType in project geode by apache.

the class PdxOrderByJUnitTest method compareResultsOfWithAndWithoutIndex.

public boolean compareResultsOfWithAndWithoutIndex(SelectResults[] r) {
    boolean ok = true;
    Set set1 = null;
    Set set2 = null;
    Iterator itert1 = null;
    Iterator itert2 = null;
    ObjectType type1, type2;
    // outer: for (int j = 0; j < r.length; j++) {
    CollectionType collType1 = r[0].getCollectionType();
    CollectionType collType2 = r[1].getCollectionType();
    type1 = collType1.getElementType();
    type2 = collType2.getElementType();
    if (r[0].size() == r[1].size()) {
        System.out.println("Both SelectResults are of Same Size i.e.  Size= " + r[1].size());
    } else {
        System.out.println("FAILED4: SelectResults size is different in both the cases. Size1=" + r[0].size() + " Size2 = " + r[1].size());
        ok = false;
    }
    if (ok) {
        set2 = (((SelectResults) r[1]).asSet());
        set1 = (((SelectResults) r[0]).asSet());
        boolean pass = true;
        itert1 = set1.iterator();
        while (itert1.hasNext()) {
            Object p1 = itert1.next();
            itert2 = set2.iterator();
            boolean exactMatch = false;
            while (itert2.hasNext()) {
                Object p2 = itert2.next();
                if (p1 instanceof Struct) {
                    Object[] values1 = ((Struct) p1).getFieldValues();
                    Object[] values2 = ((Struct) p2).getFieldValues();
                    // test.assertIndexDetailsEquals(values1.length, values2.length);
                    if (values1.length != values2.length) {
                        ok = false;
                        break;
                    }
                    boolean elementEqual = true;
                    for (int i = 0; i < values1.length; ++i) {
                        elementEqual = elementEqual && ((values1[i] == values2[i]) || values1[i].equals(values2[i]));
                    }
                    exactMatch = elementEqual;
                } else {
                    exactMatch = (p2 == p1) || p2.equals(p1);
                }
                if (exactMatch) {
                    break;
                }
            }
            if (!exactMatch) {
                System.out.println("FAILED5: Atleast one element in the pair of SelectResults supposedly identical, is not equal ");
                ok = false;
                break;
            }
        }
    }
    return ok;
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) Set(java.util.Set) SelectResults(org.apache.geode.cache.query.SelectResults) CollectionType(org.apache.geode.cache.query.types.CollectionType) Iterator(java.util.Iterator) Struct(org.apache.geode.cache.query.Struct)

Example 2 with CollectionType

use of org.apache.geode.cache.query.types.CollectionType in project geode by apache.

the class CacheUtils method compareResultsOfWithAndWithoutIndex.

public static boolean compareResultsOfWithAndWithoutIndex(SelectResults[][] r) {
    boolean ok = true;
    Set set1;
    Set set2;
    Iterator itert1;
    Iterator itert2;
    ObjectType type1;
    ObjectType type2;
    // TODO: eliminate loop labels
    outer: for (final SelectResults[] aR : r) {
        CollectionType collType1 = aR[0].getCollectionType();
        CollectionType collType2 = aR[1].getCollectionType();
        type1 = collType1.getElementType();
        type2 = collType2.getElementType();
        if (collType1.getSimpleClassName().equals(collType2.getSimpleClassName())) {
            log("Both SelectResults are of the same Type i.e.--> " + collType1);
        } else {
            log("Collection type are : " + collType1 + "and  " + collType2);
            // test.fail("FAILED:Select results Collection Type is different in both the cases.
            // CollectionType1="+collType1 + " CollectionType2="+collType2);
            ok = false;
            break;
        }
        if (type1.equals(type2)) {
            log("Both SelectResults have same element Type i.e.--> " + type1);
        } else {
            log("Classes are :  type1=" + type1.getSimpleClassName() + " type2= " + type2.getSimpleClassName());
            // test.fail("FAILED:SelectResult Element Type is different in both the cases. Type1="+
            // type1 + " Type2="+ type2);
            ok = false;
            break;
        }
        if (collType1.equals(collType2)) {
            log("Both SelectResults are of the same Type i.e.--> " + collType1);
        } else {
            log("Collections are : " + collType1 + " " + collType2);
            // test.fail("FAILED:SelectResults Collection Type is different in both the cases.
            // CollType1="+ collType1 + " CollType2="+ collType2);
            ok = false;
            break;
        }
        if (aR[0].size() == aR[1].size()) {
            log("Both SelectResults are of Same Size i.e.  Size= " + aR[1].size());
        } else {
            // test.fail("FAILED:SelectResults size is different in both the cases. Size1=" +
            // r[j][0].size() + " Size2 = " + r[j][1].size());
            ok = false;
            break;
        }
        set2 = aR[1].asSet();
        set1 = aR[0].asSet();
        itert1 = set1.iterator();
        while (itert1.hasNext()) {
            Object p1 = itert1.next();
            itert2 = set2.iterator();
            boolean exactMatch = false;
            while (itert2.hasNext()) {
                Object p2 = itert2.next();
                if (p1 instanceof Struct) {
                    Object[] values1 = ((Struct) p1).getFieldValues();
                    Object[] values2 = ((Struct) p2).getFieldValues();
                    if (values1.length != values2.length) {
                        ok = false;
                        break outer;
                    }
                    boolean elementEqual = true;
                    for (int i = 0; i < values1.length; ++i) {
                        if (values1[i] != null) {
                            elementEqual = elementEqual && (values1[i] == values2[i] || values1[i].equals(values2[i]));
                        } else {
                            elementEqual = elementEqual && values1[i] == values2[i];
                        }
                    }
                    exactMatch = elementEqual;
                } else {
                    exactMatch = p2 == p1 || p2.equals(p1);
                }
                if (exactMatch) {
                    break;
                }
            }
            if (!exactMatch) {
                ok = false;
                break outer;
            }
        }
    }
    return ok;
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) Set(java.util.Set) CollectionType(org.apache.geode.cache.query.types.CollectionType) Iterator(java.util.Iterator)

Example 3 with CollectionType

use of org.apache.geode.cache.query.types.CollectionType in project geode by apache.

the class CacheUtils method compareResultsOfWithAndWithoutIndex.

public static void compareResultsOfWithAndWithoutIndex(SelectResults[][] r, Object test) {
    Set set1;
    Set set2;
    Iterator itert1;
    Iterator itert2;
    ObjectType type1;
    ObjectType type2;
    for (final SelectResults[] selectResults : r) {
        CollectionType collType1 = selectResults[0].getCollectionType();
        CollectionType collType2 = selectResults[1].getCollectionType();
        type1 = collType1.getElementType();
        type2 = collType2.getElementType();
        if (collType1.getSimpleClassName().equals(collType2.getSimpleClassName())) {
            log("Both SelectResults are of the same Type i.e.--> " + collType1);
        } else {
            log("Collection type are : " + collType1 + "and  " + collType2);
            fail("FAILED:Select results Collection Type is different in both the cases. CollectionType1=" + collType1 + " CollectionType2=" + collType2);
        }
        if (type1.equals(type2)) {
            log("Both SelectResults have same element Type i.e.--> " + type1);
        } else {
            log("Classes are :  type1=" + type1.getSimpleClassName() + " type2= " + type2.getSimpleClassName());
            fail("FAILED:SelectResult Element Type is different in both the cases. Type1=" + type1 + " Type2=" + type2);
        }
        if (collType1.equals(collType2)) {
            log("Both SelectResults are of the same Type i.e.--> " + collType1);
        } else {
            log("Collections are : " + collType1 + " " + collType2);
            fail("FAILED:SelectResults Collection Type is different in both the cases. CollType1=" + collType1 + " CollType2=" + collType2);
        }
        if (selectResults[0].size() == selectResults[1].size()) {
            log("Both SelectResults are of Same Size i.e.  Size= " + selectResults[1].size());
        } else {
            fail("FAILED:SelectResults size is different in both the cases. Size1=" + selectResults[0].size() + " Size2 = " + selectResults[1].size());
        }
        set2 = selectResults[1].asSet();
        set1 = selectResults[0].asSet();
        itert1 = set1.iterator();
        while (itert1.hasNext()) {
            Object p1 = itert1.next();
            itert2 = set2.iterator();
            boolean exactMatch = false;
            while (itert2.hasNext()) {
                Object p2 = itert2.next();
                if (p1 instanceof Struct) {
                    Object[] values1 = ((Struct) p1).getFieldValues();
                    Object[] values2 = ((Struct) p2).getFieldValues();
                    assertEquals(values1.length, values2.length);
                    boolean elementEqual = true;
                    for (int i = 0; i < values1.length; ++i) {
                        elementEqual = elementEqual && (values1[i] == values2[i] || values1[i].equals(values2[i]));
                    }
                    exactMatch = elementEqual;
                } else {
                    exactMatch = p2 == p1 || p2.equals(p1);
                }
                if (exactMatch) {
                    break;
                }
            }
            if (!exactMatch) {
                fail("At least one element in the pair of SelectResults supposedly identical, is not equal");
            }
        }
    }
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) Set(java.util.Set) CollectionType(org.apache.geode.cache.query.types.CollectionType) Iterator(java.util.Iterator)

Example 4 with CollectionType

use of org.apache.geode.cache.query.types.CollectionType in project geode by apache.

the class PdxStringQueryDUnitTest method compareResultsOfWithAndWithoutIndex.

public boolean compareResultsOfWithAndWithoutIndex(SelectResults[][] r) {
    boolean ok = true;
    Set set1 = null;
    Set set2 = null;
    Iterator itert1 = null;
    Iterator itert2 = null;
    ObjectType type1, type2;
    outer: for (int j = 0; j < r.length; j++) {
        CollectionType collType1 = r[j][0].getCollectionType();
        CollectionType collType2 = r[j][1].getCollectionType();
        type1 = collType1.getElementType();
        type2 = collType2.getElementType();
        if (r[j][0].size() == r[j][1].size()) {
            System.out.println("Both SelectResults are of Same Size i.e.  Size= " + r[j][1].size());
        } else {
            System.out.println("FAILED4: SelectResults size is different in both the cases. Size1=" + r[j][0].size() + " Size2 = " + r[j][1].size());
            ok = false;
            break;
        }
        set2 = (((SelectResults) r[j][1]).asSet());
        set1 = (((SelectResults) r[j][0]).asSet());
        boolean pass = true;
        itert1 = set1.iterator();
        while (itert1.hasNext()) {
            Object p1 = itert1.next();
            itert2 = set2.iterator();
            boolean exactMatch = false;
            while (itert2.hasNext()) {
                Object p2 = itert2.next();
                if (p1 instanceof Struct) {
                    Object[] values1 = ((Struct) p1).getFieldValues();
                    Object[] values2 = ((Struct) p2).getFieldValues();
                    // test.assertIndexDetailsEquals(values1.length, values2.length);
                    if (values1.length != values2.length) {
                        ok = false;
                        break outer;
                    }
                    boolean elementEqual = true;
                    for (int i = 0; i < values1.length; ++i) {
                        elementEqual = elementEqual && ((values1[i] == values2[i]) || values1[i].equals(values2[i]));
                    }
                    exactMatch = elementEqual;
                } else {
                    exactMatch = (p2 == p1) || p2.equals(p1);
                }
                if (exactMatch) {
                    break;
                }
            }
            if (!exactMatch) {
                System.out.println("FAILED5: Atleast one element in the pair of SelectResults supposedly identical, is not equal ");
                ok = false;
                break outer;
            }
        }
    }
    return ok;
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) Set(java.util.Set) CollectionType(org.apache.geode.cache.query.types.CollectionType) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Iterator(java.util.Iterator) Struct(org.apache.geode.cache.query.Struct)

Example 5 with CollectionType

use of org.apache.geode.cache.query.types.CollectionType in project geode by apache.

the class StructMemberAccessJUnitTest method testResultComposition.

@Test
public void testResultComposition() throws Exception {
    String[] queries = { "select distinct p from /Portfolios p where p.ID > 0", "select distinct p.getID from /Portfolios p where p.ID > 0 ", "select distinct p.getID as secID from /Portfolios p where p.ID > 0 " };
    for (int i = 0; i < queries.length; i++) {
        Query q = CacheUtils.getQueryService().newQuery(queries[i]);
        Object o = q.execute();
        if (o instanceof SelectResults) {
            SelectResults sr = (SelectResults) o;
            if (sr instanceof StructSet && i != 2)
                fail(" StructMemberAccess::testResultComposition: Got StrcutSet when expecting ResultSet");
            CollectionType ct = sr.getCollectionType();
            CacheUtils.log("***Elememt Type of Colelction = " + ct.getElementType());
            CacheUtils.log((sr.getCollectionType()).getElementType().getSimpleClassName());
            List ls = sr.asList();
            for (int j = 0; j < ls.size(); ++j) CacheUtils.log("Object in the resultset = " + ls.get(j).getClass());
            switch(i) {
                case 0:
                    if (ct.getElementType().getSimpleClassName().equals("Portfolio")) {
                        assertTrue(true);
                    } else {
                        System.out.println("StructMemberAcessJUnitTest::testResultComposition:Colelction Element's class=" + ct.getElementType().getSimpleClassName());
                        fail();
                    }
                    break;
                case 1:
                    if (ct.getElementType().getSimpleClassName().equals("int")) {
                        assertTrue(true);
                    } else {
                        System.out.println("StructMemberAcessJUnitTest::testResultComposition:Colelction Element's class=" + ct.getElementType().getSimpleClassName());
                        fail();
                    }
                    break;
                case 2:
                    if (ct.getElementType().getSimpleClassName().equals("Struct")) {
                        assertTrue(true);
                    } else {
                        System.out.println("StructMemberAcessJUnitTest::testResultComposition:Colelction Element's class=" + ct.getElementType().getSimpleClassName());
                        fail();
                    }
            }
        }
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) StructSet(org.apache.geode.cache.query.internal.StructSet) Query(org.apache.geode.cache.query.Query) CollectionType(org.apache.geode.cache.query.types.CollectionType) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CollectionType (org.apache.geode.cache.query.types.CollectionType)7 Iterator (java.util.Iterator)6 ObjectType (org.apache.geode.cache.query.types.ObjectType)5 Set (java.util.Set)4 SelectResults (org.apache.geode.cache.query.SelectResults)4 Collection (java.util.Collection)2 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)2 Struct (org.apache.geode.cache.query.Struct)2 IOException (java.io.IOException)1 List (java.util.List)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 Query (org.apache.geode.cache.query.Query)1 QueryException (org.apache.geode.cache.query.QueryException)1 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)1 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)1 StructSet (org.apache.geode.cache.query.internal.StructSet)1 CollectionTypeImpl (org.apache.geode.cache.query.internal.types.CollectionTypeImpl)1 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)1 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)1 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)1