1 /*
2 * Replica is published under the terms
3 * of the Apache Software License.
4 */
5 package replica.server.commands;
6
7 import java.sql.DriverManager;
8 import java.sql.SQLException;
9
10 import org.hsqldb.Server;
11
12 import replica.core.ApplicationMessage;
13
14 import junit.framework.TestCase;
15
16 /***
17 *
18 * @author Pedro Costa
19 * @author Helder Silva
20 * @since 31/Jan/2004
21 */
22 public class ShutdownDatabaseCommandTest extends TestCase {
23
24 Server server;
25 ShutdownDatabaseCommand sddc;
26 int port = 9010;
27
28 /***
29 * Constructor for ShutdownDatabaseCommandTest.
30 * @param name
31 */
32 public ShutdownDatabaseCommandTest(String name) {
33 super(name);
34 }
35
36 /*
37 * @see TestCase#setUp()
38 */
39 protected void setUp() throws Exception {
40 super.setUp();
41
42 server = new Server();
43 server.putPropertiesFromString("database.0=shutdowntest");
44 server.setPort(port);
45 server.setDatabaseName(0,"shutdowntest");
46 server.start();
47 try{Thread.sleep(100);}catch(InterruptedException e){}
48
49 sddc = new ShutdownDatabaseCommand();
50 sddc.setServer(server);
51 }
52
53 /*
54 * @see TestCase#tearDown()
55 */
56 protected void tearDown() throws Exception {
57 super.tearDown();
58
59 try{
60 server.stop();
61 while( server.getState() != 16 /*ServerConstants.SERVER_STATE_SHUTDOWN*/ ){
62 try{ Thread.sleep(200); }catch(InterruptedException e){}
63 }
64 }catch(Throwable t){}
65 }
66
67 public void testInternalExecute() throws Exception{
68
69 Class.forName("org.hsqldb.jdbcDriver").newInstance();
70 DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:"+port+"/shutdowntest","sa","").close();
71
72 ApplicationMessage appMsg = new ApplicationMessage();
73 appMsg.setBody("shutdown database;");
74
75 sddc.internalExecute(appMsg);
76
77 while( server.getState() != 16 /*ServerConstants.SERVER_STATE_SHUTDOWN*/ ){
78 try{ Thread.sleep(200); }catch(InterruptedException e){}
79
80 assertFalse(server.getState() == 1);
81 assertFalse(server.getState() == 4);
82 }
83
84 try{
85 DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:"+port+"/shutdowndatabasecommandtest","sa","").close();
86
87 fail();
88 }
89 catch(SQLException e){
90 }
91
92 }
93 }
This page was automatically generated by Maven