001: /*
002: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
003:
004: This file is part of the JODB (Java Objects Database) open source project.
005:
006: JODB is free software; you can redistribute it and/or modify it under
007: the terms of version 2 of the GNU General Public License as published
008: by the Free Software Foundation.
009:
010: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
011: WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013: for more details.
014:
015: You should have received a copy of the GNU General Public License along
016: with this program; if not, write to the Free Software Foundation, Inc.,
017: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019: package com.mobixess.jodb.tests.clientserver;
020:
021: import java.io.File;
022: import java.io.IOException;
023:
024: import com.mobixess.jodb.core.ISessionCloseListener;
025: import com.mobixess.jodb.core.JODB;
026: import com.mobixess.jodb.core.JODBServer;
027: import com.mobixess.jodb.core.JODBSessionContainer;
028: import com.mobixess.jodb.tests.SimpleAddTest;
029:
030: public class ServerClientModeSimpleAddTest extends SimpleAddTest {
031:
032: private JODBServer _lastServer;
033:
034: /**
035: * @param args
036: * @throws Exception
037: */
038: public static void main(String[] args) throws Exception {
039:
040: SimpleAddTest simpleAddTest = new ServerClientModeSimpleAddTest();
041: simpleAddTest.ensureTestFolderExists();
042: //innerClassTest();
043:
044: simpleAddTest.sizeAndPositioningTest();
045: simpleAddTest.checkInputBuffersCount();
046:
047: simpleAddTest.objectWithChildFieldsTest();
048: simpleAddTest.checkInputBuffersCount();
049: simpleAddTest.arraysTest();
050: simpleAddTest.checkInputBuffersCount();
051:
052: simpleAddTest.noFieldsObjectTest();
053: simpleAddTest.checkInputBuffersCount();
054: simpleAddTest.multipleSubsTablesTest();
055: simpleAddTest.fileLockCheck();
056: simpleAddTest.checkInputBuffersCount();
057: simpleAddTest.transactionTest();
058: simpleAddTest.checkInputBuffersCount();
059: simpleAddTest.stringTest();
060: simpleAddTest.checkInputBuffersCount();
061: simpleAddTest.transientTest();
062: simpleAddTest.checkInputBuffersCount();
063: simpleAddTest.sizeAndPositioningTest1();
064: simpleAddTest.checkInputBuffersCount();
065: simpleAddTest.largeSubstTablesTest();
066: simpleAddTest.checkInputBuffersCount();
067: simpleAddTest.checkInputBuffersCount();
068: simpleAddTest.sizeIncreaseTest();
069: simpleAddTest.checkInputBuffersCount();
070: simpleAddTest.arraysTest1();
071: simpleAddTest.checkInputBuffersCount();
072: simpleAddTest.setTestBufferFactory();
073: simpleAddTest.checkInputBuffersCount();
074: simpleAddTest.objectWithFieldsTest();
075: simpleAddTest.checkInputBuffersCount();
076: simpleAddTest.multipleObjectWithFieldsTest();
077: simpleAddTest.checkInputBuffersCount();
078: simpleAddTest.objectWithChildFieldsModificationTest1();
079: simpleAddTest.checkInputBuffersCount();
080: simpleAddTest.objectWithChildFieldsModificationTest0();
081: simpleAddTest.checkInputBuffersCount();
082: simpleAddTest.deleteTest();
083: simpleAddTest.checkInputBuffersCount();
084: simpleAddTest.gcTest();
085: simpleAddTest.checkInputBuffersCount();
086: System.out.println("Server Test complete");
087: }
088:
089: @Override
090: public JODBSessionContainer getContainerForFile(File file)
091: throws IOException {
092: JODBServer server = _lastServer;
093: // if(server!=null){
094: // server.stop();
095: // }
096: _lastServer = JODB.openServer(file);
097: SessionCloseListenerImpl closeListener = new SessionCloseListenerImpl(
098: _lastServer);
099: JODBSessionContainer container = (JODBSessionContainer) JODB
100: .openClient("//127.0.0.1", null, "rw");
101: container.addCloseListener(closeListener);
102: return container;
103: }
104:
105: private static class SessionCloseListenerImpl implements
106: ISessionCloseListener {
107:
108: JODBServer _server;
109:
110: /**
111: * @param server
112: */
113: public SessionCloseListenerImpl(JODBServer server) {
114: super ();
115: _server = server;
116: }
117:
118: public void sessionClosed(JODBSessionContainer closedSession) {
119: try {
120: _server.stop();
121: } catch (IOException e) {
122: e.printStackTrace();
123: }
124: }
125:
126: }
127: }
|