notloggedin
[mediawiki.git] / testsuite / src / com / piclab / wikitest / WikiFetchThread.java
blob000d31c7cc795b14b849e49a85596e3e56ea9f7a
2 /*
3 * WikiFetchThread is a background thread that fetches
4 * pages from the preload list until the suite is done.
5 */
7 package com.piclab.wikitest;
8 import com.meterware.httpunit.*;
10 public class WikiFetchThread extends Thread {
12 private WebConversation m_conv;
13 private int m_totalfetches;
14 private long m_totaltime;
15 private volatile boolean m_running;
18 public WikiFetchThread() {
19 m_conv = new WebConversation();
20 m_totalfetches = 0;
21 m_totaltime = 0;
24 public int getFetches() { return m_totalfetches; }
25 public long getTime() { return m_totaltime; }
26 public void requestStop() { m_running = false; }
29 public void run() {
30 int index = 0;
31 String url;
32 double r;
33 long start, end;
35 m_running = true;
36 while ( m_running ) {
37 r = Math.random();
38 if ( r < 0.1 ) {
39 url = WikiTest.viewUrl( "" ); /* Main page */
40 } else if ( r < 0.15 ) {
41 url = WikiTest.viewUrl( "Special:Recentchanges" );
42 } else {
43 if ( ++index >= WikiSuite.preloadedPages.length ) { index = 0; }
44 url = WikiTest.viewUrl( WikiSuite.preloadedPages[index] );
47 start = System.currentTimeMillis();
48 try {
49 WebResponse wr = m_conv.getResponse( url );
50 } catch (Exception e) {
51 WikiSuite.warning( "Error (" + e + ") fetching \"" + url + "\"" );
53 end = System.currentTimeMillis();
55 WikiSuite.finer( "Fetched \"" + url + "\"" );
56 ++m_totalfetches;
57 m_totaltime += ( end - start );
59 try {
60 Thread.sleep( 1000 );
61 } catch( InterruptedException e ) {
62 break;
66 * The main suite tells us to stop, but we wait until the
67 * current fetch is done. So we have the suite wait for us
68 * to actually stop before continuing with its final report,
69 * and we wake it up here.
71 synchronized (this) { notify(); }