KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > tests > BridgeTest


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.tests;
11 import org.mmbase.bridge.*;
12
13 /**
14  * Test-case running via the bridge. This base class takes care of
15  * configuration issues like login-information and port-numbers.
16  *
17  * @author Michiel Meeuwissen
18  */

19 public abstract class BridgeTest extends MMBaseTest {
20
21     public BridgeTest() {
22         super();
23     }
24     public BridgeTest(String JavaDoc name) {
25         super(name);
26     }
27
28     int tryCount = 0;
29
30     protected Cloud getCloud() {
31         Cloud c = null;
32         while(c == null) {
33             CloudContext cc = null;
34             try {
35                 cc = ContextProvider.getDefaultCloudContext();
36                 c = cc.getCloud("mmbase", "class", null);
37                 break;
38             } catch (BridgeException be) {
39                 if (cc instanceof LocalContext) {
40                     throw be;
41                 }
42                 System.out.println(be.getMessage() + ". LOCAL. Perhaps mmbase not yet running, retrying in 5 seconds (" + tryCount + ")");
43                 try {
44                     tryCount ++;
45                     Thread.sleep(5000);
46                 } catch (Exception JavaDoc ie) {
47                     return null;
48                 }
49                 if (tryCount > 25) {
50                     throw be;
51                 }
52             }
53         }
54         ensureDeployed(c, "local cloud");
55         return c;
56     }
57
58     protected Cloud getRemoteCloud() {
59         return getRemoteCloud("rmi://127.0.0.1:1221/remotecontext");
60     }
61
62     protected Cloud getRemoteCloud(String JavaDoc uri) {
63         Cloud c = null;
64         while(c == null) {
65             try {
66                 c = ContextProvider.getCloudContext(uri).getCloud("mmbase", "class", null);
67                 break;
68             } catch (BridgeException be) {
69                 System.out.println(be.getMessage() + ". " + uri + ". Perhaps mmbase '" + uri + "' not yet running, retrying in 5 seconds (" + tryCount + ")");
70                 try {
71                     tryCount ++;
72                     Thread.sleep(5000);
73                 } catch (Exception JavaDoc ie) {
74                     return null;
75                 }
76                 if (tryCount > 25) throw be;
77             }
78         }
79         ensureDeployed(c, uri);
80         return c;
81
82     }
83
84     protected void ensureDeployed(Cloud cloud, String JavaDoc uri) {
85         while(true) {
86             // make sure basic app is deployed
87
if (cloud.hasRelationManager("bb", "cc", "posrel") &&
88                 cloud.hasRelationManager("aa", "bb", "related") &&
89                 cloud.hasRelationManager("bb", "aa", "related")
90                 ) {
91                 return;
92             }
93             if (!cloud.hasRelationManager("bb", "cc", "posrel")) {
94                 System.out.println("No relation bb--(posrel)-->cc, in '" + uri + "' perhaps BridgeTest application not yet deployed. Waiting another 5 seconds (" + tryCount + ")");
95             } else if (!cloud.hasRelationManager("aa", "bb", "related")) {
96                 System.out.println("No relation aa--(related)-->bb, in '" + uri + "' perhaps BridgeTest application not yet deployed. Waiting another 5 seconds (" + tryCount + ")");
97             } else if (!cloud.hasRelationManager("bb", "aa", "related")) {
98                 System.out.println("No relation bb--(related)-->aa, in '" + uri + "' perhaps BridgeTest application not yet deployed. Waiting another 5 seconds (" + tryCount + ")");
99             }
100             try {
101                 tryCount ++;
102                 Thread.sleep(5000);
103                 if (tryCount > 25) {
104                     System.err.println("Giving up");
105                     return;
106                 };
107             } catch (InterruptedException JavaDoc ie) {
108                 return;
109             }
110         }
111     }
112
113 }
114
Popular Tags