KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.db4o.*;
24
25 public class VMTermination {
26     
27     private String JavaDoc str;
28     
29     public VMTermination(){}
30     
31     public VMTermination(String JavaDoc str){
32         this.str = str;
33     }
34     
35     public static void main(String JavaDoc[] args) throws Exception JavaDoc{
36         
37         
38         // to circumvent the shutdown-hook, run this
39
// testcase with a breakpoint in the debugger
40
// see comments below
41

42         
43         // run one at a time, one after the other
44

45         int step = 0;
46         
47         switch(step){
48             case 0:
49                 // Test.delete();
50
Test.statistics();
51                 break;
52             case 1:
53                 killSingleUser();
54                 break;
55             case 2:
56                 testSingleUser();
57                 break;
58             case 3:
59                 killServer1();
60                 break;
61             case 4:
62                 testServer1();
63                 break;
64             case 5:
65                 killServer2();
66                 break;
67             case 6:
68                 testServer2();
69                 break;
70         }
71         
72     }
73     
74     public static void killSingleUser() throws Exception JavaDoc{
75         Test.runServer = false;
76         Test.clientServer = false;
77         Test.delete();
78         ObjectContainer con = Test.open();
79         con.set(new VMTermination("willbethere"));
80         con.commit();
81         
82         // place a breakpoint on the following line
83
// and stop the debugger
84

85         System.exit(0);
86     }
87     
88     public static void testSingleUser() {
89         Test.runServer = false;
90         Test.clientServer = false;
91         ObjectContainer con = Test.open();
92         Test.ensureOccurrences(new VMTermination(), 1);
93         Test.logAll();
94         Test.end();
95     }
96     
97     public static void killServer1() throws Exception JavaDoc{
98         Test.runServer = true;
99         Test.clientServer = true;
100         Test.delete();
101         ObjectContainer con = Test.open();
102         con.set(new VMTermination("willbethere"));
103         con.commit();
104         
105         // place a breakpoint on the following line
106
// and stop the debugger
107
System.exit(0);
108     }
109     
110     public static void testServer1(){
111         Test.runServer = true;
112         Test.clientServer = true;
113         ObjectContainer con = Test.open();
114         Test.ensureOccurrences(new VMTermination(), 1);
115         Test.logAll();
116         Test.end();
117     }
118     
119     public static void killServer2() throws Exception JavaDoc{
120         Test.runServer = true;
121         Test.clientServer = true;
122         ObjectContainer con = Test.open();
123         con.set(new VMTermination("willbethere"));
124         
125         
126         // a bit tougher now: place a
127
// breakpoint in commit sourcecode
128
// and stop the debugger there
129
con.commit();
130     }
131     
132     public static void testServer2(){
133         Test.runServer = true;
134         Test.clientServer = true;
135         ObjectContainer con = Test.open();
136         Test.ensureOccurrences(new VMTermination(), 2);
137         Test.logAll();
138         Test.end();
139     }
140     
141     
142     
143     
144     
145     
146 }
147
148
Popular Tags