001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026:
027: /**
028: * Runs the Regression test in client server mode.
029: */
030: public class RegressionCS extends Regression {
031:
032: /**
033: * starts a db4o server automatically.
034: * You may also choose to start a server on another computer separately.
035: */
036: private static final boolean START_IN_PROCESS_SERVER = true;
037:
038: /**
039: * modify to connect to a remote server
040: */
041: private static final String HOST_NAME = "localhost";
042:
043: /**
044: * the server port name
045: */
046: private static final int SERVER_PORT = 4044;
047:
048: /**
049: * the user to login with
050: */
051: private static final String USER = "db4o";
052:
053: /**
054: * the password to use
055: */
056: private static final String PASSWORD = "db4o";
057:
058: /**
059: * the file used. Only relevant if START_IN_PROCESS_SERVER == true
060: */
061: private static final String SERVER_FILE = "server.yap";
062:
063: /**
064: * the db4o server instance
065: */
066: private ObjectServer server = null;
067:
068: public static void main(String[] args) {
069: System.out.println("Client Server Regression Test");
070: Db4o.configure().messageLevel(-1);
071:
072: new RegressionCS().run();
073: }
074:
075: public RegressionCS() {
076: if (START_IN_PROCESS_SERVER) {
077: new File(SERVER_FILE).delete();
078: try {
079: server = Db4o.openServer(SERVER_FILE, SERVER_PORT);
080: server.grantAccess(USER, PASSWORD);
081: // wait for server to come online
082: Thread.sleep(3000);
083: } catch (Exception e) {
084: e.printStackTrace();
085: }
086: } else {
087: new File(Regression.FILE).delete();
088: }
089: }
090:
091: public void completed() {
092: if (START_IN_PROCESS_SERVER) {
093: server.close();
094: }
095: }
096:
097: public ObjectContainer openContainer() {
098: configure();
099: try {
100: /*
101: if(com.db4o.Debug.fakeServer){
102: return new YapClient(Regression.file);
103: }else{
104: return Db4o.openClient(HOST_NAME,SERVER_PORT,"db4o","db4o");
105: }
106: */
107:
108: return server.openClient();
109:
110: // return Db4o.openClient(HOST_NAME, SERVER_PORT, USER, PASSWORD);
111:
112: } catch (Exception e) {
113: e.printStackTrace();
114: System.out
115: .println("Could not connect to server. Settings:");
116: System.out.println("Host Name: " + HOST_NAME + " Port:"
117: + SERVER_PORT);
118: System.out.println("User: " + USER + " Password:"
119: + PASSWORD);
120: System.out
121: .println("Check the variables in RegressionCS.java");
122: }
123: return null;
124: }
125:
126: }
|