KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > RegressionCS


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test;
22
23 import java.io.*;
24
25 import com.db4o.*;
26
27 /**
28  * Runs the Regression test in client server mode.
29  */

30 public class RegressionCS extends Regression {
31
32     /**
33      * starts a db4o server automatically.
34      * You may also choose to start a server on another computer separately.
35      */

36     private static final boolean START_IN_PROCESS_SERVER = true;
37     
38     /**
39      * modify to connect to a remote server
40      */

41     private static final String JavaDoc HOST_NAME = "localhost";
42     
43     /**
44      * the server port name
45      */

46      private static final int SERVER_PORT = 4044;
47     
48     /**
49      * the user to login with
50      */

51     private static final String JavaDoc USER = "db4o";
52     
53     /**
54      * the password to use
55      */

56     private static final String JavaDoc PASSWORD = "db4o";
57     
58     /**
59      * the file used. Only relevant if START_IN_PROCESS_SERVER == true
60      */

61     private static final String JavaDoc SERVER_FILE = "server.yap";
62     
63     /**
64      * the db4o server instance
65      */

66     private ObjectServer server = null;
67
68
69     public static void main(String JavaDoc[] args) {
70         System.out.println("Client Server Regression Test");
71         Db4o.configure().messageLevel(-1);
72
73         new RegressionCS().run();
74     }
75     
76     public RegressionCS(){
77         if (START_IN_PROCESS_SERVER) {
78             new File(SERVER_FILE).delete();
79             try {
80                 server = Db4o.openServer(SERVER_FILE, SERVER_PORT);
81                 server.grantAccess(USER, PASSWORD);
82                 // wait for server to come online
83
Thread.sleep(3000);
84             } catch (Exception JavaDoc e) {
85                 e.printStackTrace();
86             }
87         } else {
88             new File(Regression.FILE).delete();
89         }
90     }
91     
92     public void completed(){
93         if (START_IN_PROCESS_SERVER) {
94             server.close();
95         }
96     }
97
98     public ObjectContainer openContainer() {
99         configure();
100         try {
101             /*
102             if(com.db4o.Debug.fakeServer){
103                 return new YapClient(Regression.file);
104             }else{
105                 return Db4o.openClient(HOST_NAME,SERVER_PORT,"db4o","db4o");
106             }
107             */

108             
109             return server.openClient();
110             
111             // return Db4o.openClient(HOST_NAME, SERVER_PORT, USER, PASSWORD);
112

113         } catch (Exception JavaDoc e) {
114             e.printStackTrace();
115             System.out.println("Could not connect to server. Settings:");
116             System.out.println("Host Name: " + HOST_NAME + " Port:" + SERVER_PORT);
117             System.out.println("User: " + USER + " Password:" + PASSWORD);
118             System.out.println("Check the variables in RegressionCS.java");
119         }
120         return null;
121     }
122     
123 }
124
Popular Tags