Project

General

Profile

« Previous | Next » 

Revision 7167

test for running concurrent Metacat queries to mimic Kepler data search.
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5518

View differences:

test/path_query.xml
1
<?xml version="1.0"?>
2
<pathquery version="1.2">
3
	<querytitle>Untitled-Search-1</querytitle>
4
	<returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype>
5
	<returndoctype>eml://ecoinformatics.org/eml-2.0.1</returndoctype>
6
	<returndoctype>eml://ecoinformatics.org/eml-2.1.0</returndoctype>
7
	<returndoctype>eml://ecoinformatics.org/eml-2.1.1</returndoctype>
8
	<returnfield>dataset/title</returnfield>
9
	<returnfield>entityName</returnfield>
10
	<querygroup operator="INTERSECT">
11
		<querygroup operator="UNION">
12
			<queryterm searchmode="contains" casesensitive="false">
13
				<value>Insects</value>
14
				<pathexpr>dataset/title</pathexpr>
15
			</queryterm>
16
			<queryterm searchmode="contains" casesensitive="false">
17
				<value>Insects</value>
18
				<pathexpr>keyword</pathexpr>
19
			</queryterm>
20
			<queryterm searchmode="contains" casesensitive="false">
21
				<value>Insects</value>
22
				<pathexpr>creator/individualName/surName
23
				</pathexpr>
24
			</queryterm>
25
			<queryterm searchmode="contains" casesensitive="false">
26
				<value>Insects</value>
27
				<pathexpr>abstract/para</pathexpr>
28
			</queryterm>
29
			<queryterm searchmode="contains" casesensitive="false">
30
				<value>Insects</value>
31
				<pathexpr>taxonRankValue</pathexpr>
32
			</queryterm>
33
		</querygroup>
34
		<querygroup operator="UNION">
35
			<queryterm searchmode="contains" casesensitive="false">
36
				<value>http://%</value>
37
				<pathexpr>dataset/dataTable/physical/distribution/online/url</pathexpr>
38
			</queryterm>
39
			<queryterm searchmode="contains" casesensitive="false">
40
				<value>ecogrid://%</value>
41
				<pathexpr>dataset/dataTable/physical/distribution/online/url</pathexpr>
42
			</queryterm>
43
			<queryterm searchmode="contains" casesensitive="false">
44
				<value>ecogrid://%</value>
45
	     		<pathexpr>dataset/spatialRaster/physical/distribution/online/url</pathexpr>
46
	       </queryterm>
47
     	</querygroup>
48
     	<querygroup operator="UNION">
49
			<queryterm searchmode="equals" casesensitive="false">
50
				<value>download</value>
51
				<pathexpr>dataset/dataTable/physical/distribution/online/url/@function</pathexpr>
52
			</queryterm>
53
			<queryterm searchmode="equals" casesensitive="false">
54
				<value>download</value>
55
				<pathexpr>dataset/spatialRaster/physical/distribution/online/url/@function</pathexpr>
56
			</queryterm>
57
     	</querygroup>
58
	</querygroup>
59
</pathquery>
0 60

  
test/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java
1 1
package edu.ucsb.nceas.metacattest;
2 2

  
3

  
4 3
import java.io.FileReader;
4
import java.io.IOException;
5 5
import java.io.Reader;
6
import java.util.ArrayList;
7
import java.util.List;
8
import java.util.concurrent.ExecutorService;
9
import java.util.concurrent.Executors;
10
import java.util.concurrent.TimeUnit;
11

  
6 12
import edu.ucsb.nceas.metacat.client.Metacat;
7
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
8 13
import edu.ucsb.nceas.metacat.client.MetacatFactory;
9 14
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
10 15
import edu.ucsb.nceas.utilities.IOUtil;
11 16
import junit.framework.Test;
12 17
import junit.framework.TestCase;
13 18
import junit.framework.TestSuite;
14
public class MetaCatQueryPerformanceTest extends TestCase{
19

  
20
public class MetaCatQueryPerformanceTest extends TestCase {
15 21
	
16 22
	 /**
17 23
     * Create a suite of tests to be run together
......
28 34
    	{
29 35
    		String metacatURL = arg[0];
30 36
    	    String queryFilePath = arg[1];
31
    	    query(metacatURL, queryFilePath);
37
    	    try {
38
				//query(metacatURL, queryFilePath);
39
				multiThreadedQuery(metacatURL, queryFilePath);
40
			} catch (Exception e) {
41
				// TODO Auto-generated catch block
42
				e.printStackTrace();
43
			}
32 44
    	}
33 45
    	else
34 46
    	{
35 47
    		System.out.println("Usage: java MetaCatQueryPerformance metacatURL queryFilePath");
36 48
    	}
37 49
    }
38
    public static void query(String metacatURL, String queryFile)
50
    
51
    public static String query(String metacatURL, String queryFile) throws MetacatInaccessibleException, IOException
39 52
    {
40
        try 
41
        {
42
        	Thread.sleep(120000);
43
            Metacat m = MetacatFactory.createMetacatConnection(metacatURL);;
44
            FileReader fr = new FileReader(queryFile);
45
            Reader r = m.query(fr);
46
            //System.out.println("Starting query...");
47
            String result = IOUtil.getAsString(r, true);
48
            //System.out.println("Query result:\n" + result);
53
        Metacat m = MetacatFactory.createMetacatConnection(metacatURL);;
54
        FileReader fr = new FileReader(queryFile);
55
        Reader r = m.query(fr);
56
        //System.out.println("Starting query...");
57
        String result = IOUtil.getAsString(r, true);
58
        System.out.println("Query result:\n" + result);
49 59
                
50
        } catch (Exception e) {
51
        	System.err.println("General exception:\n" + e.getMessage());
52
        }
60
        return result;
53 61
    }
62
    
63
    public static void multiThreadedQuery(String metacatURL, String queryFile) throws InterruptedException {
64
    	
65
    	int nThreads = 25;
66
		ExecutorService executor = Executors.newFixedThreadPool(nThreads);
67
		
68
		List<QueryRunner> tasks = new ArrayList<QueryRunner>();
69
		// launch threads
70
		for (int i = 0; i < nThreads; i++) {
71
			QueryRunner query = new QueryRunner(metacatURL, queryFile, i);
72
			tasks.add(query);
73
			executor.execute(query);
74
		}
75
		
76
		// now wait
77
		executor.shutdown();
78
		executor.awaitTermination(1, TimeUnit.HOURS);
79
		
80
		// now show the runtimes
81
		for (QueryRunner query: tasks) {
82
			System.out.println("query: " + query.id + " took: " + query.runtime);
83
		}
84
		
85
    }
54 86
}
87
class QueryRunner implements Runnable{
88
	
89
	String metacatURL;
90
	String queryFile;
91
	int id;
92
	long runtime;
93
	
94
	public QueryRunner(String metacatURL, String queryFile, int id) {
95
		this.metacatURL = metacatURL;
96
		this.queryFile = queryFile;
97
		this.id = id;
98
	}
99
	
100
	@Override
101
	public void run() {
102
		try {
103
			long startTime = System.currentTimeMillis();
104
			MetaCatQueryPerformanceTest.query(metacatURL, queryFile);
105
			long endTime = System.currentTimeMillis();
106
			this.runtime = endTime - startTime;
107
		} catch (Exception e) {
108
			e.printStackTrace();
109
		}
110
	}
111
}

Also available in: Unified diff