Package com.mobixess.jodb.tests.testobjects

Examples of com.mobixess.jodb.tests.testobjects.ObjectA


        testFileDir.mkdirs();
        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
       
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        ObjectA objectA = new ObjectA((byte)1,(short)2,null);
        ObjectA objectA1 = new ObjectA((byte)3,(short)4,null);
        sessionContainer.set(objectA);
        sessionContainer.set(objectA1);
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        List classes = sessionContainer.getAllObjects();
        if(classes.size()!=2){
            throw new RuntimeException();
        }
        int index = classes.indexOf(objectA);
        if(index == -1){
            throw new RuntimeException();
        }
        Object obj = classes.get(index);
        if(obj.getClass() != objectA.getClass()){
            throw new RuntimeException();
        }
        ObjectA objA = (ObjectA) obj;
        if(objA.getVal1() != objectA.getVal1() || objA.getVal2() != objectA.getVal2() || objA.getVal3() != objectA.getVal3() ){
            throw new RuntimeException();
        }
        sessionContainer.close();
    }
View Full Code Here


        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
       
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        ObjectB objectB = new ObjectB();
        ObjectA objectA = new ObjectA((byte)1,(short)2,objectB);
        objectB._val3 = objectA;
        sessionContainer.set(objectA);
        sessionContainer.commit();
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        sessionContainer.printFileMap();
        List classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=2){
            throw new RuntimeException(""+classes.size());
        }
       
        int index = classes.indexOf(objectA);
       
        if(index == -1){
            throw new RuntimeException();
        }
        Object obj = classes.get(index);
        if(obj.getClass() != objectA.getClass()){
            throw new RuntimeException();
        }
        ObjectA objA = (ObjectA) obj;
        if(objA.getVal1() != objectA.getVal1() || objA.getVal2() != objectA.getVal2()){
            throw new RuntimeException();
        }
       
        if(objA.getVal3().getClass() != objectB.getClass()){
            throw new RuntimeException();
        }
       
        int bIndex = classes.indexOf(objectB);
       
        if(bIndex == -1){
            throw new RuntimeException();
        }
       
        ObjectB objectB2 = (ObjectB) classes.get(bIndex);
       
        if(objectB2._val3 != objA){
            throw new RuntimeException();
        }
       
        objectB2 = new ObjectB();
        objA.setVal3(objectB2);
        sessionContainer.set(objA);
       
        sessionContainer.commit();
       
        sessionContainer.close();
View Full Code Here

        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
       
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        ObjectB objectB = new ObjectB();
        ObjectA objectA = new ObjectA((byte)1,(short)2,objectB);
        ObjectA objectA2 = new ObjectA((byte)3,(byte)3,objectB);
        objectB._val3 = objectA;
        sessionContainer.set(objectA);
        sessionContainer.set(objectA2);
        sessionContainer.commit();
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        List classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        int index = classes.indexOf(objectA);
       
        if(index == -1){
            throw new RuntimeException();
        }
        Object obj = classes.get(index);
        if(obj.getClass() != objectA.getClass()){
            throw new RuntimeException();
        }
        ObjectA objA = (ObjectA) obj;
        if(objA.getVal1() != objectA.getVal1() || objA.getVal2() != objectA.getVal2()){
            throw new RuntimeException();
        }
       
        if(objA.getVal3().getClass() != objectB.getClass()){
            throw new RuntimeException();
        }
       
        int bIndex = classes.indexOf(objectB);
       
        if(bIndex == -1){
            throw new RuntimeException();
        }
       
        ObjectB objectB2 = (ObjectB) classes.get(bIndex);
       
        if(objectB2._val3 != objA){
            throw new RuntimeException();
        }
       
        objA.setVal2((short) 33);
       
        sessionContainer.set(objA);
       
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        index = classes.indexOf(objA);
       
        if(index == -1){
            throw new RuntimeException();
        }
       
        objA = (ObjectA) classes.get(index);
        if(objA.getVal2() != 33){
            throw new RuntimeException();
        }
       
        objA.setVal1((byte) 100);
        objA.setVal2((short) 300);
        sessionContainer.set(objA);
       
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        //sessionContainer.printFileMap();
        classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        index = classes.indexOf(objA);
       
        if(index == -1){
            throw new RuntimeException();
        }
       
        objA = (ObjectA) classes.get(index);
        if(objA.getVal1() != 100 || objA.getVal2() != 300 || objA.getVal3()==null ){
            throw new RuntimeException();
        }
       
        objA.setVal1((byte) 111);
        objA.setVal2((short) 333);
        objA.setVal3(null);
        sessionContainer.set(objA);
       
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        sessionContainer.printFileMap();
        classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        index = classes.indexOf(objA);
       
        if(index == -1){
            throw new RuntimeException();
        }
       
        objA = (ObjectA) classes.get(index);
        if(objA.getVal1() != 111 || objA.getVal2() != 333 || objA.getVal3()!=null ){
            throw new RuntimeException();
        }
       
       
        sessionContainer.printFileMap();
View Full Code Here

        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
       
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        ObjectB objectB = new ObjectB();
        ObjectA objectA = new ObjectA((byte)1,(short)2,null);
        ObjectA objectA2 = new ObjectA((byte)3,(byte)3,objectB);
        objectB._val3 = objectA;
        sessionContainer.set(objectA);
        sessionContainer.set(objectA2);
        sessionContainer.commit();
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        List classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        int index = classes.indexOf(objectA);
       
        if(index == -1){
            throw new RuntimeException();
        }
        Object obj = classes.get(index);
        if(obj.getClass() != objectA.getClass()){
            throw new RuntimeException();
        }
        ObjectA objA = (ObjectA) obj;
        if(objA.getVal1() != objectA.getVal1() || objA.getVal2() != objectA.getVal2()){
            throw new RuntimeException();
        }
       
       
        int bIndex = classes.indexOf(objectB);
       
        if(bIndex == -1){
            throw new RuntimeException();
        }
       
        ObjectB objectB2 = (ObjectB) classes.get(bIndex);
       
        if(objectB2._val3 != objA){
            throw new RuntimeException();
        }
       
        objA.setVal2((short) 33);
       
        int indexA2 = classes.indexOf(objectA2);
       
        ObjectA objA2 = (ObjectA) classes.get(indexA2);
       
        objA2.setVal3(null);
       
        sessionContainer.set(objA);
        sessionContainer.set(objA2);
       
        sessionContainer.printFileMap();
View Full Code Here

        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
       
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        ObjectB objectB = new ObjectB();
        ObjectA objectA = new ObjectA((byte)1,(short)2,objectB);
        ObjectA objectA2 = new ObjectA((byte)3,(byte)3,null);
        objectB._val3 = objectA2;
        sessionContainer.set(objectA);
        sessionContainer.commit();
        sessionContainer.close();
       
View Full Code Here

        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
       
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        ObjectB objectB = new ObjectB();
        ObjectA objectA = new ObjectA((byte)1,(short)2,objectB);
        ObjectA objectA2 = new ObjectA((byte)3,(byte)3,objectB);
        objectB._val3 = objectA;
        sessionContainer.set(objectA);
        sessionContainer.set(objectA2);
        sessionContainer.commit();
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        List classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        int index = classes.indexOf(objectA);
       
        if(index == -1){
            throw new RuntimeException();
        }
        Object obj = classes.get(index);
        if(obj.getClass() != objectA.getClass()){
            throw new RuntimeException();
        }
        ObjectA objA = (ObjectA) obj;
        if(objA.getVal1() != objectA.getVal1() || objA.getVal2() != objectA.getVal2()){
            throw new RuntimeException();
        }
       
        if(objA.getVal3().getClass() != objectB.getClass()){
            throw new RuntimeException();
        }
       
        int bIndex = classes.indexOf(objectB);
       
        if(bIndex == -1){
            throw new RuntimeException();
        }
       
        ObjectB objectB2 = (ObjectB) classes.get(bIndex);
       
        if(objectB2._val3 != objA){
            throw new RuntimeException();
        }
       
        objA.setVal2((short) 33);
       
        sessionContainer.set(objA);
       
        sessionContainer.close();
       
        sessionContainer = getContainerForFile(testFile);
        classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
       
        index = classes.indexOf(objA);
       
        if(index == -1){
            throw new RuntimeException();
        }
       
        ObjectA objectA3 = (ObjectA) classes.get(index);
        if(objectA3.getVal2() != 33){
            throw new RuntimeException();
        }
       
        if(sessionContainer.getCachedObjectsCount() <= 0){
            throw new RuntimeException();
        }
       
        System.out.println("DELAY START --------------->"+sessionContainer.getCachedObjectsCount());
        objectA3 = null;
       
        objectB = null;
        objectA = null;
        objectA2 = null;
        objectB2 = null;
        objectA3 = null;
        obj = null;
        objA = null;
        classes = null;
       
        System.gc();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("DELAY END ---------------"+sessionContainer.getCachedObjectsCount());
        if(sessionContainer.getCachedObjectsCount() > 0){
            throw new RuntimeException();
        }
        classes = sessionContainer.getAllObjects();
       
        if(classes.size()!=3){
            throw new RuntimeException();
        }
        objA = new ObjectA((byte)1,(short)33,null);
        index = classes.indexOf(objA);
       
        if(index == -1){
            throw new RuntimeException();
        }
       
        objectA3 = (ObjectA) classes.get(index);
        if(objectA3.getVal2() != 33){
            throw new RuntimeException();
        }
       
//        try {
//            Thread.sleep(2000000);
View Full Code Here

        }
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        sessionContainer.configureIndex(ObjectA.class, "_val2", true);
       
        for (int i = 1000; i  >= 0; --i) {
            ObjectA objectA = new ObjectA((byte)2,(byte)i,null);
            sessionContainer.set(objectA);
        }

        //sessionContainer.printFileMap();
       
        sessionContainer.commit();
       
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
       
        //System.err.println("_________________________________________________________");
        //sessionContainer.printFileMap();
       
        JODBQueryList list = sessionContainer.getAllObjects();
       
        int total = list.size();
        for (int i = 0; i < total; i++) {
            ObjectA nextObj = (ObjectA) list.get(i);
            nextObj.setVal2((short) i);
            sessionContainer.set(nextObj);
        }
       
        sessionContainer.commit();
       
View Full Code Here

       
        int maxObjects = 10000;
       
        for (int i = maxObjects-1; i  >= 0; --i) {
            short next = (short) random.nextInt();
            ObjectA objectA = new ObjectA((byte)2,next ,null);
            sessionContainer.set(objectA);
        }
       
        sessionContainer.commit();
       
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
       
       
       
        Query query = sessionContainer.query();
        query.constrain(ObjectA.class);
        if(ascending){
            query.descend("_val2").orderAscending();
        }else{
            query.descend("_val2").orderDescending();
        }
       
        JODBQueryList list = (JODBQueryList) query.execute();
        if(list.size() != maxObjects){
            throw new RuntimeException();
        }
       
        ObjectA prev = null;
        for (int i = 0; i < list.size(); i++) {
            ObjectA current = (ObjectA) list.get(i);
            //System.err.println("Indexing Random test iter #="+i);
            if(prev!=null){
                if(ascending){
                    if( prev.getVal2() > current.getVal2() ){
                        throw new RuntimeException();
                    }
                }else if(prev.getVal2() < current.getVal2() ){
                    JODBIndexingAgent indexingAgent = sessionContainer.getIndexingAgent(ObjectA.class.getDeclaredField("_val2") );
                    long prevID = sessionContainer.getPersistenceStatistics(prev).getObjectID();
                    long currentID = sessionContainer.getPersistenceStatistics(current).getObjectID();
                    int prevPosition = indexingAgent.linearIdSearch(prevID);
                    int currentPosition = indexingAgent.linearIdSearch(currentID);
                    throw new RuntimeException(""+prevID+"  "+prevPosition+"  "+ currentID+"  "+currentPosition);
                }
            }
            prev = current;
        }
       
       
        //System.err.println("_________________________________________________________");
        //sessionContainer.printFileMap();
       
        list = sessionContainer.getAllObjects();
       
        int total = list.size();
        for (int i = 0; i < total; i++) {
            ObjectA nextObj = (ObjectA) list.get(i);
            nextObj.setVal2((short) i);
            sessionContainer.set(nextObj);
        }
       
        sessionContainer.commit();
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
       
       
        query = sessionContainer.query();
        query.constrain(ObjectA.class);
        if(ascending){
            query.descend("_val2").orderAscending();
        }else{
            query.descend("_val2").orderDescending();
        }
       
        list = (JODBQueryList) query.execute();
        if(list.size() == 0){
            throw new RuntimeException();
        }
       
        prev = null;
        for (int i = 0; i < list.size(); i++) {
            //System.err.println("Indexing Random test iter1 #="+i);
            ObjectA current = (ObjectA) list.get(i);
            if(prev!=null){
                if(ascending){
                    if( prev.getVal2() > current.getVal2() ){
                        throw new RuntimeException();
                    }
                }else if(prev.getVal2() < current.getVal2() ){
                    JODBIndexingAgent indexingAgent = sessionContainer.getIndexingAgent(ObjectA.class.getDeclaredField("_val2") );
                    long prevID = sessionContainer.getPersistenceStatistics(prev).getObjectID();
                    long currentID = sessionContainer.getPersistenceStatistics(current).getObjectID();
                    int prevPosition = indexingAgent.linearIdSearch(prevID);
                    int currentPosition = indexingAgent.linearIdSearch(currentID);
                    throw new RuntimeException(" i="+i+" -->"+prevID+"  "+prevPosition+"  "+prev.getVal2()+" "+ currentID+"  "+currentPosition+" "+current.getVal2());
                }
            }
            prev = current;
        }
       
View Full Code Here

        File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
        testFile.delete();
        JODBSessionContainer sessionContainer = getContainerForFile(testFile);
        sessionContainer.configureIndex(ObjectA.class, "_val1", true);
        sessionContainer.configureIndex(ObjectA.class, "_val2", true);
        ObjectA objectA1 = new ObjectA((byte)0,(short)2,null);
        ObjectA objectA2 = new ObjectA((byte)0,(short)1,null);
        ObjectA objectA3 = new ObjectA((byte)0,(short)3,null);
       
        sessionContainer.set(objectA1);
        sessionContainer.set(objectA2);
        sessionContainer.set(objectA3);
       
        sessionContainer.commit();
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
        Query query = sessionContainer.query();
        query.constrain(ObjectA.class);
        if(ascending){
            query.descend("_val1").orderAscending();
        }else{
            query.descend("_val1").orderDescending();
        }
        if(ascending){
            query.descend("_val2").orderAscending();
        }else{
            query.descend("_val2").orderDescending();
        }
        JODBConfig.setCacheOnSortOperations(false);
        List list = query.execute();
        if(list.size() == 0){
            throw new RuntimeException();
        }
       
        ObjectA prev = null;
        for (int i = 0; i < list.size(); i++) {
            ObjectA current = (ObjectA) list.get(i);
            if(prev!=null){
                if(ascending){
                    if( prev.getVal2() > current.getVal2() ){
                        throw new RuntimeException();
                    }
                }else if(prev.getVal2() < current.getVal2() ){
                    throw new RuntimeException();
                }
            }
            prev = current;
        }
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
       
        query = sessionContainer.query();
        query.constrain(ObjectA.class);
        if(ascending){
            query.descend("_val2").orderAscending();
        }else{
            query.descend("_val2").orderDescending();
        }
       
        JODBConfig.setCacheOnSortOperations(true);
        list = query.execute();
        if(list.size() == 0){
            throw new RuntimeException();
        }
       
        prev = null;
        for (int i = 0; i < list.size(); i++) {
            ObjectA current = (ObjectA) list.get(i);
            if(prev!=null){
                if(ascending){
                    if( prev.getVal2() > current.getVal2() ){
                        throw new RuntimeException();
                    }
                }else if(prev.getVal2() < current.getVal2() ){
                    throw new RuntimeException();
                }
            }
            prev = current;
        }
View Full Code Here

        for (int i = maxObjects-1; i  >= 0; --i) {
            short next = (short) random.nextInt();
            if(next<0){
                negatives++;
            }
            ObjectA objectA = new ObjectA((byte)2,next ,null);
            sessionContainer.set(objectA);
        }
       
        if(negatives ==0 ){
            throw new RuntimeException();
        }
       
        sessionContainer.commit();
       
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
       
        Query query = sessionContainer.query();
        query.constrain(ObjectA.class);

        query.descend("_val2").constrain(0).smaller();
       
       
        long queryStart = System.currentTimeMillis();
        JODBQueryList list = (JODBQueryList) query.execute();
        long noneIndexQuery = System.currentTimeMillis() - queryStart;
        System.err.println("noneIndexQuery="+noneIndexQuery);
       
        if(list.size() != negatives){
            throw new RuntimeException();
        }
       
        sessionContainer.configureIndex(ObjectA.class, "_val2", true);
       
        if(reopen){
            sessionContainer.close();
            sessionContainer = getContainerForFile(testFile);
        }
       
       
        query = sessionContainer.query();
        query.constrain(ObjectA.class);

        query.descend("_val2").constrain(0).smaller();
       
        queryStart = System.currentTimeMillis();
        list = (JODBQueryList) query.execute();
        long queryWithIndex = System.currentTimeMillis() - queryStart;
        System.err.println("queryWithIndex="+queryWithIndex);
       
        if(list.size() != negatives){
            throw new RuntimeException();
        }
       
       
       
        sessionContainer.commit();
       
       
        for (int i = 0; i < list.size(); i++) {
            ObjectA current = (ObjectA) list.get(i);
            if(current.getVal2()>=0){
                throw new RuntimeException();
            }
        }
       
        sessionContainer.commit();
View Full Code Here

TOP

Related Classes of com.mobixess.jodb.tests.testobjects.ObjectA

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.