01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.tests.clientserver;
20:
21: import java.io.File;
22: import java.io.IOException;
23:
24: import com.mobixess.jodb.core.ISessionCloseListener;
25: import com.mobixess.jodb.core.JODB;
26: import com.mobixess.jodb.core.JODBServer;
27: import com.mobixess.jodb.core.JODBSessionContainer;
28: import com.mobixess.jodb.tests.IndexingTests;
29:
30: public class ServerClientIndexingTests extends IndexingTests {
31: /**
32: * @param args
33: * @throws Exception
34: */
35: public static void main(String[] args) throws Exception {
36: IndexingTests indexingTests = new ServerClientIndexingTests();
37: indexingTests.randomAddTest();
38: indexingTests.randomAddSearchWithIndexTest();
39: indexingTests.sortingTest();
40: indexingTests.simpleIndexAdd(true);
41: indexingTests.simpleIndexAdd(false);
42: System.out.println("Test complete");
43: }
44:
45: private JODBServer _lastServer;
46:
47: @Override
48: public JODBSessionContainer getContainerForFile(File file)
49: throws IOException {
50: JODBServer server = _lastServer;
51: // if(server!=null){
52: // server.stop();
53: // }
54: _lastServer = JODB.openServer(file);
55: SessionCloseListenerImpl closeListener = new SessionCloseListenerImpl(
56: _lastServer);
57: JODBSessionContainer container = (JODBSessionContainer) JODB
58: .openClient("//127.0.0.1", "null", "rw");
59: container.addCloseListener(closeListener);
60: return container;
61: }
62:
63: private static class SessionCloseListenerImpl implements
64: ISessionCloseListener {
65:
66: JODBServer _server;
67:
68: /**
69: * @param server
70: */
71: public SessionCloseListenerImpl(JODBServer server) {
72: super ();
73: _server = server;
74: }
75:
76: public void sessionClosed(JODBSessionContainer closedSession) {
77: try {
78: _server.stop();
79: } catch (IOException e) {
80: e.printStackTrace();
81: }
82: }
83:
84: }
85: }
|