All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.cache.query.BaseLineAndCompareQueryPerfTest Maven / Gradle / Ivy

There is a newer version: 2.0-BETA
Show newest version
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */
/*
 * BaseLineAndCompareQueryPerfTest.java
 *
 * Created on October 13, 2005, 11:28 AM
 */

package com.gemstone.gemfire.cache.query;

/**
 *
 * @author  prafulla
 *This test is to baseline and compare the performance figures for index usage benchmarks.
 */

import com.gemstone.gemfire.cache.*;
import com.gemstone.gemfire.cache.query.data.*;
import com.gemstone.gemfire.cache.query.internal.*;

import junit.framework.*;
import java.util.*;
import java.io.*;

public class BaseLineAndCompareQueryPerfTest extends TestCase {
    
    /** Creates a new instance of BaseLineAndCompareQueryPerfTest */
    public BaseLineAndCompareQueryPerfTest(String name) {
        super(name);
    }//end of constructor1
    
    
    /////////////////////
//    static Cache cache;
    static Region region;
    static Region region1;
    static Region region2;
    static Region region3;
    static Index index;
 //   static DistributedSystem ds;
   // static Properties props = new Properties();
    static QueryService qs;
    static Map queriesMap = new TreeMap();
    static Map withoutIndexTimeRegion = new TreeMap();
    static Map withIndexTimeRegion = new TreeMap();
    static Map indexNameRegion = new TreeMap();
    static Map withoutIndexResultSetSize = new TreeMap();
    static Map withIndexResultSetSize = new TreeMap();
    
    private static FileOutputStream file;
    private static BufferedWriter wr;
    private static int printCntr = 1;
    
    static final int MAX_OBJECTS = 10;
    static final int QUERY_EXECUTED = 5;
    
    /////////////queries ///////////
    
    String queries[] ={
        //Query 1
        "SELECT DISTINCT * FROM /Countries c, c.states s, s.districts d," +
        " d.villages v, d.cities ct WHERE v.name = 'MAHARASHTRA_VILLAGE1'",
        //Query 2
        "SELECT DISTINCT * FROM /Countries c, c.states s, s.districts d, d.villages v," +
        " d.cities ct WHERE v.name='MAHARASHTRA_VILLAGE1' AND ct.name = 'PUNE'",
        //Query 3
        "SELECT DISTINCT * FROM /Countries c, c.states s, s.districts d, d.villages v, " +
        "d.cities ct WHERE ct.name = 'PUNE' AND s.name = 'MAHARASHTRA'",
        //Query 4a & 4b
        "SELECT DISTINCT * FROM /Countries c WHERE c.name = 'INDIA'",
        "SELECT DISTINCT * FROM /Countries c, c.states s, s.districts d, d.cities ct, d.villages v WHERE c.name = 'INDIA'",
        //Query 5
        "SELECT DISTINCT * FROM /Countries c, c.states s, s.districts d WHERE d.name = 'PUNEDIST' AND s.name = 'GUJARAT'",
        //Query 6
        "SELECT DISTINCT * FROM /Countries c, c.states s, s.districts d, d.cities ct WHERE ct.name = 'MUMBAI'",
        //Query 7
        "SELECT DISTINCT c.name, s.name, d.name, ct.name FROM /Countries c, c.states s, s.districts d, d.cities ct WHERE ct.name = 'MUMBAI' OR ct.name = 'CHENNAI'",
        //Query 8
        "SELECT DISTINCT c.name, s.name FROM /Countries c, c.states s, s.districts d, d.cities ct WHERE ct.name = 'MUMBAI' AND s.name = 'GUJARAT'",
        
        ////following are multiregion queries        
        // Query 9
        "SELECT DISTINCT * FROM /Countries1 c1, c1.states s1, s1.districts d1, d1.villages v1, d1.cities ct1, /Countries2 c2, c2.states s2, s2.districts d2, d2.villages v2, d2.cities ct2 WHERE v1.name = 'MAHARASHTRA_VILLAGE1' AND ct2.name = 'MUMBAI' ",
        // Query 10
        //"SELECT DISTINCT * FROM /Countries1 c1, c1.states s1, s1.districts d1, d1.villages v1, d1.cities ct1, /Countries2 c2, c2.states s2, s2.districts d2, d2.villages v2, d2.cities ct2, /Countries3 c3, c3.states s3, s3.districts d3, d3.villages v3, d3.cities ct3  WHERE v1.name='MAHARASHTRA_VILLAGE1' AND ct3.name = 'PUNE'",
        // Query 11
        "SELECT DISTINCT * FROM /Countries1 c1, /Countries2 c2 WHERE c1.name = 'INDIA' AND c2.name = 'ISRAEL'",
        // Query 12
        "SELECT DISTINCT * FROM /Countries1 c1, c1.states s1, s1.districts d1, d1.cities ct1, d1.villages v1, /Countries2 c2, c2.states s2, s2.districts d2, d2.cities ct2, d2.villages v2 WHERE c1.name = 'INDIA' AND c2.name = 'ISRAEL'",
        // Query 13
        "SELECT DISTINCT * FROM /Countries1 c1, c1.states s1, s1.districts d1, /Countries2 c2, c2.states s2, s2.districts d2, /Countries3 c3, c3.states s3, s3.districts d3 WHERE d3.name = 'PUNEDIST' AND s2.name = 'GUJARAT'",
        // Query 14
        "SELECT DISTINCT c1.name, s1.name, d2.name, ct2.name FROM /Countries1 c1, c1.states s1, s1.districts d1, d1.cities ct1, /Countries2 c2, c2.states s2, s2.districts d2, d2.cities ct2 WHERE ct1.name = 'MUMBAI' OR ct2.name = 'CHENNAI'",
        // Query 15
        "SELECT DISTINCT c1.name, s1.name, ct1.name FROM /Countries1 c1, c1.states s1, (SELECT DISTINCT * FROM /Countries2 c2, c2.states s2, s2.districts d2, d2.cities ct2 WHERE s2.name = 'PUNJAB') itr1, s1.districts d1, d1.cities ct1 WHERE ct1.name = 'CHANDIGARH'",
        // Query 16
        "SELECT DISTINCT c1.name, s1.name, ct1.name FROM /Countries1 c1, c1.states s1, s1.districts d1, d1.cities ct1 WHERE ct1.name = element (SELECT DISTINCT ct3.name FROM /Countries3 c3, c3.states s3, s3.districts d3, d3.cities ct3 WHERE s3.name = 'MAHARASHTRA' AND ct3.name = 'PUNE')",
        // Query 17
        "SELECT DISTINCT c1.name, s1.name, ct1.name FROM /Countries1 c1, c1.states s1, s1.districts d1, d1.cities ct1, d1.getVillages() v1 WHERE v1.getName() = 'PUNJAB_VILLAGE1'",
        // Query 18
        "SELECT DISTINCT s.name, s.getDistricts(), ct.getName() FROM /Countries1 c, c.getStates() s, s.getDistricts() d, d.getCities() ct WHERE ct.getName() = 'PUNE' OR ct.name = 'CHANDIGARH' OR s.getName() = 'GUJARAT'",
        // Query 19
        "SELECT DISTINCT d.getName(), d.getCities(), d.getVillages() FROM /Countries3 c, c.states s, s.districts d WHERE d.name = 'MUMBAIDIST'"
        
        //Query 9a & 9b
        //        "SELECT DISTINCT c.name, s.name, ct.name FROM /Countries c, c.states s, (SELECT DISTINCT * FROM " +
        //        "/Countries c, c.states s, s.districts d, d.cities ct WHERE s.name = 'PUNJAB') itr1, " +
        //        "s.districts d, d.cities ct WHERE ct.name = 'CHANDIGARH'",
        //
        //        "SELECT DISTINCT c.name, s.name, ct.name FROM /Countries c, c.states s, s.districts d," +
        //        " d.cities ct WHERE ct.name = (SELECT DISTINCT ct.name FROM /Countries c, c.states s, " +
        //        "s.districts d, d.cities ct WHERE s.name = 'MAHARASHTRA' AND ct.name = 'PUNE')",
        //        //Query 10
        //        "SELECT DISTINCT c.name, s.name, ct.name FROM /Countries c, c.states s, s.districts d, " +
        //        "d.cities ct, d.getVillages() v WHERE v.getName() = 'PUNJAB_VILLAGE1'",
        //        //Query 11
        //        "SELECT DISTINCT s.name, s.getDistricts(), ct.getName() FROM /Countries c, c.getStates() s, " +
        //        "s.getDistricts() d, d.getCities() ct WHERE ct.getName() = 'PUNE' OR ct.name = 'CHANDIGARH' " +
        //        "OR s.getName() = 'GUJARAT'",
        //        //Query 12
        //        "SELECT DISTINCT d.getName(), d.getCities(), d.getVillages() FROM /Countries c, " +
        //        "c.states s, s.districts d WHERE d.name = 'MUMBAIDIST'"
    };
    
    
    ////////////////////
    
    @Override
    protected void setUp() throws java.lang.Exception {
       CacheUtils.startCache();
	}//end of setUp
    
    @Override
    protected void tearDown() throws java.lang.Exception {
        CacheUtils.closeCache();
    //    ds.disconnect();
    }//end of tearDown
    
    
    public static Test suite(){
        TestSuite suite = new TestSuite(BaseLineAndCompareQueryPerfTest.class);
        return suite;
    }//end of suite
    
    ////////////////test methods ///////////////
    public void testPerf() throws Exception{
        createRegion();
        populateData();
        
        String sqlStr;
        long startTime, endTime, totalTime = 0;
        SelectResults rs=null;
        Query q;
        
        /////without index ////////
        for (int x = 0; x




© 2015 - 2024 Weber Informatics LLC | Privacy Policy